Skip to content

Commit 8965b5d

Browse files
authored
Meta tweak, fix crash on no-useless-undefined (#2782)
1 parent 2ef6f83 commit 8965b5d

File tree

9 files changed

+132
-37
lines changed

9 files changed

+132
-37
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import globals from 'globals';
22
import xo from 'eslint-config-xo';
33
import eslintPlugin from 'eslint-plugin-eslint-plugin';
44
import jsdoc from 'eslint-plugin-jsdoc';
5+
import nodeStyleTextConfig from 'node-style-text/eslint-config';
56
import internalRules from './scripts/internal-rules/index.js';
67
import unicorn from './index.js';
78

89
const config = [
910
...xo,
1011
unicorn.configs.recommended,
12+
nodeStyleTextConfig,
1113
internalRules,
1214
{
1315
languageOptions: {

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,58 +58,58 @@
5858
"dependencies": {
5959
"@babel/helper-validator-identifier": "^7.27.1",
6060
"@eslint-community/eslint-utils": "^4.9.0",
61-
"@eslint/plugin-kit": "^0.3.5",
61+
"@eslint/plugin-kit": "^0.4.0",
6262
"change-case": "^5.4.4",
63-
"ci-info": "^4.3.0",
63+
"ci-info": "^4.3.1",
6464
"clean-regexp": "^1.0.0",
65-
"core-js-compat": "^3.45.1",
65+
"core-js-compat": "^3.46.0",
6666
"esquery": "^1.6.0",
6767
"find-up-simple": "^1.0.1",
68-
"globals": "^16.3.0",
68+
"globals": "^16.4.0",
6969
"indent-string": "^5.0.0",
7070
"is-builtin-module": "^5.0.0",
7171
"jsesc": "^3.1.0",
7272
"pluralize": "^8.0.0",
7373
"regexp-tree": "^0.1.27",
74-
"regjsparser": "^0.12.0",
75-
"semver": "^7.7.2",
76-
"strip-indent": "^4.0.0"
74+
"regjsparser": "^0.13.0",
75+
"semver": "^7.7.3",
76+
"strip-indent": "^4.1.1"
7777
},
7878
"devDependencies": {
7979
"@babel/code-frame": "^7.27.1",
8080
"@babel/core": "^7.28.4",
8181
"@babel/eslint-parser": "^7.28.4",
8282
"@eslint/eslintrc": "^3.3.1",
8383
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
84-
"@typescript-eslint/parser": "^8.43.0",
84+
"@typescript-eslint/parser": "^8.46.1",
8585
"ava": "^6.4.1",
8686
"c8": "^10.1.3",
8787
"enquirer": "^2.4.1",
88-
"eslint": "^9.35.0",
88+
"eslint": "^9.37.0",
8989
"eslint-ava-rule-tester": "^5.0.1",
9090
"eslint-config-xo": "^0.49.0",
91-
"eslint-doc-generator": "^2.2.2",
91+
"eslint-doc-generator": "^2.3.0",
9292
"eslint-plugin-eslint-plugin": "^7.0.0",
93-
"eslint-plugin-jsdoc": "^55.0.3",
93+
"eslint-plugin-jsdoc": "^61.1.2",
9494
"eslint-remote-tester": "^4.0.3",
9595
"eslint-remote-tester-repositories": "^2.0.2",
9696
"espree": "^10.4.0",
97-
"listr2": "^9.0.3",
97+
"listr2": "^9.0.4",
9898
"lodash-es": "^4.17.21",
9999
"markdownlint-cli": "^0.45.0",
100-
"nano-spawn": "^1.0.3",
101-
"node-style-text": "^1.0.0",
100+
"nano-spawn": "^2.0.0",
101+
"node-style-text": "^2.1.2",
102102
"npm-package-json-lint": "^9.0.0",
103103
"npm-run-all2": "^8.0.4",
104104
"open-editor": "^5.1.0",
105105
"outdent": "^0.8.0",
106-
"pretty-ms": "^9.2.0",
107-
"typescript": "^5.9.2",
106+
"pretty-ms": "^9.3.0",
107+
"typescript": "^5.9.3",
108108
"vue-eslint-parser": "^10.2.0",
109109
"yaml": "^2.8.1"
110110
},
111111
"peerDependencies": {
112-
"eslint": ">=9.35.0"
112+
"eslint": ">=9.37.0"
113113
},
114114
"ava": {
115115
"files": [

rules/no-useless-undefined.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {isCommaToken} from '@eslint-community/eslint-utils';
22
import {replaceNodeOrTokenAndSpacesBefore} from './fix/index.js';
33
import {isUndefined, isFunction} from './ast/index.js';
4+
import {getParenthesizedRange} from './utils/index.js';
45

56
const messageId = 'no-useless-undefined';
67
const messages = {
@@ -257,16 +258,16 @@ const create = context => {
257258
end: sourceCode.getLoc(lastUndefined).end,
258259
},
259260
fix(fixer) {
260-
let [start] = sourceCode.getRange(firstUndefined);
261-
let [, end] = sourceCode.getRange(lastUndefined);
261+
let [start] = getParenthesizedRange(firstUndefined, sourceCode);
262+
let [, end] = getParenthesizedRange(lastUndefined, sourceCode);
262263

263264
const previousArgument = argumentNodes[argumentNodes.length - undefinedArguments.length - 1];
264265

265266
if (previousArgument) {
266-
[, start] = sourceCode.getRange(previousArgument);
267+
[, start] = getParenthesizedRange(previousArgument, sourceCode);
267268
} else {
268269
// If all arguments removed, and there is trailing comma, we need remove it.
269-
const tokenAfter = sourceCode.getTokenAfter(lastUndefined);
270+
const tokenAfter = sourceCode.getTokenBefore(sourceCode.getLastToken(node));
270271
if (isCommaToken(tokenAfter)) {
271272
[, end] = sourceCode.getRange(tokenAfter);
272273
}

test/integration/projects.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,27 @@ export default [
163163
],
164164
},
165165
],
166-
{
167-
repository: 'https://github.com/gatsbyjs/gatsby',
168-
ignore: [
169-
// These files use `flow`
170-
'**/*.js',
171-
'packages/gatsby-cli/src/reporter/__tests__',
172-
],
173-
},
166+
[
167+
{
168+
repository: 'https://github.com/gatsbyjs/gatsby',
169+
ignore: [
170+
// These files use `flow`
171+
'**/*.js',
172+
'packages/gatsby-cli/src/reporter/__tests__',
173+
],
174+
},
175+
{
176+
repository: 'https://github.com/webpack/webpack',
177+
ignore: ['test/**/*'],
178+
},
179+
],
174180
{
175181
repository: 'https://github.com/vercel/next.js',
176182
ignore: [
177183
'examples/**',
178-
179-
// These files use `>` in jsx
180-
'test/integration/**',
181-
182-
// Contains Flow syntax
183-
'test/e2e/babel/fixture/**',
184+
'test/**',
185+
'**/tests/**',
186+
'**/compiled/**',
184187
],
185188
},
186189
// #903

test/integration/run-eslint.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ async function runEslint(project) {
122122
],
123123
fix: true,
124124
errorOnUnmatchedPattern: false,
125+
/*
126+
TODO: Try to figure out how to make it work, currently it throws error
127+
"The option "overrideConfig" cannot be cloned. When concurrency is enabled, all options must be cloneable values (JSON values). Remove uncloneable options or use an options module."
128+
*/
129+
// concurrency: 'auto',
125130
});
126131

127132
const startTime = process.hrtime.bigint();
@@ -145,7 +150,7 @@ async function runEslint(project) {
145150
const fixableWarningCount = sum(results, 'fixableWarningCount');
146151
console.log();
147152
console.log(outdent`
148-
${styleText.green.bold.underline(`[${project.name}]`)} ${results.length} files linted:
153+
${styleText.green.bold.underline`[${project.name}]`} ${results.length} files linted:
149154
- error: ${styleText.gray(String(errorCount))}
150155
- warning: ${styleText.gray(String(warningCount))}
151156
- fixable error: ${styleText.gray(String(fixableErrorCount))}

test/integration/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function printEslintError(error) {
8080

8181
console.log();
8282
console.error(
83-
styleText.red.bold.underline(`[${project.name}]`),
83+
styleText.red.bold.underline`[${project.name}]`,
8484
message,
8585
);
8686

test/no-useless-undefined.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ test.snapshot({
449449
'foo.bind?.(bar, undefined)',
450450
'foo[bind](bar, undefined)',
451451
'foo.notBind(bar, undefined)',
452+
// https://github.com/webpack/webpack/blob/0f84d1e3bf69915dc060f23ced9dfa468a884a42/lib/wasm-sync/WasmFinalizeExportsPlugin.js#L49
453+
outdent`
454+
const referencedExports =
455+
compilation.getDependencyReferencedExports(
456+
/** @type {Dependency} */ (connection.dependency),
457+
undefined
458+
);
459+
`,
460+
'foo( ((a)), ((undefined)), ((undefined)), )',
461+
'foo( ((undefined)), ((undefined)), )',
452462
],
453463
});
454464

test/snapshots/no-useless-undefined.js.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,80 @@ Generated by [AVA](https://avajs.dev).
360360
| ^^^^^^^^^ Do not use useless \`undefined\`.␊
361361
`
362362

363+
## invalid(13): const referencedExports = compilation.getDependencyReferencedExports( /** @type {Dependency} */ (connection.dependency), undefined );
364+
365+
> Input
366+
367+
`␊
368+
1 | const referencedExports =␊
369+
2 | compilation.getDependencyReferencedExports(␊
370+
3 | /** @type {Dependency} */ (connection.dependency),␊
371+
4 | undefined␊
372+
5 | );␊
373+
`
374+
375+
> Output
376+
377+
`␊
378+
1 | const referencedExports =␊
379+
2 | compilation.getDependencyReferencedExports(␊
380+
3 | /** @type {Dependency} */ (connection.dependency)␊
381+
4 | );␊
382+
`
383+
384+
> Error 1/1
385+
386+
`␊
387+
1 | const referencedExports =␊
388+
2 | compilation.getDependencyReferencedExports(␊
389+
3 | /** @type {Dependency} */ (connection.dependency),␊
390+
> 4 | undefined␊
391+
| ^^^^^^^^^ Do not use useless \`undefined\`.␊
392+
5 | );␊
393+
`
394+
395+
## invalid(14): foo( ((a)), ((undefined)), ((undefined)), )
396+
397+
> Input
398+
399+
`␊
400+
1 | foo( ((a)), ((undefined)), ((undefined)), )␊
401+
`
402+
403+
> Output
404+
405+
`␊
406+
1 | foo( ((a)), )␊
407+
`
408+
409+
> Error 1/1
410+
411+
`␊
412+
> 1 | foo( ((a)), ((undefined)), ((undefined)), )␊
413+
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not use useless \`undefined\`.␊
414+
`
415+
416+
## invalid(15): foo( ((undefined)), ((undefined)), )
417+
418+
> Input
419+
420+
`␊
421+
1 | foo( ((undefined)), ((undefined)), )␊
422+
`
423+
424+
> Output
425+
426+
`␊
427+
1 | foo( )␊
428+
`
429+
430+
> Error 1/1
431+
432+
`␊
433+
> 1 | foo( ((undefined)), ((undefined)), )␊
434+
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not use useless \`undefined\`.␊
435+
`
436+
363437
## invalid(1): <script> import {nextTick} from 'vue'; const foo = nextTick(undefined); </script>
364438

365439
> Input
229 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)