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

0 commit comments

Comments
 (0)