-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well. To achieve this, we're now dynamically creating flat configs on a new `flatConfigs` export. I was a bit on the fence about using this convention, or the other convention that's become prevalent in the community: adding the flat configs directly to the `configs` object, but with a 'flat/' prefix. I like this better, since it's slightly more ergonomic when using it in practice. e.g. `...importX.flatConfigs.recommended` vs `...importX.configs['flat/recommended']`, but i'm open to changing that. Example Usage ```js 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.js'], rules: { 'no-unused-vars': 'off', 'import/no-dynamic-require': 'warn', 'import/no-nodejs-modules': 'warn', }, }, ]; ``` Note: in order to fill a gap in a future API gap for the `no-unused-module`, this takes advantage of a *proposed* new API on the ESLint context, that currently only exists in a POC state (unreleased). Closes import-js#2556
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import importPlugin from 'eslint-plugin-import-x'; | ||
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-x/no-dynamic-require': 'warn', | ||
'import-x/no-nodejs-modules': 'warn', | ||
'import-x/no-unused-modules': ['warn', { unusedExports: true }], | ||
}, | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "flat", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"clean": "rimraf node_modules", | ||
"lint": "cross-env ESLINT_USE_FLAT_CONFIG=true eslint src --report-unused-disable-directives" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.5.0", | ||
"@types/node": "^20.14.5", | ||
"@typescript-eslint/parser": "^7.13.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-import-x": "link:../..", | ||
"rimraf": "^6.0.1", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
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; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//import c from './exports'; | ||
import { a, b } from './exports'; | ||
Check failure on line 2 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 2 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 2 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
||
import type { ScalarType, ObjType } from './exports'; | ||
Check failure on line 3 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 3 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 3 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
||
|
||
import path from 'path'; | ||
Check failure on line 5 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 5 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 5 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
||
import fs from 'node:fs'; | ||
Check failure on line 6 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 6 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 6 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
||
import console from 'console'; | ||
Check failure on line 7 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 7 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 7 in examples/flat/src/imports.ts GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const Components = () => { | ||
Check failure on line 1 in examples/flat/src/jsx.tsx GitHub Actions / Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
Check failure on line 1 in examples/flat/src/jsx.tsx GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on macos-latest
Check failure on line 1 in examples/flat/src/jsx.tsx GitHub Actions / Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
|
||
return <></>; | ||
}; |
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 | ||
} | ||
} |