eslint-plugin-chrome-extensions 2.4.1 → 2.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 +101 -23
- package/package.json +4 -3
- package/src/data/apis.js +166 -115
- package/src/data/deprecations.js +7 -7
- package/src/data/i18n.js +11 -69
- package/src/data/manifest.js +61 -57
- package/src/data/permissions.js +29 -29
- package/src/data/regex.js +10 -0
- package/src/index.js +7 -123
- package/src/rules/manifest-key-order.js +8 -8
- package/src/rules/manifest-spacing.js +5 -5
- package/src/rules/no-content-style-leak.js +6 -4
- package/src/rules/no-deprecated-apis.js +4 -4
- package/src/rules/no-duplicate-manifest-keys.js +3 -4
- package/src/rules/no-insecure-messaging.js +4 -4
- package/src/rules/no-invalid-permissions.js +10 -11
- package/src/rules/no-missing-default-locale.js +7 -9
- package/src/rules/no-missing-i18n-keys.js +22 -20
- package/src/rules/no-missing-permissions.js +7 -5
- package/src/rules/no-missing-web-accessible-resources.js +7 -5
- package/src/rules/no-remote-code.js +12 -12
- package/src/rules/no-sensitive-permissions.js +75 -0
- package/src/rules/no-unrestricted-host-permissions.js +8 -7
- package/src/rules/no-unused-i18n-keys.js +11 -10
- package/src/rules/no-unused-permissions.js +22 -23
- package/src/rules/require-license-file.js +9 -8
- package/src/rules/require-mv3.js +4 -5
- package/src/rules/require-short-name-when-useful.js +4 -3
- package/src/rules/valid-filenames.js +3 -10
- package/src/rules/valid-license-file.js +18 -11
- package/src/rules/valid-manifest-icons.js +6 -5
- package/src/rules/valid-mv3-schema.js +21 -21
- package/src/rules/valid-service-worker.js +36 -13
- package/src/rules/valid-url-fields.js +10 -7
- package/src/rules/valid-version-field.js +4 -8
- package/src/utils/extension.js +51 -0
- package/src/utils/i18n.js +55 -0
- package/src/utils/init.js +105 -0
- package/src/utils/license.js +55 -0
- package/src/utils/node.js +23 -0
- package/src/utils/pkg.js +21 -0
- package/src/utils/rules.js +7 -0
- package/src/utils/text.js +13 -0
- package/src/data/license.js +0 -27
- package/src/data/text-parser.js +0 -11
- package/src/utils.js +0 -95
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/* eslint-disable security/detect-non-literal-fs-filename -- lint-time project inspection only */
|
|
2
2
|
|
|
3
|
+
import extension from '../utils/extension.js'
|
|
3
4
|
import fs from 'node:fs'
|
|
5
|
+
import i18n from '../utils/i18n.js'
|
|
4
6
|
import path from 'node:path'
|
|
5
7
|
|
|
6
|
-
import
|
|
7
|
-
import { readManifest } from '../utils.js'
|
|
8
|
-
|
|
9
|
-
const re = { manifestFile: /manifest\.json$/ }
|
|
8
|
+
import regex from '../data/regex.js'
|
|
10
9
|
|
|
11
10
|
function readMessages(filePath) {
|
|
12
11
|
try {
|
|
@@ -53,10 +52,9 @@ export default {
|
|
|
53
52
|
},
|
|
54
53
|
|
|
55
54
|
create(context) {
|
|
56
|
-
const filename = context.filename
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const root = findExtensionRoot(filename) ; if (!root) return {}
|
|
55
|
+
const filename = context.filename ; if (!filename || !regex.filename.manifest.test(filename)) return {}
|
|
56
|
+
const manifest = extension.manifest.read(context) ; if (!manifest) return {}
|
|
57
|
+
const root = extension.findRoot(context) ; if (!root) return {}
|
|
60
58
|
const localesDir = path.join(root, '_locales'),
|
|
61
59
|
hasLocales = fs.existsSync(localesDir),
|
|
62
60
|
defaultLocale = manifest.default_locale,
|
|
@@ -81,7 +79,7 @@ export default {
|
|
|
81
79
|
if (locale == defaultLocale) continue
|
|
82
80
|
const msgs = readMessages(path.join(localesDir, locale, 'messages.json')) ; if (!msgs) continue
|
|
83
81
|
for (const key of Object.keys(msgs)) {
|
|
84
|
-
if (isPredefined(key) || ignored.has(key)) continue
|
|
82
|
+
if (i18n.isPredefined(key) || ignored.has(key)) continue
|
|
85
83
|
if (!(key in defaultMsgs))
|
|
86
84
|
context.report({ loc, messageId: 'missingKeyInDefault', data: { key, locale, defaultLocale }})
|
|
87
85
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import i18nUtils from '../utils/i18n.js'
|
|
3
|
+
import nodeUtils from '../utils/node.js'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
import i18nData from '../data/i18n.js'
|
|
6
|
+
import regex from '../data/regex.js'
|
|
5
7
|
|
|
6
8
|
export default {
|
|
7
9
|
meta: {
|
|
@@ -32,37 +34,37 @@ export default {
|
|
|
32
34
|
},
|
|
33
35
|
|
|
34
36
|
create(context) {
|
|
35
|
-
const filename = context.filename
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const i18n = readDefaultLocaleMessages(manifest, root) ; if (!i18n) return {}
|
|
37
|
+
const filename = context.filename ; if (!filename || filename == '<input>') return {}
|
|
38
|
+
const manifest = extension.manifest.read(context) ; if (!manifest?.default_locale) return {}
|
|
39
|
+
const root = extension.findRoot(context) ; if (!root) return {}
|
|
40
|
+
const i18n = i18nUtils.readDefaultLocaleMessages(manifest, root) ; if (!i18n) return {}
|
|
40
41
|
const opts = context.options[0] || {},
|
|
41
42
|
ignored = new Set(opts.ignoreKeys || []),
|
|
42
|
-
isMissing = key => !isPredefined(key) && !ignored.has(key) && !(key in i18n.messages),
|
|
43
|
+
isMissing = key => !i18nUtils.isPredefined(key) && !ignored.has(key) && !(key in i18n.messages),
|
|
43
44
|
loc = { line: 1, column: 1 }
|
|
44
|
-
if (
|
|
45
|
+
if (regex.filename.script.test(filename))
|
|
45
46
|
return {
|
|
46
47
|
CallExpression(node) {
|
|
47
48
|
if (node.callee.type != 'MemberExpression') return
|
|
48
|
-
const path = getMemberPath(node.callee)
|
|
49
|
-
if (path != 'chrome.i18n.getMessage' && path != 'browser.i18n.getMessage') return
|
|
49
|
+
const path = nodeUtils.getMemberPath(node.callee) ; if (!i18nData.re.getMsg.path.test(path)) return
|
|
50
50
|
const arg = node.arguments[0] ; if (!arg) return
|
|
51
51
|
let key
|
|
52
|
-
if (arg.type == 'Literal' && typeof arg.value == 'string')
|
|
53
|
-
|
|
52
|
+
if (arg.type == 'Literal' && typeof arg.value == 'string')
|
|
53
|
+
key = arg.value
|
|
54
|
+
else if (arg.type == 'TemplateLiteral' && arg.expressions.length === 0)
|
|
54
55
|
key = arg.quasis[0].value.cooked
|
|
55
56
|
if (key && isMissing(key))
|
|
56
57
|
context.report({ loc, messageId: 'missingKey', data: { key, locale: i18n.locale }})
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
60
|
+
if (!regex.filename.cssHTML.test(filename) && !regex.filename.manifest.test(filename))
|
|
61
|
+
return {}
|
|
62
|
+
const seenKeys = new Set()
|
|
63
|
+
function scanPlaceholders() {
|
|
64
|
+
for (const match of context.sourceCode.text.matchAll(i18nData.re.msgPlaceholder)) {
|
|
63
65
|
const key = match[1]
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
+
if (seenKeys.has(key)) continue
|
|
67
|
+
seenKeys.add(key)
|
|
66
68
|
if (isMissing(key))
|
|
67
69
|
context.report({ loc, messageId: 'missingKey', data: { key, locale: i18n.locale }})
|
|
68
70
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import nodeUtils from '../utils/node.js'
|
|
3
|
+
|
|
4
|
+
import apis from '../data/apis.js'
|
|
3
5
|
|
|
4
6
|
function queriesActiveTab(node) {
|
|
5
7
|
const arg = node.arguments[0] ; if (arg?.type != 'ObjectExpression') return false
|
|
@@ -26,13 +28,13 @@ export default {
|
|
|
26
28
|
},
|
|
27
29
|
|
|
28
30
|
create(context) {
|
|
29
|
-
const manifest =
|
|
31
|
+
const manifest = extension.manifest.read(context) ; if (!manifest) return {}
|
|
30
32
|
const declared = new Set([...(manifest.permissions || []), ...(manifest.optional_permissions || [])])
|
|
31
33
|
return {
|
|
32
34
|
CallExpression(node) {
|
|
33
35
|
if (node.callee.type != 'MemberExpression') return
|
|
34
|
-
const api = getMemberPath(node.callee) ; if (!api) return
|
|
35
|
-
const permission = findPermission(api) ; if (!permission || declared.has(permission)) return
|
|
36
|
+
const api = nodeUtils.getMemberPath(node.callee) ; if (!api) return
|
|
37
|
+
const permission = apis.findPermission(api) ; if (!permission || declared.has(permission)) return
|
|
36
38
|
const isActiveTabQuery = permission == 'tabs' && queriesActiveTab(node)
|
|
37
39
|
if (isActiveTabQuery && declared.has('activeTab')) return
|
|
38
40
|
const messageId = `missing${ isActiveTabQuery ? 'ActiveTab' : 'Permission' }`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import nodeUtils from '../utils/node.js'
|
|
2
3
|
|
|
3
4
|
const re = { leadingSlash: /^\//, regexSpecial: /[.+?^${}()|[\]\\]/g }
|
|
4
5
|
|
|
@@ -34,13 +35,14 @@ export default {
|
|
|
34
35
|
},
|
|
35
36
|
|
|
36
37
|
create(context) {
|
|
37
|
-
const manifest =
|
|
38
|
-
if (!
|
|
38
|
+
const manifest = extension.manifest.read(context) ; if (!manifest) return {}
|
|
39
|
+
if (!extension.file.isContentScript(context, manifest)) return {}
|
|
39
40
|
const regexes = collectWARpatterns(manifest).map(patternToRegex)
|
|
40
41
|
return {
|
|
41
42
|
CallExpression(node) {
|
|
42
|
-
if (node.callee.type != 'MemberExpression'
|
|
43
|
-
|
|
43
|
+
if (node.callee.type != 'MemberExpression'
|
|
44
|
+
|| nodeUtils.getMemberPath(node.callee) != 'chrome.runtime.getURL'
|
|
45
|
+
) return
|
|
44
46
|
const arg = node.arguments[0] ; if (arg?.type != 'Literal' || typeof arg.value != 'string') return
|
|
45
47
|
const resourcePath = arg.value.replace(re.leadingSlash, '')
|
|
46
48
|
for (const regex of regexes) if (regex.test(resourcePath)) return
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getMemberPath } from '../utils.js'
|
|
1
|
+
import nodeUtils from '../utils/node.js'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import manifest from '../data/manifest.js'
|
|
4
|
+
import regex from '../data/regex.js'
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
meta: {
|
|
@@ -22,7 +22,7 @@ export default {
|
|
|
22
22
|
properties: {
|
|
23
23
|
patterns: {
|
|
24
24
|
type: 'array',
|
|
25
|
-
items: { enum:
|
|
25
|
+
items: { enum: manifest.patterns.remoteCode },
|
|
26
26
|
description: 'Detection paths to enable'
|
|
27
27
|
},
|
|
28
28
|
checkExecuteScriptClosures: {
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
|
|
46
46
|
create(context) {
|
|
47
47
|
const opts = context.options[0] || {},
|
|
48
|
-
patterns = new Set(opts.patterns ||
|
|
48
|
+
patterns = new Set(opts.patterns || manifest.regexmoteCode),
|
|
49
49
|
checkClosures = opts.checkExecuteScriptClosures !== false,
|
|
50
50
|
scriptElems = new Set()
|
|
51
51
|
function isCreateScript(node) {
|
|
@@ -53,10 +53,10 @@ export default {
|
|
|
53
53
|
&& node.callee?.property?.name == 'createElement'
|
|
54
54
|
&& node.arguments[0]?.value == 'script'
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function isLiteralURL(node) {
|
|
57
57
|
return node?.type == 'Literal'
|
|
58
58
|
&& typeof node.value == 'string'
|
|
59
|
-
&&
|
|
59
|
+
&& regex.url.test(node.value)
|
|
60
60
|
}
|
|
61
61
|
function isObjectAssign(node) {
|
|
62
62
|
return node?.type == 'CallExpression'
|
|
@@ -67,7 +67,7 @@ export default {
|
|
|
67
67
|
function isScriptSrcAssignment(left, right) {
|
|
68
68
|
if (left.type != 'MemberExpression') return false
|
|
69
69
|
if (left.property?.name != 'src') return false
|
|
70
|
-
if (!
|
|
70
|
+
if (!isLiteralURL(right)) return false
|
|
71
71
|
if (isCreateScript(left.object)) return true
|
|
72
72
|
if (left.object.type == 'Identifier' && scriptElems.has(left.object.name)) return true
|
|
73
73
|
return false
|
|
@@ -87,7 +87,7 @@ export default {
|
|
|
87
87
|
},
|
|
88
88
|
ImportExpression(node) {
|
|
89
89
|
if (!patterns.has('dynamic-import')) return
|
|
90
|
-
if (
|
|
90
|
+
if (isLiteralURL(node.source))
|
|
91
91
|
context.report({ node, messageId: 'dynamicImport' })
|
|
92
92
|
},
|
|
93
93
|
CallExpression(node) {
|
|
@@ -103,10 +103,10 @@ export default {
|
|
|
103
103
|
) context.report({ node, messageId: 'stringTimer', data: { fn: node.callee.name }})
|
|
104
104
|
if (patterns.has('dynamic-import')
|
|
105
105
|
&& node.callee.type == 'Import'
|
|
106
|
-
&&
|
|
106
|
+
&& isLiteralURL(node.arguments[0])
|
|
107
107
|
) context.report({ node, messageId: 'dynamicImport' })
|
|
108
108
|
if (node.callee.type == 'MemberExpression') {
|
|
109
|
-
const path = getMemberPath(node.callee)
|
|
109
|
+
const path = nodeUtils.getMemberPath(node.callee)
|
|
110
110
|
if (path == 'chrome.scripting.executeScript') {
|
|
111
111
|
const optsNode = node.arguments[0]
|
|
112
112
|
if (optsNode?.type != 'ObjectExpression') return
|
|
@@ -132,7 +132,7 @@ export default {
|
|
|
132
132
|
Property(node) {
|
|
133
133
|
if (!patterns.has('remote-script-src')
|
|
134
134
|
|| node.key?.name != 'src'
|
|
135
|
-
|| !
|
|
135
|
+
|| !isLiteralURL(node.value)
|
|
136
136
|
|| !isScriptSrcProperty(node)
|
|
137
137
|
) return
|
|
138
138
|
context.report({ node: node.value, messageId: 'remoteScriptSrc' })
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
|
|
3
|
+
import permissions from '../data/permissions.js'
|
|
4
|
+
import regex from '../data/regex.js'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Flag sensitive permissions that warrant security review',
|
|
11
|
+
category: 'Possible Errors',
|
|
12
|
+
recommended: true,
|
|
13
|
+
security: true,
|
|
14
|
+
manifest: true
|
|
15
|
+
},
|
|
16
|
+
defaultOptions: [{ allowedPermissions: [] }],
|
|
17
|
+
schema: [{
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
allowedPermissions: {
|
|
21
|
+
oneOf: [
|
|
22
|
+
{ type: 'string', description: 'Single sensitive permission to allow' },
|
|
23
|
+
{
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: { type: 'string', description: 'Sensitive permission to allow' },
|
|
26
|
+
description: 'List of sensitive permissions to allow'
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
description: 'Sensitive permission names to explicitly allow'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false
|
|
33
|
+
}],
|
|
34
|
+
messages: {
|
|
35
|
+
sensitivePermission: '`{{permission}}` is a sensitive permission. Review whether it\'s needed'
|
|
36
|
+
+ ' or add it to `allowedPermissions`.'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
create(context) {
|
|
41
|
+
const opts = context.options[0] || {},
|
|
42
|
+
allowed = new Set(Array.isArray(opts.allowedPermissions) ? opts.allowedPermissions
|
|
43
|
+
: opts.allowedPermissions ? [opts.allowedPermissions] : [])
|
|
44
|
+
function checkPermission(node, permission) {
|
|
45
|
+
if (typeof permission != 'string') return
|
|
46
|
+
if (allowed.has(permission) || !permissions.sensitive.has(permission)) return
|
|
47
|
+
context.report({ node, messageId: 'sensitivePermission', data: { permission }})
|
|
48
|
+
}
|
|
49
|
+
if (regex.filename.manifest.test(extension.file.getName(context))) // lint it directly
|
|
50
|
+
return {
|
|
51
|
+
'*'(node) {
|
|
52
|
+
const keyNode = node.name || node.key ; if (!keyNode) return
|
|
53
|
+
const keyName = keyNode.value ?? keyNode.name
|
|
54
|
+
if (keyName != 'permissions' && keyName != 'optional_permissions') return
|
|
55
|
+
const arrNode = node.value ; if (arrNode?.type != 'Array') return
|
|
56
|
+
const nodeElems = arrNode.elements || arrNode.items || []
|
|
57
|
+
for (const elem of nodeElems) {
|
|
58
|
+
const valueNode = elem.value || elem
|
|
59
|
+
checkPermission(valueNode, valueNode?.value)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const manifest = extension.manifest.read(context) ; if (!manifest) return {}
|
|
64
|
+
const allPermissions = [...(manifest.permissions || []), ...(manifest.optional_permissions || [])]
|
|
65
|
+
return {
|
|
66
|
+
'Program:exit'() {
|
|
67
|
+
for (const permission of allPermissions) {
|
|
68
|
+
if (allowed.has(permission) || !permissions.sensitive.has(permission)) continue
|
|
69
|
+
context.report({ loc: { line: 1, column: 0 },
|
|
70
|
+
messageId: 'sensitivePermission', data: { permission }})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import regex from '../data/regex.js'
|
|
2
3
|
|
|
3
|
-
const re = { broadHost: /^(?:<all_urls>|\*:\/\/\*\/\*|\w+:\/\/\*\/\*)
|
|
4
|
+
const re = { broadHost: /^(?:<all_urls>|\*:\/\/\*\/\*|\w+:\/\/\*\/\*)$/ },
|
|
4
5
|
hostKeys = new Set(['host_permissions', 'optional_host_permissions', 'optional_permissions', 'permissions'])
|
|
5
6
|
|
|
6
7
|
export default {
|
|
@@ -31,20 +32,20 @@ export default {
|
|
|
31
32
|
},
|
|
32
33
|
|
|
33
34
|
create(context) {
|
|
34
|
-
if (!
|
|
35
|
-
const
|
|
35
|
+
if (!regex.filename.manifest.test(extension.file.getName(context))) return {}
|
|
36
|
+
const allowedPatterns = new Set(context.options[0]?.allowedPatterns || [])
|
|
36
37
|
return {
|
|
37
38
|
'*'(node) {
|
|
38
39
|
const keyNode = node.name || node.key ; if (!keyNode) return
|
|
39
40
|
const keyName = keyNode.value ?? keyNode.name
|
|
40
41
|
if (!hostKeys.has(keyName)) return
|
|
41
42
|
const arrNode = node.value ; if (arrNode?.type != 'Array') return
|
|
42
|
-
const
|
|
43
|
-
for (const elem of
|
|
43
|
+
const nodeElems = arrNode.elements || arrNode.items || []
|
|
44
|
+
for (const elem of nodeElems) {
|
|
44
45
|
const valueNode = elem.value || elem,
|
|
45
46
|
pattern = valueNode?.value
|
|
46
47
|
if (typeof pattern != 'string'
|
|
47
|
-
||
|
|
48
|
+
|| allowedPatterns.has(pattern)
|
|
48
49
|
|| !re.broadHost.test(pattern)
|
|
49
50
|
) continue
|
|
50
51
|
context.report({ node: valueNode, messageId: 'unrestrictedHost', data: { pattern }})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import i18nUtils from '../utils/i18n.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import i18nData from '../data/i18n.js'
|
|
5
|
+
import regex from '../data/regex.js'
|
|
5
6
|
|
|
6
7
|
export default {
|
|
7
8
|
meta: {
|
|
@@ -26,7 +27,7 @@ export default {
|
|
|
26
27
|
},
|
|
27
28
|
additionalProperties: false
|
|
28
29
|
}],
|
|
29
|
-
defaultOptions: [{ ignoreKeys: [], scanExtensions: defaultScanExtensions }],
|
|
30
|
+
defaultOptions: [{ ignoreKeys: [], scanExtensions: i18nData.defaultScanExtensions }],
|
|
30
31
|
messages: {
|
|
31
32
|
unusedKey: '`{{key}}` in `_locales/{{locale}}/messages.json` is never referenced.'
|
|
32
33
|
}
|
|
@@ -34,15 +35,15 @@ export default {
|
|
|
34
35
|
|
|
35
36
|
create(context) {
|
|
36
37
|
const filename = context.filename
|
|
37
|
-
if (!filename || !
|
|
38
|
-
const manifest =
|
|
39
|
-
const root =
|
|
40
|
-
const i18n = readDefaultLocaleMessages(manifest, root) ; if (!i18n) return {}
|
|
38
|
+
if (!filename || !regex.filename.manifest.test(filename)) return {}
|
|
39
|
+
const manifest = extension.manifest.read(context) ; if (!manifest?.default_locale) return {}
|
|
40
|
+
const root = extension.findRoot(context) ; if (!root) return {}
|
|
41
|
+
const i18n = i18nUtils.readDefaultLocaleMessages(manifest, root) ; if (!i18n) return {}
|
|
41
42
|
const opts = context.options[0] || {},
|
|
42
43
|
ignored = new Set(opts.ignoreKeys || []),
|
|
43
|
-
scanExtensions = opts.scanExtensions || defaultScanExtensions
|
|
44
|
+
scanExtensions = opts.scanExtensions || i18nData.defaultScanExtensions
|
|
44
45
|
function check() {
|
|
45
|
-
const { used, patterns } = collectUsedKeys(root, scanExtensions)
|
|
46
|
+
const { used, patterns } = i18nUtils.collectUsedKeys(root, scanExtensions)
|
|
46
47
|
for (const key of Object.keys(i18n.messages)) {
|
|
47
48
|
if (ignored.has(key) || used.has(key) || patterns.some(patt => patt.test(key))) continue
|
|
48
49
|
context.report({ loc: { line: 1, column: 1 }, messageId: 'unusedKey',
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
1
2
|
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
const re = { manifestFilename: /manifest\.json$/ }
|
|
5
|
+
import apis from '../data/apis.js'
|
|
6
|
+
import regex from '../data/regex.js'
|
|
8
7
|
|
|
9
8
|
function collectUsedAPIs(manifest, root) {
|
|
10
9
|
const files = new Set()
|
|
@@ -44,18 +43,18 @@ export default {
|
|
|
44
43
|
},
|
|
45
44
|
|
|
46
45
|
create(context) {
|
|
47
|
-
if (!
|
|
48
|
-
const manifest =
|
|
49
|
-
const root =
|
|
50
|
-
const usedAPIs = collectUsedAPIs(manifest, root)
|
|
51
|
-
|
|
46
|
+
if (!regex.filename.manifest.test(extension.file.getName(context))) return {}
|
|
47
|
+
const manifest = extension.manifest.read(context) ; if (!manifest) return {}
|
|
48
|
+
const root = extension.findRoot(context) ; if (!root) return {}
|
|
49
|
+
const usedAPIs = collectUsedAPIs(manifest, root),
|
|
50
|
+
permissionNodes = new Map()
|
|
52
51
|
function isUsed(permission) {
|
|
53
|
-
let
|
|
54
|
-
for (const [, perm] of
|
|
55
|
-
if (perm == permission) {
|
|
56
|
-
if (!
|
|
52
|
+
let knownPerm = false
|
|
53
|
+
for (const [, perm] of apis.permissionMap)
|
|
54
|
+
if (perm == permission) { knownPerm = true ; break }
|
|
55
|
+
if (!knownPerm) return true
|
|
57
56
|
for (const api of usedAPIs)
|
|
58
|
-
if (findPermission(api) == permission) return true
|
|
57
|
+
if (apis.findPermission(api) == permission) return true
|
|
59
58
|
return false
|
|
60
59
|
}
|
|
61
60
|
return {
|
|
@@ -64,20 +63,20 @@ export default {
|
|
|
64
63
|
const keyName = keyNode.value ?? keyNode.name
|
|
65
64
|
if (keyName != 'permissions' && keyName != 'optional_permissions') return
|
|
66
65
|
const arrNode = node.value ; if (arrNode?.type != 'Array') return
|
|
67
|
-
const
|
|
68
|
-
for (const elem of
|
|
69
|
-
const valueNode = elem.value || elem
|
|
70
|
-
|
|
71
|
-
if (typeof
|
|
72
|
-
if (!permissionNodes.has(
|
|
73
|
-
permissionNodes.get(
|
|
66
|
+
const nodeElems = arrNode.elements || arrNode.items || []
|
|
67
|
+
for (const elem of nodeElems) {
|
|
68
|
+
const valueNode = elem.value || elem,
|
|
69
|
+
permission = valueNode?.value
|
|
70
|
+
if (typeof permission != 'string') continue
|
|
71
|
+
if (!permissionNodes.has(permission)) permissionNodes.set(permission, [])
|
|
72
|
+
permissionNodes.get(permission).push(valueNode)
|
|
74
73
|
}
|
|
75
74
|
},
|
|
76
75
|
'Document:exit'() {
|
|
77
76
|
for (const [permission, nodes] of permissionNodes) {
|
|
78
77
|
if (isUsed(permission)) continue
|
|
79
|
-
for (const
|
|
80
|
-
context.report({ node
|
|
78
|
+
for (const node of nodes)
|
|
79
|
+
context.report({ node, messageId: 'unusedPermission', data: { permission }})
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import license from '../utils/license.js'
|
|
1
2
|
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { findLicenseFile } from '../data/license.js'
|
|
3
|
+
import pkg from '../utils/pkg.js'
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
meta: {
|
|
@@ -13,15 +13,16 @@ export default {
|
|
|
13
13
|
schema: [],
|
|
14
14
|
messages: {
|
|
15
15
|
missingFile: 'No license file found. Add one of: LICENSE, LICENSE.md, LICENSE.txt, COPYING '
|
|
16
|
-
+ '(at
|
|
16
|
+
+ '(at the package root or in a subdir).'
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
create(context) {
|
|
20
|
-
const { filename } = context
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const { filename } = context
|
|
21
|
+
function check(node) {
|
|
22
|
+
const pkgRoot = pkg.findRoot(path.dirname(filename))
|
|
23
|
+
if (!pkgRoot || !license.find(pkgRoot)) // eslint-disable-line e18e/prefer-array-some
|
|
24
|
+
context.report({ node, messageId: 'missingFile' })
|
|
25
|
+
}
|
|
25
26
|
return { Program: check, Document: check }
|
|
26
27
|
}
|
|
27
28
|
}
|
package/src/rules/require-mv3.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const re = { manifestFilename: /manifest\.json$/ }
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import regex from '../data/regex.js'
|
|
4
3
|
|
|
5
4
|
export default {
|
|
6
5
|
meta: {
|
|
@@ -18,7 +17,7 @@ export default {
|
|
|
18
17
|
},
|
|
19
18
|
|
|
20
19
|
create(context) {
|
|
21
|
-
if (
|
|
20
|
+
if (regex.filename.manifest.test(extension.file.getName(context))) { // lint it directly
|
|
22
21
|
let foundVersion = null, versionNode = null
|
|
23
22
|
return {
|
|
24
23
|
'*'(node) {
|
|
@@ -33,7 +32,7 @@ export default {
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
const manifest =
|
|
35
|
+
const manifest = extension.manifest.read(context) ; if (!manifest || manifest.manifest_version == 3) return {}
|
|
37
36
|
return { Program(node) { context.report({ node, messageId: 'notMV3' }) }}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import extension from '../utils/extension.js'
|
|
2
|
+
import regex from '../data/regex.js'
|
|
2
3
|
|
|
3
4
|
const defaults = { maxNameLength: 12 },
|
|
4
|
-
re = { i18nPlaceholder: /^__MSG_.+__
|
|
5
|
+
re = { i18nPlaceholder: /^__MSG_.+__$/ }
|
|
5
6
|
|
|
6
7
|
function isI18n(value) { return typeof value == 'string' && re.i18nPlaceholder.test(value) }
|
|
7
8
|
|
|
@@ -43,7 +44,7 @@ export default {
|
|
|
43
44
|
},
|
|
44
45
|
|
|
45
46
|
create(context) {
|
|
46
|
-
if (!
|
|
47
|
+
if (!regex.filename.manifest.test(extension.file.getName(context))) return {}
|
|
47
48
|
const opts = context.options[0] || {},
|
|
48
49
|
maxNameLength = opts.maxNameLength ?? defaults.maxNameLength,
|
|
49
50
|
always = opts.always ?? false,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* eslint-disable security/detect-non-literal-fs-filename -- lint-time project inspection only */
|
|
2
2
|
|
|
3
|
+
import extension from '../utils/extension.js'
|
|
3
4
|
import fs from 'node:fs'
|
|
4
5
|
import path from 'node:path'
|
|
5
6
|
|
|
6
|
-
const re = { invalidChars: /[^\w\-.]/,
|
|
7
|
+
const re = { invalidChars: /[^\w\-.]/, reservedPrefix: /^_/ }
|
|
7
8
|
|
|
8
9
|
const refKeys = [
|
|
9
10
|
['action.default_popup', manifest => manifest.action?.default_popup],
|
|
@@ -15,14 +16,6 @@ const refKeys = [
|
|
|
15
16
|
['side_panel.default_path', manifest => manifest.side_panel?.default_path]
|
|
16
17
|
]
|
|
17
18
|
|
|
18
|
-
function findExtensionRoot(startPath) {
|
|
19
|
-
let dir = path.dirname(startPath)
|
|
20
|
-
while (dir != path.dirname(dir)) {
|
|
21
|
-
if (fs.existsSync(path.join(dir, 'manifest.json'))) return dir
|
|
22
|
-
dir = path.dirname(dir)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
function collectRefs(manifest) {
|
|
27
20
|
const refs = []
|
|
28
21
|
for (const [label, get] of refKeys) {
|
|
@@ -115,7 +108,7 @@ export default {
|
|
|
115
108
|
filename = context.filename
|
|
116
109
|
if (!filename || filename == '<input>') return {}
|
|
117
110
|
const basename = path.basename(filename),
|
|
118
|
-
extRoot =
|
|
111
|
+
extRoot = extension.findRoot(context) || path.dirname(filename),
|
|
119
112
|
segments = path.relative(extRoot, filename).split(path.sep)
|
|
120
113
|
if (noReservedPrefix)
|
|
121
114
|
for (const seg of segments)
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import license from '../utils/license.js'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url),
|
|
7
|
-
spdxLicenseIDs = require('spdx-license-ids')
|
|
4
|
+
import regex from '../data/regex.js'
|
|
8
5
|
|
|
9
6
|
function toArray(value) { return value == null ? [] : Array.isArray(value) ? value : [value] }
|
|
10
7
|
|
|
11
8
|
function validateContent(context, node, { requireSPDX, allowedLicenses }) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const text = context.sourceCode.text,
|
|
10
|
+
id = license.spdx.parse(text)
|
|
11
|
+
if (!id) {
|
|
12
|
+
if (!requireSPDX) return
|
|
13
|
+
const inferredID = license.spdx.find(text),
|
|
14
|
+
report = { node, messageId: 'missingSPDX' }
|
|
15
|
+
if (inferredID && (!allowedLicenses.length || allowedLicenses.includes(inferredID)))
|
|
16
|
+
report.fix = fixer => license.spdx.appendTag(fixer, text, inferredID)
|
|
17
|
+
return context.report(report)
|
|
18
|
+
}
|
|
19
|
+
if (!license.spdx.isValid(id))
|
|
16
20
|
return context.report({ node, messageId: 'invalidSPDX', data: { id }})
|
|
17
21
|
if (allowedLicenses.length && !allowedLicenses.includes(id))
|
|
18
22
|
context.report({ node, messageId: 'disallowedSPDX', data: { id, allowed: allowedLicenses.join(', ') }})
|
|
@@ -21,6 +25,7 @@ function validateContent(context, node, { requireSPDX, allowedLicenses }) {
|
|
|
21
25
|
export default {
|
|
22
26
|
meta: {
|
|
23
27
|
type: 'problem',
|
|
28
|
+
fixable: 'code',
|
|
24
29
|
docs: {
|
|
25
30
|
description: 'Validates SPDX identifiers in license files',
|
|
26
31
|
recommended: false,
|
|
@@ -47,13 +52,15 @@ export default {
|
|
|
47
52
|
disallowedSPDX: 'License `{{id}}` is not in allowed list: {{allowed}}.'
|
|
48
53
|
}
|
|
49
54
|
},
|
|
55
|
+
|
|
50
56
|
create(context) {
|
|
51
57
|
const opts = context.options[0],
|
|
52
|
-
|
|
58
|
+
{ requireSPDX } = opts,
|
|
53
59
|
allowedLicenses = toArray(opts.allowedLicenses),
|
|
54
60
|
{ filename } = context,
|
|
55
61
|
basename = path.basename(filename)
|
|
56
|
-
if (!
|
|
62
|
+
if (!regex.filename.license.test(basename) || regex.filename.script.test(basename))
|
|
63
|
+
return {}
|
|
57
64
|
return { Program: node => validateContent(context, node, { requireSPDX, allowedLicenses })}
|
|
58
65
|
}
|
|
59
66
|
}
|