Skip to content

Commit e2cb799

Browse files
committed
feat: add support for Flat Config
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. 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', }, }, ]; ```
1 parent 417db45 commit e2cb799

File tree

7 files changed

+246
-96
lines changed

7 files changed

+246
-96
lines changed

config/flat/react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
module.exports = {
99
settings: {
10-
'import/extensions': ['.js', '.jsx'],
10+
'import/extensions': ['.js', '.jsx', '.mjs', '.cjs'],
1111
},
1212
languageOptions: {
1313
parserOptions: {

config/react.js

-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
* if you don't enable these settings at the top level.
77
*/
88
module.exports = {
9-
109
settings: {
1110
'import/extensions': ['.js', '.jsx'],
1211
},
1312

1413
parserOptions: {
1514
ecmaFeatures: { jsx: true },
1615
},
17-
1816
};

config/typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// `.ts`/`.tsx`/`.js`/`.jsx` implementation.
1010
const typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx'];
1111

12-
const allExtensions = [...typeScriptExtensions, '.js', '.jsx'];
12+
const allExtensions = [...typeScriptExtensions, '.js', '.jsx', '.mjs', '.cjs'];
1313

1414
module.exports = {
1515
settings: {

examples/flat/eslint.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default [
1414
ecmaVersion: 'latest',
1515
sourceType: 'module',
1616
},
17-
ignores: ['eslint.config.js', '**/exports-unused.ts'],
17+
ignores: ['eslint.config.mjs', '**/exports-unused.ts'],
1818
rules: {
1919
'no-unused-vars': 'off',
2020
'import/no-dynamic-require': 'warn',

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
109109
},
110110
"dependencies": {
111+
"@nodelib/fs.walk": "^2.0.0",
111112
"array-includes": "^3.1.7",
112113
"array.prototype.findlastindex": "^1.2.4",
113114
"array.prototype.flat": "^1.3.2",

0 commit comments

Comments
 (0)