eslint-plugin-greasemonkey 1.9.0 → 1.10.1

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.
@@ -0,0 +1,56 @@
1
+ // oxlint-disable security/detect-non-literal-fs-filename
2
+
3
+ import { createRequire } from 'node:module'
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+
7
+ import regex from '../data/regex.js'
8
+
9
+ const re = { spdxTag: /SPDX-License-Identifier:\s*([\w.-]+)/i },
10
+ require = createRequire(import.meta.url),
11
+ skipDirs = new Set(['node_modules']),
12
+ spdxIDs = new Set(require('spdx-license-ids')),
13
+ spdxNames = Object.entries(require('spdx-license-list'))
14
+ .map(([id, { name }]) => ({ id, name }))
15
+ .sort((a, b) => b.name.length - a.name.length)
16
+
17
+ function tryReaddir(dir) { try { return fs.readdirSync(dir, { withFileTypes: true }) } catch { return null }}
18
+
19
+ export default {
20
+ find(root) {
21
+ const queue = [root]
22
+ while (queue.length) {
23
+ const dir = queue.shift(), entries = tryReaddir(dir)
24
+ if (!entries) continue
25
+ for (const entry of entries) {
26
+ if (entry.name.startsWith('.') || skipDirs.has(entry.name)) continue
27
+ if (entry.isFile() && regex.filename.license.test(entry.name)) return path.join(dir, entry.name)
28
+ if (entry.isDirectory()) queue.push(path.join(dir, entry.name))
29
+ }
30
+ }
31
+ return null
32
+ },
33
+
34
+ spdx: {
35
+ appendTag(fixer, text, id) {
36
+ const nl = text.includes('\r\n') ? '\r\n' : '\n',
37
+ trailer = `${text.endsWith(nl) ? '' : nl}${nl}SPDX-License-Identifier: ${id}${nl}`
38
+ return fixer.insertTextAfterRange([0, text.length], trailer)
39
+ },
40
+
41
+ find(text) {
42
+ const normalizedTxt = text.replace(/\s+/g, ' ')
43
+ let best = null
44
+ for (const { id, name } of spdxNames) {
45
+ const idx = normalizedTxt.indexOf(name)
46
+ if (idx == -1) continue
47
+ if (!best || idx < best.idx || (idx == best.idx && name.length > best.name.length))
48
+ best = { id, idx, name }
49
+ }
50
+ return best?.id ?? null
51
+ },
52
+
53
+ isValid(id) { return spdxIDs.has(id) },
54
+ parse(text) { return text.match(re.spdxTag)?.[1] ?? null }
55
+ }
56
+ }
@@ -1,4 +1,4 @@
1
- const re = { whitespace: /\s/ }
1
+ import regex from '../data/regex.js'
2
2
 
3
3
  export default {
4
4
  createBlock(...entries) {
@@ -20,7 +20,7 @@ export default {
20
20
  if (!inMetaBlock && text == '==UserScript==') inMetaBlock = true
21
21
  else if (inMetaBlock && text == '==/UserScript==') break
22
22
  else if (inMetaBlock && text.startsWith('@')) { // capture entry
23
- const spaceIdx = text.search(re.whitespace),
23
+ const spaceIdx = text.search(regex.whitespace.all),
24
24
  key = ( spaceIdx == -1 ? text.slice(1) : text.slice(1, spaceIdx) ).trim(),
25
25
  value = spaceIdx == -1 ? '' : text.slice(spaceIdx +1).trim()
26
26
  if (key) metaEntries.push({ key, value, comment, line: comment.loc.start.line })
@@ -0,0 +1,21 @@
1
+ import { fileURLToPath } from 'node:url'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ export default {
6
+ getName() { // oxlint-disable security/detect-non-literal-fs-filename
7
+ let current = path.dirname(fileURLToPath(import.meta.url))
8
+ while (current) {
9
+ const pkgPath = path.join(current, 'package.json')
10
+ if (fs.existsSync(pkgPath))
11
+ try {
12
+ const { name } = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
13
+ if (name) return name
14
+ } catch { /* malformed, keep walking */ }
15
+ const parent = path.dirname(current)
16
+ if (parent === current) return null
17
+ current = parent
18
+ }
19
+ return null
20
+ } // oxlint-enable security/detect-non-literal-fs-filename
21
+ }
@@ -11,7 +11,7 @@ export default {
11
11
  if (!combos) return null
12
12
  const withQuasi = combos.map(combo => combo + quasi.value.raw)
13
13
  if (idx >= n.expressions.length) return withQuasi
14
- const vals = walk(n.expressions[idx]) // eslint-disable-line security/detect-object-injection -- AST array indices are bounded
14
+ const vals = walk(n.expressions[idx]) // oxlint-disable-line security/detect-object-injection
15
15
  return vals ? withQuasi.flatMap(combo => vals.map(val => combo + val)) : null
16
16
  }, [''])
17
17
  else return null