Skip to content

Commit 672425f

Browse files
committed
Add @tag
Replace better use match by an avoid regexp include rule Update dependencies
1 parent 029eb1c commit 672425f

16 files changed

+54
-53
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports.configs = {
1919
'userscripts/align-attributes': ['error', 2],
2020
'userscripts/no-invalid-headers': 'error',
2121
'userscripts/no-invalid-grant': 'error',
22-
'userscripts/better-use-match': 'warning'
22+
'userscripts/avoid-regexp-include': 'warning'
2323
}
2424
}
2525
};

lib/rules/align-attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
create: (context) => {
2121
const spacing = context.options[0] || 2;
2222

23-
const sourceCode = context.getSourceCode();
23+
const sourceCode = context.sourceCode;
2424
const comments = sourceCode.getAllComments();
2525

2626
let inMetadata = false;

lib/rules/avoid-regexp-include.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const createValidator = require('../utils/createValidator');
2+
3+
module.exports = createValidator(
4+
'include',
5+
false,
6+
({ attrVal, context }) => {
7+
const argument = attrVal.val;
8+
if (argument.startsWith('/')) {
9+
context.report({
10+
loc: {
11+
start: {
12+
line: attrVal.loc.start.line,
13+
column: 0
14+
},
15+
end: attrVal.loc.end
16+
},
17+
messageId: 'avoidRegExpInclude'
18+
});
19+
}
20+
},
21+
{
22+
avoidRegExpInclude: "Using a regular expression at '@include' can cause performance issues. Use a regular @include or @match instead."
23+
}
24+
);

lib/rules/better-use-match.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/rules/no-invalid-headers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const validHeaders = new Set(
3838
'sandbox',
3939
'source',
4040
'supportURL',
41+
'tag',
4142
'unwrap',
4243
'updateURL',
4344
'version',

lib/rules/no-invalid-metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
]
2727
},
2828
create: (context) => {
29-
const sourceCode = context.getSourceCode();
29+
const sourceCode = context.sourceCode;
3030

3131
const comments = sourceCode.getAllComments();
3232
const lines = sourceCode.lines;

lib/rules/require-attribute-space-prefix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
schema: []
1212
},
1313
create: (context) => {
14-
const sourceCode = context.getSourceCode();
14+
const sourceCode = context.sourceCode;
1515
const lines = sourceCode.lines;
1616
let inMetadata = false;
1717
let done = false;

lib/rules/require-name.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = createValidator(
3232
)
3333
)
3434
) {
35-
const sourceCode = context.getSourceCode();
35+
const sourceCode = context.sourceCode;
3636
const comments = sourceCode.getAllComments();
3737
const endingMetadataComment = comments.find(
3838
(comment) =>
@@ -64,7 +64,7 @@ module.exports = createValidator(
6464
index === 0
6565
? val -
6666
context
67-
.getSourceCode()
67+
.sourceCode
6868
.lines[deepAttrValue.loc.start.line - 1].split(
6969
'//'
7070
)[0].length -
@@ -78,7 +78,7 @@ module.exports = createValidator(
7878
fixerRules.push(
7979
fixer.insertTextAfterRange(
8080
context
81-
.getSourceCode()
81+
.sourceCode
8282
.getAllComments()
8383
.find((val) => val.value.trim() === '==UserScript==').range,
8484
attrVal
@@ -93,7 +93,7 @@ module.exports = createValidator(
9393
(attrValue) =>
9494
`\n${
9595
context
96-
.getSourceCode()
96+
.sourceCode
9797
.lines[attrValue.loc.start.line - 1].split('//')[0]
9898
}//${attrValue.comment.value}`
9999
)

lib/rules/require-version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ module.exports = createValidator(
1010
messageId: 'multipleVersions'
1111
});
1212
}
13-
if (!/^([^.\s]+)(\.[^.\s]*){0,3}\s*$/.test(attrVal.val)) {
13+
if (!/^([^\s.]+)(\.[^\s.]+)*$/.test(attrVal.val)) {
1414
context.report({
1515
loc: {
1616
start: {
1717
line: attrVal.loc.start.line,
1818
column:
1919
/^(\s*\/\/\s*)/.exec(
20-
context.getSourceCode().lines[attrVal.comment.loc.start.line]
20+
context.sourceCode.lines[attrVal.comment.loc.start.line]
2121
)[1].length - 1
2222
},
2323
end: attrVal.loc.end

lib/rules/use-download-and-update-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = createValidator(
1818
return fixer.insertTextAfterRange(
1919
attrVal.comment.range,
2020
`\n${context
21-
.getSourceCode()
21+
.sourceCode
2222
.lines[attrVal.comment.loc.start.line - 1].replace(
2323
/^(\s*\/\/\s*@)\S*/,
2424
'$1' + attribute

lib/rules/use-homepage-and-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = createValidator(
2020
return fixer.insertTextAfterRange(
2121
attrVal.comment.range,
2222
`\n${context
23-
.getSourceCode()
23+
.sourceCode
2424
.lines[attrVal.comment.loc.start.line - 1].replace(
2525
/^(\s*\/\/\s*@)\S*/,
2626
'$1' + attribute

lib/utils/createValidator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = function createValidator(
6565
fixable: fixable ? 'code' : undefined
6666
},
6767
create: (context) => {
68-
const sourceCode = context.getSourceCode();
68+
const sourceCode = context.sourceCode;
6969
const comments = sourceCode.getAllComments();
7070

7171
let inMetadata = false;
@@ -86,12 +86,12 @@ module.exports = function createValidator(
8686
inMetadata = true;
8787
wentInMetadata = true;
8888
} else if (inMetadata && comment.value.trim().startsWith('@')) {
89-
const key = comment.value.trim().slice(1).split(/[ \t]/)[0];
89+
const key = comment.value.trim().slice(1).split(/[\t ]/)[0];
9090
const val = {
9191
val: comment.value
9292
.trim()
9393
.slice(1)
94-
.split(/[ \t]/)
94+
.split(/[\t ]/)
9595
.slice(1)
9696
.join(' ')
9797
.trim(),

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"@babel/eslint-parser": "^7.15.8",
2323
"acorn": "^8.5.0",
2424
"eslint": "^8.0.0",
25-
"eslint-plugin-eslint-plugin": "^4.0.0",
26-
"eslint-plugin-import": "^2.24.2",
27-
"eslint-plugin-unicorn": "^37.0.1",
25+
"eslint-plugin-eslint-plugin": ">=4.0.0",
26+
"eslint-plugin-import": ">=2.24.2",
27+
"eslint-plugin-unicorn": ">=37.0.1",
2828
"husky": "^7.0.2",
2929
"mocha": "^9.0.3",
3030
"nyc": "^15.1.0",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
var rule = require('..')['better-use-match'];
1+
var rule = require('..')['avoid-regexp-include'];
22
var RuleTester = require('eslint').RuleTester;
33

44
var ruleTester = new RuleTester();
5-
ruleTester.run('better-use-match', rule, {
5+
ruleTester.run('avoid-regexp-include', rule, {
66
valid: [
77
`// ==UserScript==
88
// @description This is my description
9-
// @match *://*/*
9+
// @include https://*
1010
// ==/UserScript==`,
1111
],
1212
invalid: [
1313
{
1414
code: `// ==UserScript==
15-
// @include *://*/*
15+
// @include /https?:\\/\\/foo.bar\\/.*/
1616
// ==/UserScript==`,
17-
errors: [{ messageId: 'betterUseMatch' }]
17+
errors: [{ messageId: 'avoidRegExpInclude' }]
1818
}
1919
]
20-
});
20+
});

tests/lib/rules/require-version.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ ruleTester.run('require-version', rule, {
3333
// ==/UserScript==`,
3434
`// ==UserScript==
3535
// @version 1.1.1.1.2.0.1.1.1.1.1
36-
// ==/UserScript==`
36+
// ==/UserScript==`,
37+
`// ==UserScript==
38+
// @version @.€.$
39+
// ==/UserScript==`,
3740
],
3841
invalid: [
3942
{
@@ -73,12 +76,6 @@ ruleTester.run('require-version', rule, {
7376
// @version 5 .6
7477
// ==/UserScript==`,
7578
errors: [{ messageId: 'invalidVersion' }]
76-
},
77-
{
78-
code: `// ==UserScript==
79-
// @version @.€.$
80-
// ==/UserScript==`,
81-
errors: [{ messageId: 'invalidVersion' }]
8279
}
8380
]
8481
});

tests/lib/utils/createValidator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const createValidator = require('../../../lib/utils/createValidator.js');
2-
const assert = require('assert');
2+
const assert = require('node:assert');
33

44
it('should properly generate description', () => {
55
assert.strictEqual(

0 commit comments

Comments
 (0)