Skip to content

Commit 9acd806

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 9acd806

File tree

15 files changed

+188
-116
lines changed

15 files changed

+188
-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/flat/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"cross-env": "^7.0.3",
1313
"eslint": "^8.57.0",
1414
"eslint-plugin-import": "file:../..",
15+
"move-file-cli": "^3.0.0",
1516
"typescript": "^5.4.5"
1617
}
1718
}

examples/v9/eslint.config.mjs

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

examples/v9/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "v9",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"lint": "eslint src --report-unused-disable-directives"
7+
},
8+
"devDependencies": {
9+
"@eslint/js": "^9.17.0",
10+
"@types/node": "^20.14.5",
11+
"@typescript-eslint/parser": "^8.18.0",
12+
"cross-env": "^7.0.3",
13+
"eslint": "^9.17.0",
14+
"eslint-plugin-import": "file:../..",
15+
"move-file-cli": "^3.0.0",
16+
"typescript": "^5.4.5"
17+
}
18+
}

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.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type ScalarType = string | number;
2+
export type ObjType = {
3+
a: ScalarType;
4+
b: ScalarType;
5+
};
6+
7+
export const a = 13;
8+
export const b = 18;
9+
10+
const defaultExport: ObjType = { a, b };
11+
12+
export default defaultExport;

examples/v9/src/exports.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type ScalarType = string | number;
2+
export type ObjType = {
3+
a: ScalarType;
4+
b: ScalarType;
5+
};
6+
7+
export const a = 13;
8+
export const b = 18;
9+
10+
const defaultExport: ObjType = { a, b };
11+
12+
export default defaultExport;

examples/v9/src/imports.ts

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

examples/v9/src/jsx.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Components = () => {
2+
return <></>;
3+
};

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