Skip to content

Commit c826688

Browse files
committed
Cleanup eslint.config.js
1 parent 37777a9 commit c826688

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

eslint.config.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const sortDestructureKeysPlugin = require('eslint-plugin-sort-destructure-keys')
1010
const unicornPlugin = require('eslint-plugin-unicorn')
1111

1212
const constants = require('@socketsecurity/registry/lib/constants')
13-
const { GIT_IGNORE, PRETTIER_IGNORE } = constants
13+
const { GIT_IGNORE, LATEST, PRETTIER_IGNORE } = constants
1414

1515
const rootPath = __dirname
1616

@@ -25,9 +25,12 @@ module.exports = [
2525
...importXPlugin.flatConfigs.recommended,
2626
languageOptions: {
2727
...importXPlugin.flatConfigs.recommended.languageOptions,
28-
ecmaVersion: 'latest',
28+
ecmaVersion: LATEST,
2929
sourceType: 'script'
3030
},
31+
linterOptions: {
32+
reportUnusedDisableDirectives: 'off'
33+
},
3134
rules: {
3235
...importXPlugin.flatConfigs.recommended.rules,
3336
'import-x/no-named-as-default-member': 'off',
@@ -58,17 +61,10 @@ module.exports = [
5861
}
5962
},
6063
{
61-
files: ['scripts/**/*.js', 'test/**/*.cjs'],
62-
...nodePlugin.configs['flat/recommended-script']
63-
},
64-
{
65-
files: ['scripts/**/*.js', 'test/**/*.cjs'],
66-
plugins: {
67-
'sort-destructure-keys': sortDestructureKeysPlugin,
68-
unicorn: unicornPlugin
69-
},
64+
files: ['scripts/**/*.{c,}js', 'test/**/*.{c,}js'],
65+
...nodePlugin.configs['flat/recommended-script'],
7066
rules: {
71-
...js.configs.recommended.rules,
67+
...nodePlugin.configs['flat/recommended-script'].rules,
7268
'n/exports-style': ['error', 'module.exports'],
7369
// The n/no-unpublished-bin rule does does not support non-trivial glob
7470
// patterns used in package.json "files" fields. In those cases we simplify
@@ -84,7 +80,17 @@ module.exports = [
8480
version: constants.maintainedNodeVersions.previous
8581
}
8682
],
87-
'n/prefer-node-protocol': ['error'],
83+
'n/prefer-node-protocol': ['error']
84+
}
85+
},
86+
{
87+
files: ['scripts/**/*.{c,}js', 'test/**/*.{c,}js'],
88+
plugins: {
89+
'sort-destructure-keys': sortDestructureKeysPlugin,
90+
unicorn: unicornPlugin
91+
},
92+
rules: {
93+
...js.configs.recommended.rules,
8894
'no-await-in-loop': ['error'],
8995
'no-control-regex': ['error'],
9096
'no-empty': ['error', { allowEmptyCatch: true }],

test/package-url.test.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@ describe('PackageURL', () => {
101101
}
102102

103103
it('should validate required params', () => {
104-
const testValid = paramName => {
104+
// eslint-disable-next-line unicorn/consistent-function-scoping
105+
function testValid(paramName) {
105106
const paramIndex = paramMap[paramName]
106107
const args = createArgs(paramName, paramName)
107108
const message = JSON.stringify(args[paramIndex])
108109
try {
110+
// eslint-disable-next-line no-new
109111
new PackageURL(...args)
110112
assert.ok(true, message)
111113
} catch {
112114
assert.ok(false, message)
113115
}
114116
}
115117

116-
const testInvalid = paramName => {
118+
// eslint-disable-next-line unicorn/consistent-function-scoping
119+
function testInvalid(paramName) {
117120
const paramIndex = paramMap[paramName]
118121
;[
119122
createArgs(paramName, 0),
@@ -127,6 +130,7 @@ describe('PackageURL', () => {
127130
].forEach(args => {
128131
const message = JSON.stringify(args[paramIndex])
129132
try {
133+
// eslint-disable-next-line no-new
130134
new PackageURL(...args)
131135
assert.ok(false, message)
132136
} catch {
@@ -135,14 +139,15 @@ describe('PackageURL', () => {
135139
})
136140
}
137141

138-
;['type', 'name'].forEach(paramName => {
142+
for (const paramName of ['type', 'name']) {
139143
testValid(paramName)
140144
testInvalid(paramName)
141-
})
145+
}
142146
})
143147

144148
it('should validate string params', () => {
145-
const testValid = paramName => {
149+
// eslint-disable-next-line unicorn/consistent-function-scoping
150+
function testValid(paramName) {
146151
const paramIndex = paramMap[paramName]
147152
;[
148153
createArgs(paramName, paramName),
@@ -152,6 +157,7 @@ describe('PackageURL', () => {
152157
].forEach(args => {
153158
const message = JSON.stringify(args[paramIndex])
154159
try {
160+
// eslint-disable-next-line no-new
155161
new PackageURL(...args)
156162
assert.ok(true, message)
157163
} catch {
@@ -160,7 +166,8 @@ describe('PackageURL', () => {
160166
})
161167
}
162168

163-
const testInvalid = paramName => {
169+
// eslint-disable-next-line unicorn/consistent-function-scoping
170+
function testInvalid(paramName) {
164171
const paramIndex = paramMap[paramName]
165172
;[
166173
createArgs(paramName, 0),
@@ -171,6 +178,7 @@ describe('PackageURL', () => {
171178
].forEach(args => {
172179
const message = JSON.stringify(args[paramIndex])
173180
try {
181+
// eslint-disable-next-line no-new
174182
new PackageURL(...args)
175183
assert.ok(false, message)
176184
} catch {
@@ -179,10 +187,10 @@ describe('PackageURL', () => {
179187
})
180188
}
181189

182-
;['namespace', 'version', 'subpath'].forEach(paramName => {
190+
for (const paramName of ['namespace', 'version', 'subpath']) {
183191
testValid(paramName)
184192
testInvalid(paramName)
185-
})
193+
}
186194
})
187195

188196
it('should not decode params', () => {
@@ -489,7 +497,7 @@ describe('PackageURL', () => {
489497
const parts = builtinName.split('/')
490498
const namespace = parts.length > 1 ? parts[0] : ''
491499
const name = parts.at(-1)
492-
500+
// eslint-disable-next-line no-new
493501
new PackageURL('npm', namespace, name)
494502
}, `assert for ${builtinName}`)
495503
}

0 commit comments

Comments
 (0)