eslint-plugin-chrome-extensions 2.5.0 → 2.6.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.
@@ -13,7 +13,7 @@ export default {
13
13
  docs: {
14
14
  description: 'Validate the manifest version field format',
15
15
  category: 'Possible Errors',
16
- recommended: false,
16
+ recommended: true,
17
17
  manifest: true
18
18
  },
19
19
  schema: [{
@@ -3,6 +3,9 @@
3
3
  import fs from 'node:fs'
4
4
  import path from 'node:path'
5
5
 
6
+ import permissions from '../data/permissions.js'
7
+ import regex from '../data/regex.js'
8
+
6
9
  const manifestCache = new Map()
7
10
 
8
11
  const utils = {
@@ -36,6 +39,16 @@ const utils = {
36
39
  },
37
40
 
38
41
  manifest: {
42
+ permission: {
43
+ valid: permissions.valid,
44
+ sensitive: permissions.sensitive,
45
+ isValid(name, target = 'mv3') {
46
+ if (permissions.valid.has(name)) return true
47
+ if (target == 'mv3') return false
48
+ return regex.url.test(name) || name.startsWith('<') || name == '*://*/*'
49
+ }
50
+ },
51
+
39
52
  read(context) {
40
53
  const root = utils.findRoot(context) ; if (!root) return null
41
54
  if (manifestCache.has(root)) return manifestCache.get(root)
package/src/utils/i18n.js CHANGED
@@ -43,6 +43,9 @@ export default {
43
43
 
44
44
  isPredefined(key) { return key.startsWith('@@') },
45
45
 
46
+ localeIsValid(code, allowed = new Set()) {
47
+ return typeof code == 'string' && (allowed.has(code) || i18n.locales.supported.has(code)) },
48
+
46
49
  readDefaultLocaleMessages(manifest, root) {
47
50
  const locale = manifest?.default_locale
48
51
  if (typeof locale != 'string') return null
package/src/utils/init.js CHANGED
@@ -11,6 +11,7 @@ import noDeprecatedAPIs from '../rules/no-deprecated-apis.js'
11
11
  import noDuplicateManifestKeys from '../rules/no-duplicate-manifest-keys.js'
12
12
  import noInsecureFetch from '../rules/no-insecure-fetch.js'
13
13
  import noInsecureMessaging from '../rules/no-insecure-messaging.js'
14
+ import noInvalidLocales from '../rules/no-invalid-locales.js'
14
15
  import noInvalidPermissions from '../rules/no-invalid-permissions.js'
15
16
  import noMissingDefaultLocale from '../rules/no-missing-default-locale.js'
16
17
  import noMissingI18nKeys from '../rules/no-missing-i18n-keys.js'
@@ -67,7 +68,7 @@ export default {
67
68
  }
68
69
  },
69
70
 
70
- plugin() { return { rules: {}, configs: {}}},
71
+ plugin() { return { rules: {}, configs: {} }},
71
72
 
72
73
  rules(plugin) {
73
74
  plugin.rules = {
@@ -78,6 +79,7 @@ export default {
78
79
  'no-duplicate-manifest-keys': noDuplicateManifestKeys,
79
80
  'no-insecure-fetch': noInsecureFetch,
80
81
  'no-insecure-messaging': noInsecureMessaging,
82
+ 'no-invalid-locales': noInvalidLocales,
81
83
  'no-invalid-permissions': noInvalidPermissions,
82
84
  'no-missing-default-locale': noMissingDefaultLocale,
83
85
  'no-missing-i18n-keys': noMissingI18nKeys,
@@ -14,8 +14,7 @@ const re = { spdxTag: /SPDX-License-Identifier:\s*([\w.-]+)/i },
14
14
  .map(([id, { name }]) => ({ id, name }))
15
15
  .sort((a, b) => b.name.length - a.name.length)
16
16
 
17
- function tryReaddir(dir) {
18
- try { return fs.readdirSync(dir, { withFileTypes: true }) } catch { return null }}
17
+ function tryReaddir(dir) { try { return fs.readdirSync(dir, { withFileTypes: true }) } catch { return null }}
19
18
 
20
19
  export default {
21
20
  find(root) {
@@ -38,6 +37,7 @@ export default {
38
37
  trailer = `${text.endsWith(nl) ? '' : nl}${nl}SPDX-License-Identifier: ${id}${nl}`
39
38
  return fixer.insertTextAfterRange([0, text.length], trailer)
40
39
  },
40
+
41
41
  find(text) {
42
42
  const normalizedTxt = text.replace(/\s+/g, ' ')
43
43
  let best = null
@@ -49,6 +49,7 @@ export default {
49
49
  }
50
50
  return best?.id ?? null
51
51
  },
52
+
52
53
  isValid(id) { return spdxIDs.has(id) },
53
54
  parse(text) { return text.match(re.spdxTag)?.[1] ?? null }
54
55
  }