Skip to content

Commit

Permalink
[Fix] no-unused-modules: don't error out when running with flat con…
Browse files Browse the repository at this point in the history
…fig and an eslintrc isn't present

This change adjusts how we're instantiating the FileEnumerator from eslint's unsupported api, in the case that the user is running with flat config.  We have to turn off the `useEslintrc` property on the ConfigArrayFactory that's passed into the FileEnumerator's constructor.

Note: This doesn't fix the fact that the FileEnumerator doesn't have knowledge of what the user's config is ignoring, it just prevents the rule from looking for a legacy / rc config and erroring out.  FileEnumerator used the rc config to understand which files to ignore.
  • Loading branch information
michaelfaith committed Dec 20, 2024
1 parent 78c3a55 commit 7ba8372
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 192 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- add [`enforce-node-protocol-usage`] rule and `import/node-version` setting ([#3024], thanks [@GoldStrikeArch] and [@sevenc-nanashi])
- add TypeScript types ([#3097], thanks [@G-Rath])

### Fixed
- [`no-unused-modules`]: don't error out when running with flat config and an eslintrc isn't present ([#3116], thanks [@michaelfaith])

### Changed
- [Docs] [`extensions`], [`order`]: improve documentation ([#3106], thanks [@Xunnamius])

Expand Down Expand Up @@ -1161,6 +1164,7 @@ for info on changes for earlier releases.

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

[#3116]: https://github.com/import-js/eslint-plugin-import/pull/3116
[#3106]: https://github.com/import-js/eslint-plugin-import/pull/3106
[#3097]: https://github.com/import-js/eslint-plugin-import/pull/3097
[#3073]: https://github.com/import-js/eslint-plugin-import/pull/3073
Expand Down
1 change: 1 addition & 0 deletions examples/flat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-plugin-import": "file:../..",
"move-file-cli": "^3.0.0",
"typescript": "^5.4.5"
}
}
26 changes: 26 additions & 0 deletions examples/v9/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import importPlugin from 'eslint-plugin-import';
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';

export default [
js.configs.recommended,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.react,
importPlugin.flatConfigs.typescript,
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
},
ignores: ['eslint.config.mjs', '**/exports-unused.ts'],
rules: {
'no-unused-vars': 'off',
'import/no-dynamic-require': 'warn',
'import/no-nodejs-modules': 'warn',
'import/no-unused-modules': ['warn', { unusedExports: true }],
'import/no-cycle': 'warn',
},
},
];
18 changes: 18 additions & 0 deletions examples/v9/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "v9",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"lint": "eslint src --report-unused-disable-directives"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@types/node": "^20.14.5",
"@typescript-eslint/parser": "^8.18.0",
"cross-env": "^7.0.3",
"eslint": "^9.17.0",
"eslint-plugin-import": "file:../..",
"move-file-cli": "^3.0.0",
"typescript": "^5.4.5"
}
}
3 changes: 3 additions & 0 deletions examples/v9/src/depth-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { foo } from "./es6/depth-one-dynamic";

foo();
3 changes: 3 additions & 0 deletions examples/v9/src/es6/depth-one-dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo() {}

export const bar = () => import("../depth-zero").then(({foo}) => foo);
12 changes: 12 additions & 0 deletions examples/v9/src/exports-unused.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type ScalarType = string | number;
export type ObjType = {
a: ScalarType;
b: ScalarType;
};

export const a = 13;
export const b = 18;

const defaultExport: ObjType = { a, b };

export default defaultExport;
12 changes: 12 additions & 0 deletions examples/v9/src/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type ScalarType = string | number;
export type ObjType = {
a: ScalarType;
b: ScalarType;
};

export const a = 13;
export const b = 18;

const defaultExport: ObjType = { a, b };

export default defaultExport;
7 changes: 7 additions & 0 deletions examples/v9/src/imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import c from './exports';
import { a, b } from './exports';
import type { ScalarType, ObjType } from './exports';

import path from 'path';
import fs from 'node:fs';
import console from 'console';
3 changes: 3 additions & 0 deletions examples/v9/src/jsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Components = () => {
return <></>;
};
14 changes: 14 additions & 0 deletions examples/v9/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"rootDir": "./",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"test": "npm run tests-only",
"test-compiled": "npm run prepublish && BABEL_ENV=testCompiled mocha --compilers js:babel-register tests/src",
"test-all": "node --require babel-register ./scripts/testAll",
"test-examples": "npm run build && npm run test-example:legacy && npm run test-example:flat",
"test-examples": "npm run build && npm run test-example:legacy && npm run test-example:flat && npm run test-example:v9",
"test-example:legacy": "cd examples/legacy && npm install && npm run lint",
"test-example:flat": "cd examples/flat && npm install && npm run lint",
"test-example:v9": "cd examples/v9 && npm install && npm run lint",
"test-types": "npx --package typescript@latest tsc --noEmit index.d.ts",
"prepublishOnly": "safe-publish-latest && npm run build",
"prepublish": "not-in-publish || npm run prepublishOnly",
Expand Down
48 changes: 0 additions & 48 deletions src/core/fsWalk.js

This file was deleted.

Loading

0 comments on commit 7ba8372

Please sign in to comment.