Skip to content

Commit dda50b9

Browse files
committed
[Fix] no-unused-modules`: don't error out when running with flat config and an eslintrc isn't present
This change adjusts what we're doing if an error is thrown while attempting to enumerate lintable files in the no-used-modules rule, when users are running with flat config. Now, if FileEnumerator throws due to a lack of eslintrc and the user is running with flat config, we catch the error and rethrow with a more informative message. I also cleaned up the original aspects of the implementation that was using the proposed eslint context functions, since that proposal was walked back and the API was never introduced. Note: This isn't an ideal state, since this rule still relies on the legacy api to understand what needs to be ignored. Remaining tethered to the legacy config system is going to need to be solved at some point. Fixes #3079
1 parent 8b2d570 commit dda50b9

File tree

12 files changed

+150
-116
lines changed

12 files changed

+150
-116
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1010
- add [`enforce-node-protocol-usage`] rule and `import/node-version` setting ([#3024], thanks [@GoldStrikeArch] and [@sevenc-nanashi])
1111
- add TypeScript types ([#3097], thanks [@G-Rath])
1212

13+
### Fixed
14+
- [`no-unused-modules`]: don't error out when running with flat config and an eslintrc isn't present ([#3116], thanks [@michaelfaith])
15+
1316
### Changed
1417
- [Docs] [`extensions`], [`order`]: improve documentation ([#3106], thanks [@Xunnamius])
1518

@@ -1161,6 +1164,7 @@ for info on changes for earlier releases.
11611164

11621165
[`memo-parser`]: ./memo-parser/README.md
11631166

1167+
[#3116]: https://github.com/import-js/eslint-plugin-import/pull/3116
11641168
[#3106]: https://github.com/import-js/eslint-plugin-import/pull/3106
11651169
[#3097]: https://github.com/import-js/eslint-plugin-import/pull/3097
11661170
[#3073]: https://github.com/import-js/eslint-plugin-import/pull/3073

examples/v9/eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import importPlugin from 'eslint-plugin-import';
2+
import js from '@eslint/js';
3+
4+
export default [
5+
js.configs.recommended,
6+
importPlugin.flatConfigs.recommended,
7+
{
8+
files: ['**/*.{js,mjs,cjs}'],
9+
languageOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
},
13+
ignores: ['eslint.config.mjs'],
14+
rules: {
15+
'no-unused-vars': 'off',
16+
'import/no-dynamic-require': 'warn',
17+
'import/no-nodejs-modules': 'warn',
18+
'import/no-unused-modules': ['warn', { unusedExports: true }],
19+
'import/no-cycle': 'warn',
20+
},
21+
},
22+
];

examples/v9/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "v9",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"type": "module",
6+
"scripts": {
7+
"lint": "eslint src --report-unused-disable-directives"
8+
},
9+
"devDependencies": {
10+
"@eslint/js": "^9.17.0",
11+
"eslint": "^9.17.0",
12+
"eslint-plugin-import": "file:../.."
13+
}
14+
}

examples/v9/src/depth-zero.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { foo } from "./es6/depth-one-dynamic";
2+
3+
foo();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function foo() {}
2+
3+
export const bar = () => import("../depth-zero").then(({foo}) => foo);

examples/v9/src/exports-unused.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const a = 13;
2+
export const b = 18;
3+
4+
const defaultExport = { a, b };
5+
6+
export default defaultExport;

examples/v9/src/exports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const a = 13;
2+
export const b = 18;
3+
4+
const defaultExport = { a, b };
5+
6+
export default defaultExport;

examples/v9/src/imports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//import c from './exports';
2+
import { a, b } from './exports';
3+
4+
import path from 'path';
5+
import fs from 'node:fs';
6+
import console from 'console';

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"test": "npm run tests-only",
3434
"test-compiled": "npm run prepublish && BABEL_ENV=testCompiled mocha --compilers js:babel-register tests/src",
3535
"test-all": "node --require babel-register ./scripts/testAll",
36-
"test-examples": "npm run build && npm run test-example:legacy && npm run test-example:flat",
36+
"test-examples": "npm run build && npm run test-example:legacy && npm run test-example:flat && npm run test-example:v9",
3737
"test-example:legacy": "cd examples/legacy && npm install && npm run lint",
3838
"test-example:flat": "cd examples/flat && npm install && npm run lint",
39+
"test-example:v9": "cd examples/v9 && npm install && npm run lint",
3940
"test-types": "npx --package typescript@latest tsc --noEmit index.d.ts",
4041
"prepublishOnly": "safe-publish-latest && npm run build",
4142
"prepublish": "not-in-publish || npm run prepublishOnly",
@@ -106,6 +107,7 @@
106107
"rimraf": "^2.7.1",
107108
"safe-publish-latest": "^2.0.0",
108109
"sinon": "^2.4.1",
110+
"tmp": "^0.2.1",
109111
"typescript": "^2.8.1 || ~3.9.5 || ~4.5.2",
110112
"typescript-eslint-parser": "^15 || ^20 || ^22"
111113
},

src/core/fsWalk.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy