-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support eslint flat config #29
Comments
I'm focusing on TypeScript migration first, see also #41. After that, I'll start working on new features like supporting flat config. |
Just to mention, some rules will break when using flat config. See this comment In brief, eslint will fail to use Related issues:
|
Interesting, we are using This seems to be working for us so far: Simplified version of the code: import eslintImportX from 'eslint-plugin-import-x';
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const configArray = [
{
plugins: {
'import-x': eslintImportX,
},
settings: {
'import-x/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import-x/resolver': {
// Load <rootdir>/tsconfig.json
typescript: true,
node: true,
},
},
rules: {
// Error on imports that don't match the underlying file system
// https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-unresolved.md
'import-x/no-unresolved': 'error',
},
]; |
@karlhorky I am trying out this plugin with the flat config. I copy pasted the config from your post, but I get these errors: (I enabled more rules than simply Any idea on how to fix? |
module.exports = {
extends: [
'plugin:import-x/recommended',
'plugin:import-x/typescript',
],
} can only be translate into export default [
...compat.config(pluginImportX.configs.recommended), // https://github.com/un-ts/eslint-plugin-import-x/issues/29#issuecomment-2148843214
pluginImportX.configs.typescript, // no need of wrapping in compat.config() since there's no pluginImportX.configs.typescript.plugins
]; since
is still passing string as plugin. |
@n0099 where is Is there an example of a simple flat config for eslint v9 that uses this plugin? My super simple set up works for everything but the import sorting. import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginImportX from "eslint-plugin-import-x";
export default [
{
languageOptions: { globals: globals.browser },
ignores: ["./dist/"],
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginImportX.configs.typescript,
]; |
import { FlatCompat } from '@eslint/eslintrc';
If you only want to extends from eslint-plugin-import-x/src/config/typescript.ts Lines 16 to 35 in 3abe5e4
so manually add plugin define to let eslint know where to find define for rules with prefix import-x/
+ { plugins: { 'import-x': pluginImportX } },
pluginImportX.configs.typescript, or just also extending + ...compat.config(pluginImportX.configs.recommended),
pluginImportX.configs.typescript, |
Where do you import compat from? |
|
Also this eslint/eslint#18087 |
Chiming in here to say that I don't think the ecosystem uses Are any other rules than |
Let's deprecate |
Never heard about knip, but I'm generally in favor of at least disabling rules that are duplicate with what typescript already validates, if the linted file is typescript, of course. But I guess this is more of a config topic than a plugin topic. |
It works great in flat config 👍🏻 but |
Yes. This is because Currently, I am working on a more performant @silverwind would you like to replace the |
In import-js#3018 they used |
Maybe @michaelfaith would be interested in porting their work here in case that PR stalls because of those "node 4 concerns" which we do not have with this fork 😆. |
Yeah. @michaelfaith if you are interested, you can port that PR to |
Sure, I don't mind helping out, when I have some time. |
note the I’d support deprecating |
Did you mean
I've considered deprecating And as long as we don't include this rule in the flat config, everything would be fine. |
I'd definitely keep it at this point, it's too valuable and not everyone wants to install another dependency and fight its config just to replace one rule. |
Yeah
Yeah, I wouldn't really say "hypothetical". Proposed is accurate though. The two functions that I used in that implementation were added in a POC branch of the eslint repo to prove the proposed api. The idea is that the code would use those functions if they were on the context, and if not, fall back to the old implementation. And if, between now and when the API is finalized, those functions get introduced with a slightly different shape, then the implementation would need to be adjusted. It'd be the same here, if that's the route you want to go. I did use the POC branch in the eslint repo to work against, though. So it did prove the solution out. |
Oh, and to add a little more context: that api very likely would have already been added to ESLint in v9, if it weren't for the feet-dragging from the |
I started a draft PR, with everything except the changes to |
Yes, I’m talking about |
Likely depends on import-js#2556 but it's good to track nonetheless.
Ref: eslint/eslint#18093
The text was updated successfully, but these errors were encountered: