Skip to content

Commit

Permalink
feat: add support for Flat Config
Browse files Browse the repository at this point in the history
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',
    },
  },
];
```
  • Loading branch information
michaelfaith committed Jul 14, 2024
1 parent 417db45 commit e2cb799
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 96 deletions.
2 changes: 1 addition & 1 deletion config/flat/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
module.exports = {
settings: {
'import/extensions': ['.js', '.jsx'],
'import/extensions': ['.js', '.jsx', '.mjs', '.cjs'],
},
languageOptions: {
parserOptions: {
Expand Down
2 changes: 0 additions & 2 deletions config/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* if you don't enable these settings at the top level.
*/
module.exports = {

settings: {
'import/extensions': ['.js', '.jsx'],
},

parserOptions: {
ecmaFeatures: { jsx: true },
},

};
2 changes: 1 addition & 1 deletion config/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// `.ts`/`.tsx`/`.js`/`.jsx` implementation.
const typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx'];

const allExtensions = [...typeScriptExtensions, '.js', '.jsx'];
const allExtensions = [...typeScriptExtensions, '.js', '.jsx', '.mjs', '.cjs'];

module.exports = {
settings: {
Expand Down
2 changes: 1 addition & 1 deletion examples/flat/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default [
ecmaVersion: 'latest',
sourceType: 'module',
},
ignores: ['eslint.config.js', '**/exports-unused.ts'],
ignores: ['eslint.config.mjs', '**/exports-unused.ts'],
rules: {
'no-unused-vars': 'off',
'import/no-dynamic-require': 'warn',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
},
"dependencies": {
"@nodelib/fs.walk": "^2.0.0",
"array-includes": "^3.1.7",
"array.prototype.findlastindex": "^1.2.4",
"array.prototype.flat": "^1.3.2",
Expand Down
Loading

0 comments on commit e2cb799

Please sign in to comment.