eslint-plugin-import-x icon indicating copy to clipboard operation
eslint-plugin-import-x copied to clipboard

feat: add flat config support

Open michaelfaith opened this issue 1 year ago • 11 comments
trafficstars

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

michaelfaith avatar Aug 04 '24 16:08 michaelfaith

🦋 Changeset detected

Latest commit: 19f0214616cefd4a5513d80d11ca3d4635ab6880

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-import-x Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Aug 04 '24 16:08 changeset-bot[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Aug 04 '24 16:08 codesandbox-ci[bot]

Are the unit tests in this repo supposed to be passing? I noticed they failed in my branch, and so I checked out current master branch, and they're also failing for me there. Is it my setup, or are they just not working?

michaelfaith avatar Aug 04 '24 16:08 michaelfaith

flat configs on a new flatConfigs export

I like it personally as well as I find configs['flat/recommended'] a bit ugly.

silverwind avatar Aug 06 '24 18:08 silverwind

Are the unit tests in this repo supposed to be passing? I noticed they failed in my branch, and so I checked out current master branch, and they're also failing for me there. Is it my setup, or are they just not working?

Tests are passing for me on master branch with yarn && yarn build && yarn test:

Test Suites: 54 passed, 54 total
Tests:       4 skipped, 2665 passed, 2669 total
Snapshots:   0 total
Time:        7.388 s

silverwind avatar Aug 06 '24 18:08 silverwind

@michaelfaith We can probably split this PR into two: a PR that adds a flat config preset without no-unused-modules, and another PR that adds flat config support for no-unused-module.

With this, people can start using the flat presets right away.

SukkaW avatar Aug 14 '24 18:08 SukkaW

@michaelfaith We can probably split this PR into two: a PR that adds a flat config preset without no-unused-modules, and another PR that adds flat config support for no-unused-module.

With this, people can start using the flat presets right away.

I would be ok doing that, if the maintainers are. I was turned down when i suggested doing that in my PR in the other repo.

michaelfaith avatar Aug 17 '24 16:08 michaelfaith

if the maintainers are. I was turned down when i suggested doing that in my PR in the other repo.

It is OK here. I myself am an early flat config adapter (when ESLint 8.40 was released). I'd love to have a flat preset.

As for the inconsistency, we can mention in the changeset that the no-unused-modules rule is not available yet.

SukkaW avatar Aug 17 '24 17:08 SukkaW

if the maintainers are. I was turned down when i suggested doing that in my PR in the other repo.

It is OK here. I myself am an early flat config adapter (when ESLint 8.40 was released). I'd love to have a flat preset.

As for the inconsistency, we can mention in the changeset that the no-unused-modules rule is not available yet.

Sounds good. Then i'll try and find some time to wrap this up soon. Thanks

michaelfaith avatar Aug 17 '24 20:08 michaelfaith

Are the unit tests in this repo supposed to be passing? I noticed they failed in my branch, and so I checked out current master branch, and they're also failing for me there. Is it my setup, or are they just not working?

Tests are passing for me on master branch with yarn && yarn build && yarn test:

Test Suites: 54 passed, 54 total
Tests:       4 skipped, 2665 passed, 2669 total
Snapshots:   0 total
Time:        7.388 s

Yeah, that's what I've been running too, but still getting a ton of failures both in my branch and master (the same tests in both). So I'm kind of just relying on CI here since i'm not able to run them locally. image

michaelfaith avatar Aug 18 '24 16:08 michaelfaith

This should be ready for review.

As per the above conversation, this doesn't include addressing issues with no-unused-module and can be addressed separately. Though, it may be worth opening a separate issue to track that, since this would close #29

if the maintainers are. I was turned down when i suggested doing that in my PR in the other repo.

It is OK here. I myself am an early flat config adapter (when ESLint 8.40 was released). I'd love to have a flat preset.

As for the inconsistency, we can mention in the changeset that the no-unused-modules rule is not available yet.

michaelfaith avatar Aug 18 '24 17:08 michaelfaith