eslint-plugin-greasemonkey 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +563 -259
- package/package.json +8 -7
- package/src/{apis.js → data/apis.js} +18 -3
- package/src/data/deprecations.js +3 -0
- package/src/data/headers.js +30 -0
- package/src/index.js +31 -4
- package/src/rules/no-invalid-headers.js +80 -0
- package/src/rules/no-missing-grants.js +1 -1
- package/src/rules/no-missing-resources.js +61 -0
- package/src/rules/{require-meta-newline.js → require-blank-line-after-meta-block.js} +6 -9
- package/src/rules/require-homepage-pair.js +2 -2
- package/src/rules/valid-grants.js +30 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-greasemonkey",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "ESLint rules for Greasemonkey/Tampermonkey userscripts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"types": "src/index.d.ts",
|
|
36
36
|
"scripts": {
|
|
37
37
|
"prepare": "husky",
|
|
38
|
-
"lint": "eslint . --cache",
|
|
39
|
-
"lint:all": "eslint .",
|
|
40
|
-
"lint:fix": "eslint . --fix --cache",
|
|
41
|
-
"lint:fix-all": "eslint . --fix",
|
|
38
|
+
"lint": "eslint . --cache && yamllint .",
|
|
39
|
+
"lint:all": "eslint . && yamllint .",
|
|
40
|
+
"lint:fix": "eslint . --fix --cache && yamllint .",
|
|
41
|
+
"lint:fix-all": "eslint . --fix && yamllint .",
|
|
42
42
|
"test": "node tests/run.js",
|
|
43
43
|
"demo": "node demo/run.js",
|
|
44
44
|
"bump:patch": "bash utils/bump.sh patch",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@eslint/markdown": "^8.0.3",
|
|
70
70
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
71
71
|
"eslint": "^10.10.0",
|
|
72
|
-
"eslint-plugin-constructors": "^1.
|
|
72
|
+
"eslint-plugin-constructors": "^1.2.0",
|
|
73
73
|
"eslint-plugin-eslint-plugin": "^7.6.2",
|
|
74
74
|
"eslint-plugin-import-x": "^4.17.1",
|
|
75
75
|
"eslint-plugin-n": "^18.3.0",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"eslint-plugin-regexp": "^3.3.0",
|
|
80
80
|
"eslint-plugin-security": "^4.0.1",
|
|
81
81
|
"globals": "^17.12.0",
|
|
82
|
-
"husky": "^9.1.7"
|
|
82
|
+
"husky": "^9.1.7",
|
|
83
|
+
"yamllint-js": "^0.2.4"
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -8,9 +8,10 @@ export const gmLegacyAPIs = new Set([ /* eslint-disable no-secrets/no-secrets */
|
|
|
8
8
|
|
|
9
9
|
export const gmModernAPIs = new Set([
|
|
10
10
|
'GM.addElement', 'GM.addStyle', 'GM.addValueChangeListener', 'GM.deleteValue', 'GM.download',
|
|
11
|
-
'GM.getResourceText', 'GM.getResourceUrl', 'GM.
|
|
12
|
-
'GM.
|
|
13
|
-
'GM.
|
|
11
|
+
'GM.getResourceText', 'GM.getResourceUrl', 'GM.getTab', 'GM.getTabs', 'GM.getValue', 'GM.getValues',
|
|
12
|
+
'GM.info', 'GM.listValues', 'GM.log', 'GM.notification', 'GM.openInTab', 'GM.registerMenuCommand',
|
|
13
|
+
'GM.removeValueChangeListener', 'GM.saveTab', 'GM.setClipboard', 'GM.setValue', 'GM.setValues',
|
|
14
|
+
'GM.unregisterMenuCommand', 'GM.webRequest', 'GM.xmlHttpRequest'
|
|
14
15
|
])
|
|
15
16
|
|
|
16
17
|
export const scAPIs = new Set([
|
|
@@ -18,3 +19,17 @@ export const scAPIs = new Set([
|
|
|
18
19
|
'CAT.agent.opfs', 'CAT.agent.skills', 'CAT.agent.task',
|
|
19
20
|
'CAT_fileStorage', 'CAT_scriptLoaded', 'CAT_userConfig'
|
|
20
21
|
])
|
|
22
|
+
|
|
23
|
+
const tmAPIs = new Set([
|
|
24
|
+
'GM_getTab', 'GM_getTabs', 'GM_saveTab', 'GM_webRequest',
|
|
25
|
+
'GM.getTab', 'GM.getTabs', 'GM.saveTab', 'GM.webRequest'
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
export const allAPIs = new Set([...gmLegacyAPIs, ...gmModernAPIs, ...scAPIs])
|
|
29
|
+
|
|
30
|
+
export function isAPIValidFor(api, manager) {
|
|
31
|
+
if (!allAPIs.has(api)) return false
|
|
32
|
+
if (api.startsWith('CAT')) return manager == 'scriptcat'
|
|
33
|
+
if (tmAPIs.has(api)) return manager == 'tampermonkey'
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const universalHeaders = new Set([
|
|
2
|
+
'antifeature', 'author', 'compatible', 'connect', 'contributionAmount', 'contributionURL', 'copyright',
|
|
3
|
+
'defaulticon', 'description', 'downloadURL', 'exclude', 'exclude-match', 'grant', 'homepage', 'homepageURL',
|
|
4
|
+
'icon', 'icon64', 'include', 'license', 'match', 'name', 'namespace', 'noframes', 'require', 'resource',
|
|
5
|
+
'run-at', 'source', 'supportURL', 'unwrap', 'updateURL', 'version', 'website'
|
|
6
|
+
])
|
|
7
|
+
|
|
8
|
+
export const managerHeaders = new Map([
|
|
9
|
+
['inject-into', ['violentmonkey']],
|
|
10
|
+
['top-level-await', ['violentmonkey']],
|
|
11
|
+
['user-agent', ['tampermonkey']],
|
|
12
|
+
['run-in', ['tampermonkey']],
|
|
13
|
+
['sandbox', ['tampermonkey']],
|
|
14
|
+
['webRequest', ['tampermonkey']],
|
|
15
|
+
['nocompat', ['tampermonkey']],
|
|
16
|
+
['domain', ['scriptish']]
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
export const localizedHeaders = ['name', 'description', 'antifeature']
|
|
20
|
+
export const managers = ['tampermonkey', 'violentmonkey', 'greasemonkey', 'scriptish']
|
|
21
|
+
export const validHeaders = new Map()
|
|
22
|
+
|
|
23
|
+
validHeaders.set('all', new Set([...universalHeaders, ...managerHeaders.keys()]))
|
|
24
|
+
|
|
25
|
+
for (const manager of managers) {
|
|
26
|
+
const specific = [...managerHeaders]
|
|
27
|
+
.filter(([, supportedBy]) => supportedBy.includes(manager))
|
|
28
|
+
.map(([header]) => header)
|
|
29
|
+
validHeaders.set(manager, new Set([...universalHeaders, ...specific]))
|
|
30
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import aliases from './data/deprecations.js'
|
|
2
|
+
|
|
1
3
|
import metaSpacing from './rules/meta-spacing.js'
|
|
2
4
|
import noDuplicateKeys from './rules/no-duplicate-keys.js'
|
|
5
|
+
import noInvalidHeaders from './rules/no-invalid-headers.js'
|
|
3
6
|
import noMissingGrants from './rules/no-missing-grants.js'
|
|
7
|
+
import noMissingResources from './rules/no-missing-resources.js'
|
|
4
8
|
import noUnusedGrants from './rules/no-unused-grants.js'
|
|
5
9
|
import noUnusedResources from './rules/no-unused-resources.js'
|
|
6
10
|
import preferMatch from './rules/prefer-match.js'
|
|
11
|
+
import requireBlankLineAfterMetaBlock from './rules/require-blank-line-after-meta-block.js'
|
|
7
12
|
import requireHomepagePair from './rules/require-homepage-pair.js'
|
|
8
13
|
import requireMatchingLocalizedFields from './rules/require-matching-localized-fields.js'
|
|
9
|
-
import requireMetaNewline from './rules/require-meta-newline.js'
|
|
10
14
|
import requireRequiredFields from './rules/require-required-fields.js'
|
|
11
15
|
import requireSpaceBeforeMetaKey from './rules/require-space-before-meta-key.js'
|
|
12
16
|
import requireUpdateDownloadPair from './rules/require-update-download-pair.js'
|
|
@@ -18,13 +22,15 @@ const plugin = {
|
|
|
18
22
|
rules: {
|
|
19
23
|
'meta-spacing': metaSpacing,
|
|
20
24
|
'no-duplicate-keys': noDuplicateKeys,
|
|
25
|
+
'no-invalid-headers': noInvalidHeaders,
|
|
21
26
|
'no-missing-grants': noMissingGrants,
|
|
22
27
|
'no-unused-grants': noUnusedGrants,
|
|
28
|
+
'no-missing-resources': noMissingResources,
|
|
23
29
|
'no-unused-resources': noUnusedResources,
|
|
24
30
|
'prefer-match': preferMatch,
|
|
31
|
+
'require-blank-line-after-meta-block': requireBlankLineAfterMetaBlock,
|
|
25
32
|
'require-homepage-pair': requireHomepagePair,
|
|
26
33
|
'require-matching-localized-fields': requireMatchingLocalizedFields,
|
|
27
|
-
'require-meta-newline': requireMetaNewline,
|
|
28
34
|
'require-required-fields': requireRequiredFields,
|
|
29
35
|
'require-space-before-meta-key': requireSpaceBeforeMetaKey,
|
|
30
36
|
'require-update-download-pair': requireUpdateDownloadPair,
|
|
@@ -34,18 +40,37 @@ const plugin = {
|
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
|
|
43
|
+
const docsURL = 'https://codeberg.org/adamlui/eslint-plugin-greasemonkey/#'
|
|
44
|
+
for (const [ruleId, rule] of Object.entries(plugin.rules))
|
|
45
|
+
rule.meta.docs.url = docsURL + ruleId
|
|
46
|
+
|
|
47
|
+
// Generate deprecated aliases
|
|
48
|
+
for (const [oldName, newName] of Object.entries(aliases.rules)) { /* eslint-disable security/detect-object-injection */
|
|
49
|
+
const newRule = plugin.rules[newName]
|
|
50
|
+
plugin.rules[oldName] = {
|
|
51
|
+
...newRule,
|
|
52
|
+
meta: {
|
|
53
|
+
...newRule.meta,
|
|
54
|
+
docs: { ...newRule.meta.docs, recommended: false },
|
|
55
|
+
deprecated: { message: `Use \`${newName}\` instead.`, replacedBy: [{ rule: { name: newName }}] }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} /* eslint-enable security/detect-object-injection */
|
|
59
|
+
|
|
37
60
|
plugin.configs = {
|
|
38
61
|
recommended: {
|
|
39
62
|
plugins: { greasemonkey: plugin },
|
|
40
63
|
rules: {
|
|
41
64
|
'greasemonkey/meta-spacing': 'error',
|
|
42
65
|
'greasemonkey/no-duplicate-keys': 'error',
|
|
66
|
+
'greasemonkey/no-invalid-headers': 'error',
|
|
43
67
|
'greasemonkey/no-missing-grants': 'error',
|
|
44
68
|
'greasemonkey/no-unused-grants': 'error',
|
|
69
|
+
'greasemonkey/no-missing-resources': 'error',
|
|
45
70
|
'greasemonkey/no-unused-resources': 'error',
|
|
46
71
|
'greasemonkey/prefer-match': 'error',
|
|
72
|
+
'greasemonkey/require-blank-line-after-meta-block': 'error',
|
|
47
73
|
'greasemonkey/require-matching-localized-fields': 'error',
|
|
48
|
-
'greasemonkey/require-meta-newline': 'error',
|
|
49
74
|
'greasemonkey/require-required-fields': 'error',
|
|
50
75
|
'greasemonkey/require-space-before-meta-key': 'error',
|
|
51
76
|
'greasemonkey/require-user-js-filename': 'error',
|
|
@@ -58,13 +83,15 @@ plugin.configs = {
|
|
|
58
83
|
rules: {
|
|
59
84
|
'greasemonkey/meta-spacing': 'error',
|
|
60
85
|
'greasemonkey/no-duplicate-keys': 'error',
|
|
86
|
+
'greasemonkey/no-invalid-headers': 'error',
|
|
61
87
|
'greasemonkey/no-missing-grants': 'error',
|
|
62
88
|
'greasemonkey/no-unused-grants': 'error',
|
|
89
|
+
'greasemonkey/no-missing-resources': 'error',
|
|
63
90
|
'greasemonkey/no-unused-resources': 'error',
|
|
64
91
|
'greasemonkey/prefer-match': 'error',
|
|
92
|
+
'greasemonkey/require-blank-line-after-meta-block': 'error',
|
|
65
93
|
'greasemonkey/require-homepage-pair': 'error',
|
|
66
94
|
'greasemonkey/require-matching-localized-fields': 'error',
|
|
67
|
-
'greasemonkey/require-meta-newline': 'error',
|
|
68
95
|
'greasemonkey/require-required-fields': 'error',
|
|
69
96
|
'greasemonkey/require-space-before-meta-key': 'error',
|
|
70
97
|
'greasemonkey/require-update-download-pair': 'error',
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { extractMetadata } from '../utils.js'
|
|
2
|
+
import { managerHeaders, managers, localizedHeaders, validHeaders } from '../data/headers.js'
|
|
3
|
+
|
|
4
|
+
function parseAllowedPattern(entry) {
|
|
5
|
+
if (typeof entry != 'string' || !entry.startsWith('/')) return null
|
|
6
|
+
const lastSlash = entry.lastIndexOf('/')
|
|
7
|
+
if (lastSlash == 0) return null
|
|
8
|
+
try { /* eslint-disable-next-line security/detect-non-literal-regexp */
|
|
9
|
+
return new RegExp(entry.slice(1, lastSlash), entry.slice(lastSlash +1))
|
|
10
|
+
} catch { return null }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Disallow invalid metadata headers',
|
|
18
|
+
category: 'Possible Errors',
|
|
19
|
+
recommended: true
|
|
20
|
+
},
|
|
21
|
+
schema: [{
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
target: {
|
|
25
|
+
anyOf: [
|
|
26
|
+
{ type: 'string', enum: ['all', ...managers] },
|
|
27
|
+
{ type: 'array', items: { type: 'string', enum: managers }, minItems: 1, uniqueItems: true }
|
|
28
|
+
],
|
|
29
|
+
description: 'Manager(s) whose headers to validate against (default: all)'
|
|
30
|
+
},
|
|
31
|
+
allowedHeaders: {
|
|
32
|
+
anyOf: [{ type: 'string' }, { type: 'array' }, {}],
|
|
33
|
+
description: 'Additional headers: string, RegExp, or array mixing both'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
additionalProperties: false
|
|
37
|
+
}],
|
|
38
|
+
defaultOptions: [{ allowedHeaders: [] }],
|
|
39
|
+
messages: {
|
|
40
|
+
invalidHeader: 'Invalid header: "@{{header}}"',
|
|
41
|
+
unsupportedHeader: '"@{{header}}" is not supported by {{target}} (only by {{supporting}})'
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
create(context) {
|
|
46
|
+
const options = context.options[0] || {},
|
|
47
|
+
rawTarget = options.target ?? 'all',
|
|
48
|
+
targets = Array.isArray(rawTarget) ? rawTarget : [rawTarget],
|
|
49
|
+
rawAllowed = options.allowedHeaders ?? [],
|
|
50
|
+
allowedList = Array.isArray(rawAllowed) ? rawAllowed : [rawAllowed],
|
|
51
|
+
allowedExact = new Set(),
|
|
52
|
+
allowedRegexes = [],
|
|
53
|
+
validSet = targets.includes('all') ? validHeaders.get('all')
|
|
54
|
+
: new Set(targets.flatMap(target => [...validHeaders.get(target)]))
|
|
55
|
+
for (const entry of allowedList) {
|
|
56
|
+
if (entry instanceof RegExp) allowedRegexes.push(entry)
|
|
57
|
+
else if (typeof entry == 'string') {
|
|
58
|
+
const parsed = parseAllowedPattern(entry)
|
|
59
|
+
if (parsed) allowedRegexes.push(parsed)
|
|
60
|
+
else allowedExact.add(entry)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
Program() {
|
|
65
|
+
const metaEntries = extractMetadata(context.sourceCode)
|
|
66
|
+
for (const entry of metaEntries) {
|
|
67
|
+
if (allowedExact.has(entry.key)) continue
|
|
68
|
+
if (allowedRegexes.some(re => re.test(entry.key))) continue
|
|
69
|
+
if (localizedHeaders.includes(entry.key.split(':')[0])) continue
|
|
70
|
+
if (validSet.has(entry.key)) continue
|
|
71
|
+
const supporting = managerHeaders.get(entry.key)
|
|
72
|
+
if (supporting)
|
|
73
|
+
context.report({ node: entry.comment, messageId: 'unsupportedHeader',
|
|
74
|
+
data: { header: entry.key, target: targets.join(', '), supporting: supporting.join(', ') }})
|
|
75
|
+
else context.report({ node: entry.comment, messageId: 'invalidHeader', data: { header: entry.key }})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { extractMetadata } from '../utils.js'
|
|
2
|
-
import { gmLegacyAPIs, gmModernAPIs, scAPIs } from '../apis.js'
|
|
2
|
+
import { gmLegacyAPIs, gmModernAPIs, scAPIs } from '../data/apis.js'
|
|
3
3
|
|
|
4
4
|
const apis = new Set([...gmLegacyAPIs, ...gmModernAPIs, ...scAPIs]),
|
|
5
5
|
grantlessAPIs = new Set(['GM_info', 'GM.info']) // always available, no grant required
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { extractMetadata, resolveTemplate } from '../utils.js'
|
|
2
|
+
|
|
3
|
+
const resourceGetterNames = new Set(['GM_getResourceText', 'GM_getResourceURL']),
|
|
4
|
+
re = { specialChars: /[.*+?^${}()|[\]\\]/g, whitespace: /\s+/ }
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Disallow @resource references without a matching declaration',
|
|
11
|
+
category: 'Possible Errors',
|
|
12
|
+
recommended: true
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
missingResource: 'Missing @resource: "{{name}}"',
|
|
17
|
+
noMatchingResource: 'No declared @resource matches `{{pattern}}`'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
create(context) {
|
|
22
|
+
const usedRefs = []
|
|
23
|
+
function record(node, arg) {
|
|
24
|
+
if (arg?.type == 'Literal' && typeof arg.value == 'string')
|
|
25
|
+
usedRefs.push({ names: [arg.value], pattern: null, node })
|
|
26
|
+
else if (arg?.type == 'TemplateLiteral') {
|
|
27
|
+
const resolved = resolveTemplate(arg)
|
|
28
|
+
if (resolved) usedRefs.push({ names: resolved, pattern: null, node })
|
|
29
|
+
else usedRefs.push({
|
|
30
|
+
names: null,
|
|
31
|
+
pattern: new RegExp( // eslint-disable-line security/detect-non-literal-regexp
|
|
32
|
+
`^${arg.quasis.map(q => q.value.raw.replace(re.specialChars, '\\$&')).join('.*')}$`),
|
|
33
|
+
node
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
CallExpression(node) {
|
|
39
|
+
if (!resourceGetterNames.has(node.callee.name)) return
|
|
40
|
+
record(node, node.arguments[0])
|
|
41
|
+
},
|
|
42
|
+
'Program:exit'() {
|
|
43
|
+
if (!usedRefs.length) return
|
|
44
|
+
const declared = new Set(
|
|
45
|
+
extractMetadata(context.sourceCode)
|
|
46
|
+
.filter(entry => entry.key == 'resource')
|
|
47
|
+
.map(entry => entry.value.trim().split(re.whitespace)[0])
|
|
48
|
+
)
|
|
49
|
+
for (const ref of usedRefs) {
|
|
50
|
+
if (ref.names) {
|
|
51
|
+
for (const name of ref.names)
|
|
52
|
+
if (!declared.has(name))
|
|
53
|
+
context.report({ node: ref.node, messageId: 'missingResource', data: { name }})
|
|
54
|
+
} else if (![...declared].some(name => ref.pattern.test(name)))
|
|
55
|
+
context.report({
|
|
56
|
+
node: ref.node, messageId: 'noMatchingResource', data: { pattern: ref.pattern.source }})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { extractMetadata } from '../utils.js'
|
|
2
|
-
|
|
3
1
|
export default {
|
|
4
2
|
meta: {
|
|
5
3
|
type: 'layout',
|
|
6
4
|
docs: {
|
|
7
|
-
description: 'Require a
|
|
5
|
+
description: 'Require a blank line between the metadata and code',
|
|
8
6
|
category: 'Stylistic Issues',
|
|
9
7
|
recommended: true
|
|
10
8
|
},
|
|
11
9
|
fixable: 'whitespace',
|
|
12
10
|
schema: [],
|
|
13
|
-
messages: {
|
|
11
|
+
messages: { missingBlankLine: 'Missing blank line after metadata block' }
|
|
14
12
|
},
|
|
15
13
|
|
|
16
14
|
create(context) {
|
|
@@ -18,16 +16,15 @@ export default {
|
|
|
18
16
|
Program() {
|
|
19
17
|
const sourceCode = context.sourceCode,
|
|
20
18
|
comments = sourceCode.getAllComments(),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!closingComment) return
|
|
19
|
+
hasOpening = comments.some(comment => comment.value.trim() == '==UserScript=='),
|
|
20
|
+
closingComment = comments.find(comment => comment.value.trim() == '==/UserScript==')
|
|
21
|
+
if (!hasOpening || !closingComment) return
|
|
25
22
|
const tokenAfter = sourceCode.getTokenAfter(closingComment)
|
|
26
23
|
if (!tokenAfter) return
|
|
27
24
|
if (tokenAfter.loc.start.line - closingComment.loc.end.line < 2)
|
|
28
25
|
context.report({
|
|
29
26
|
node: closingComment,
|
|
30
|
-
messageId: '
|
|
27
|
+
messageId: 'missingBlankLine',
|
|
31
28
|
fix(fixer) { return fixer.insertTextAfter(closingComment, '\n') }
|
|
32
29
|
})
|
|
33
30
|
}
|
|
@@ -33,8 +33,8 @@ export default {
|
|
|
33
33
|
node: homepageURLEntry.comment, messageId: 'missingPair',
|
|
34
34
|
data: { missing: 'homepage', present: 'homepageURL' },
|
|
35
35
|
fix(fixer) {
|
|
36
|
-
return fixer.
|
|
37
|
-
|
|
36
|
+
return fixer.insertTextBefore(homepageURLEntry.comment,
|
|
37
|
+
`// @homepage ${homepageURLEntry.value}\n`)
|
|
38
38
|
}
|
|
39
39
|
})
|
|
40
40
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { extractMetadata } from '../utils.js'
|
|
2
|
-
import {
|
|
2
|
+
import { allAPIs, isAPIValidFor } from '../data/apis.js'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
])
|
|
7
|
-
|
|
8
|
-
const grants = new Set([...gmLegacyAPIs, ...gmModernAPIs, ...scAPIs, ...specialGrants]),
|
|
9
|
-
sortedGrants = new Map(Array.from(grants, grant => [grant.toLowerCase(), grant]))
|
|
4
|
+
const managers = ['tampermonkey', 'violentmonkey', 'greasemonkey', 'scriptcat'],
|
|
5
|
+
specialGrants = new Set(['none', 'unsafeWindow', 'window.close', 'window.focus', 'window.onurlchange']),
|
|
6
|
+
allGrants = new Set([...allAPIs, ...specialGrants]),
|
|
7
|
+
sortedGrants = new Map(Array.from(allGrants, grant => [grant.toLowerCase(), grant]))
|
|
10
8
|
|
|
11
9
|
export default {
|
|
12
10
|
meta: {
|
|
@@ -19,6 +17,13 @@ export default {
|
|
|
19
17
|
schema: [{
|
|
20
18
|
type: 'object',
|
|
21
19
|
properties: {
|
|
20
|
+
target: {
|
|
21
|
+
anyOf: [
|
|
22
|
+
{ type: 'string', enum: ['all', ...managers] },
|
|
23
|
+
{ type: 'array', items: { type: 'string', enum: managers }, minItems: 1, uniqueItems: true }
|
|
24
|
+
],
|
|
25
|
+
description: 'Manager(s) whose grants to validate against (default: all)'
|
|
26
|
+
},
|
|
22
27
|
allowedGrants: {
|
|
23
28
|
type: 'array',
|
|
24
29
|
items: { type: 'string' },
|
|
@@ -30,12 +35,15 @@ export default {
|
|
|
30
35
|
defaultOptions: [{}],
|
|
31
36
|
messages: {
|
|
32
37
|
invalidGrant: 'Invalid @grant: "{{grant}}"',
|
|
38
|
+
unsupportedGrant: '"@{{grant}}" is not supported by {{target}} (only by {{supporting}})',
|
|
33
39
|
wrongCase: 'Invalid @grant: "{{grant}}" (did you mean "{{suggestion}}"?)'
|
|
34
40
|
}
|
|
35
41
|
},
|
|
36
42
|
|
|
37
43
|
create(context) {
|
|
38
44
|
const options = context.options[0] || {},
|
|
45
|
+
rawTarget = options.target ?? 'all',
|
|
46
|
+
targets = Array.isArray(rawTarget) ? rawTarget : [rawTarget],
|
|
39
47
|
allowedGrants = options.allowedGrants || []
|
|
40
48
|
return {
|
|
41
49
|
Program() {
|
|
@@ -43,12 +51,21 @@ export default {
|
|
|
43
51
|
grantEntries = metaEntries.filter(entry => entry.key == 'grant')
|
|
44
52
|
for (const grant of grantEntries) {
|
|
45
53
|
const grantName = grant.value.trim()
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
if (specialGrants.has(grantName) || allowedGrants.includes(grantName)) continue
|
|
55
|
+
else if (!allGrants.has(grantName)) {
|
|
56
|
+
const suggestion = sortedGrants.get(grantName.toLowerCase())
|
|
57
|
+
if (suggestion && suggestion != grantName)
|
|
58
|
+
context.report({ node: grant.comment, messageId: 'wrongCase',
|
|
59
|
+
data: { grant: grantName, suggestion }})
|
|
60
|
+
else
|
|
61
|
+
context.report({ node: grant.comment, messageId: 'invalidGrant',
|
|
62
|
+
data: { grant: grantName }})
|
|
63
|
+
continue
|
|
64
|
+
} else if (!targets.includes('all') && !targets.some(m => isAPIValidFor(grantName, m))) {
|
|
65
|
+
const supporting = managers.filter(manager => isAPIValidFor(grantName, manager ))
|
|
66
|
+
context.report({ node: grant.comment, messageId: 'unsupportedGrant',
|
|
67
|
+
data: { grant: grantName, target: targets.join(', '), supporting: supporting.join(', ') }})
|
|
68
|
+
}
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
71
|
}
|