Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports.configs = {
'userscripts/align-attributes': ['error', 2],
'userscripts/no-invalid-headers': 'error',
'userscripts/no-invalid-grant': 'error',
'userscripts/better-use-match': 'warning'
'userscripts/avoid-regexp-include': 'warning'
}
}
};
24 changes: 24 additions & 0 deletions lib/rules/avoid-regexp-include.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const createValidator = require('../utils/createValidator');

module.exports = createValidator(
'include',
false,
({ attrVal, context }) => {
const argument = attrVal.val;
if (argument.startsWith('/')) {
context.report({
loc: {
start: {
line: attrVal.loc.start.line,
column: 0
},
end: attrVal.loc.end
},
messageId: 'avoidRegExpInclude'
});
}
},
{
avoidRegExpInclude: "Using a regular expression at '@include' can cause performance issues. Use a regular @include or @match instead."
}
);
21 changes: 0 additions & 21 deletions lib/rules/better-use-match.js

This file was deleted.

8 changes: 8 additions & 0 deletions lib/rules/no-invalid-grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const gmFunctions = [
'addValueChangeListener',
'cookie',
'deleteValue',
'deleteValues',
'download',
'getResourceText',
'getResourceURL',
'getTab',
'getTabs',
'getValue',
'getValues',
'info',
'listValues',
'log',
Expand All @@ -26,7 +28,9 @@ const gmFunctions = [
'saveTab',
'setClipboard',
'setValue',
'setValues',
'unregisterMenuCommand',
'webRequest',
'xmlhttpRequest'
].map((item) => `GM_${item}`);
const greasemonkey = [
Expand All @@ -35,12 +39,14 @@ const greasemonkey = [
'addValueChangeListener',
'cookie',
'deleteValue',
'deleteValues',
'download',
'getResourceText',
'getResourceUrl', // note lowercase "rl"
'getTab',
'getTabs',
'getValue',
'getValues',
'info',
'listValues',
'log',
Expand All @@ -51,7 +57,9 @@ const greasemonkey = [
'saveTab',
'setClipboard',
'setValue',
'setValues',
'unregisterMenuCommand',
'webRequest',
'xmlHttpRequest' // note uppercase "H"
].map((item) => `GM.${item}`);
const miscellaneous = [
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/no-invalid-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ const validHeaders = new Set(
'require',
'resource',
'run-at',
'run-in',
'sandbox',
'source',
'supportURL',
'tag',
'unwrap',
'updateURL',
'version',
'website'
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = createValidator(
messageId: 'multipleVersions'
});
}
if (!/^([\dA-Za-z-]+)(\.[\dA-Za-z-]+)*\s*$/.test(attrVal.val)) {
if (!/^([^\s.]+)(\.[^\s.]+)*$/.test(attrVal.val)) {
context.report({
loc: {
start: {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/createValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ module.exports = function createValidator(
inMetadata = true;
wentInMetadata = true;
} else if (inMetadata && comment.value.trim().startsWith('@')) {
const key = comment.value.trim().slice(1).split(/[ \t]/)[0];
const key = comment.value.trim().slice(1).split(/[\t ]/)[0];
const val = {
val: comment.value
.trim()
.slice(1)
.split(/[ \t]/)
.split(/[\t ]/)
.slice(1)
.join(' ')
.trim(),
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-userscripts",
"version": "0.1.1",
"version": "0.2.0",
"description": "Implements rules for userscripts metadata in eslint",
"keywords": [
"eslint",
Expand All @@ -22,9 +22,9 @@
"@babel/eslint-parser": "^7.15.8",
"acorn": "^8.5.0",
"eslint": "^8.0.0",
"eslint-plugin-eslint-plugin": "^4.0.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-unicorn": "^37.0.1",
"eslint-plugin-eslint-plugin": ">=4.0.0",
"eslint-plugin-import": ">=2.24.2",
"eslint-plugin-unicorn": ">=37.0.1",
"husky": "^7.0.2",
"mocha": "^9.0.3",
"nyc": "^15.1.0",
Expand All @@ -34,7 +34,7 @@
"eslint": ">=6.0.0 <=^8.0.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
"node": ">=16.0.0"
},
"license": "MIT",
"homepage": "https://github.com/Yash-Singh1/eslint-plugin-userscripts#readme",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
var rule = require('..')['better-use-match'];
var rule = require('..')['avoid-regexp-include'];
var RuleTester = require('eslint').RuleTester;

var ruleTester = new RuleTester();
ruleTester.run('better-use-match', rule, {
ruleTester.run('avoid-regexp-include', rule, {
valid: [
`// ==UserScript==
// @description This is my description
// @match *://*/*
// @include https://*
// ==/UserScript==`,
],
invalid: [
{
code: `// ==UserScript==
// @include *://*/*
// @include /https?:\\/\\/foo.bar\\/.*/
// ==/UserScript==`,
errors: [{ messageId: 'betterUseMatch' }]
errors: [{ messageId: 'avoidRegExpInclude' }]
}
]
});
});
2 changes: 2 additions & 0 deletions tests/lib/rules/no-invalid-grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ruleTester.run('no-invalid-grant', rule, {
// @grant GM.download
// @grant GM_cookie
// @grant GM.cookie
// @grant GM.getValues
// @grant GM.setValues
// @grant unsafeWindow
// @grant window.onurlchange
// ==/UserScript==
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-invalid-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ ruleTester.run('no-invalid-headers', rule, {
// @downloadURL https://raw.githubusercontent.com/Yash-Singh1/UserScripts/main/Bottom_Padding_to_Swagger_UI/Bottom_Padding_to_Swagger_UI.user.js
// @updateURL https://raw.githubusercontent.com/Yash-Singh1/UserScripts/main/Bottom_Padding_to_Swagger_UI/Bottom_Padding_to_Swagger_UI.user.js
// @nocompat Chrome
// @run-in normal-tabs
// @run-in container-id-1
// @history 1.0 Initial release
// @copyright 2020-2021, Yash Singh (https://github.com/Yash-Singh1)
// ==/UserScript==
Expand Down
11 changes: 4 additions & 7 deletions tests/lib/rules/require-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ ruleTester.run('require-version', rule, {
// ==/UserScript==`,
`// ==UserScript==
// @version 1.1.1.1.2.0.1.1.1.1.1
// ==/UserScript==`
// ==/UserScript==`,
`// ==UserScript==
// @version @.€.$
// ==/UserScript==`,
],
invalid: [
{
Expand Down Expand Up @@ -73,12 +76,6 @@ ruleTester.run('require-version', rule, {
// @version 5 .6
// ==/UserScript==`,
errors: [{ messageId: 'invalidVersion' }]
},
{
code: `// ==UserScript==
// @version @.€.$
// ==/UserScript==`,
errors: [{ messageId: 'invalidVersion' }]
}
]
});
2 changes: 1 addition & 1 deletion tests/lib/utils/createValidator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const createValidator = require('../../../lib/utils/createValidator.js');
const assert = require('assert');
const assert = require('node:assert');

it('should properly generate description', () => {
assert.strictEqual(
Expand Down