eslint-plugin-greasemonkey 1.3.0 → 1.5.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 +757 -289
- package/package.json +8 -7
- package/src/{apis.js → data/apis.js} +19 -3
- package/src/data/deprecations.js +3 -0
- package/src/data/headers.js +29 -0
- package/src/index.js +45 -21
- package/src/rules/meta-order.js +76 -0
- package/src/rules/no-duplicate-keys.js +3 -3
- package/src/rules/no-invalid-headers.js +79 -0
- package/src/rules/no-missing-grants.js +2 -3
- package/src/rules/no-missing-resources.js +61 -0
- package/src/rules/{require-meta-newline.js → require-blank-line-after-meta-block.js} +6 -10
- package/src/rules/require-homepage-pair.js +6 -6
- package/src/rules/require-matching-localized-fields.js +6 -4
- package/src/rules/require-sri-hashing.js +57 -0
- package/src/rules/valid-grants.js +38 -16
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { extractMetadata } from '../utils.js'
|
|
2
|
-
import {
|
|
2
|
+
import { allAPIs, supportsAPI } 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,9 +17,18 @@ 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
|
-
|
|
24
|
-
|
|
28
|
+
anyOf: [
|
|
29
|
+
{ type: 'string' },
|
|
30
|
+
{ type: 'array', items: { type: 'string' }, minItems: 1, uniqueItems: true }
|
|
31
|
+
],
|
|
25
32
|
description: 'Additional @grant values to allow beyond the built-in list'
|
|
26
33
|
}
|
|
27
34
|
},
|
|
@@ -30,25 +37,40 @@ export default {
|
|
|
30
37
|
defaultOptions: [{}],
|
|
31
38
|
messages: {
|
|
32
39
|
invalidGrant: 'Invalid @grant: "{{grant}}"',
|
|
40
|
+
unsupportedGrant: '"@{{grant}}" is not supported by {{target}} (only by {{supporting}})',
|
|
33
41
|
wrongCase: 'Invalid @grant: "{{grant}}" (did you mean "{{suggestion}}"?)'
|
|
34
42
|
}
|
|
35
43
|
},
|
|
36
44
|
|
|
37
45
|
create(context) {
|
|
38
46
|
const options = context.options[0] || {},
|
|
39
|
-
|
|
47
|
+
rawTarget = options.target ?? 'all',
|
|
48
|
+
targets = Array.isArray(rawTarget) ? rawTarget : [rawTarget],
|
|
49
|
+
allowedGrants = [options.allowedGrants ?? []].flat()
|
|
40
50
|
return {
|
|
41
51
|
Program() {
|
|
42
52
|
const metaEntries = extractMetadata(context.sourceCode),
|
|
43
53
|
grantEntries = metaEntries.filter(entry => entry.key == 'grant')
|
|
44
54
|
for (const grant of grantEntries) {
|
|
45
55
|
const grantName = grant.value.trim()
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
if (specialGrants.has(grantName) || allowedGrants.includes(grantName)) continue
|
|
57
|
+
if (!allGrants.has(grantName)) {
|
|
58
|
+
const suggestion = sortedGrants.get(grantName.toLowerCase())
|
|
59
|
+
if (suggestion && suggestion != grantName)
|
|
60
|
+
context.report({ node: grant.comment, messageId: 'wrongCase',
|
|
61
|
+
data: { grant: grantName, suggestion }})
|
|
62
|
+
else
|
|
63
|
+
context.report({ node: grant.comment, messageId: 'invalidGrant',
|
|
64
|
+
data: { grant: grantName }})
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
if (!targets.includes('all')
|
|
68
|
+
&& !targets.some(manager => supportsAPI({ manager, api: grantName }))
|
|
69
|
+
) {
|
|
70
|
+
const supporting = managers.filter(manager => supportsAPI({ manager, api: grantName }))
|
|
71
|
+
context.report({ node: grant.comment, messageId: 'unsupportedGrant',
|
|
72
|
+
data: { grant: grantName, target: targets.join(', '), supporting: supporting.join(', ') }})
|
|
73
|
+
}
|
|
52
74
|
}
|
|
53
75
|
}
|
|
54
76
|
}
|