eslint-plugin-import-x
eslint-plugin-import-x copied to clipboard
feat: add flat config support
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
🦋 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
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.
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?
flat configs on a new flatConfigs export
I like it personally as well as I find configs['flat/recommended'] a bit ugly.
Are the unit tests in this repo supposed to be passing? I noticed they failed in my branch, and so I checked out current
masterbranch, 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
@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.
@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 forno-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.
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.
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-modulesrule is not available yet.
Sounds good. Then i'll try and find some time to wrap this up soon. Thanks
Are the unit tests in this repo supposed to be passing? I noticed they failed in my branch, and so I checked out current
masterbranch, 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.
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-modulesrule is not available yet.