Skip to content

feat: add flat config support#122

Merged
SukkaW merged 2 commits intoun-ts:masterfrom
michaelfaith:feat/flat-config-support-x
Aug 26, 2024
Merged

feat: add flat config support#122
SukkaW merged 2 commits intoun-ts:masterfrom
michaelfaith:feat/flat-config-support-x

Conversation

@michaelfaith
Copy link
Copy Markdown
Contributor

@michaelfaith michaelfaith commented Aug 4, 2024

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

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',
    },
  },
];

Closes #29

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support eslint flat config

5 participants