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

`parserOptions` shouldn't be in recommended config

Open dword-design opened this issue 2 years ago • 7 comments

I think the parserOptions options are part of the ESLint config extending from eslint-plugin-import or they should be set to the latest ecmaVersion. Using the recommended config leads to errors parsing new JS features like optional chaining.

dword-design avatar Aug 30 '23 14:08 dword-design

They definitely should be there, and if you want to set your own parserOptions, that would always be happening after extending configs, so it shouldn't cause any errors.

ljharb avatar Aug 30 '23 18:08 ljharb

No @ljharb he's right; it's incorrect to set parserOptions.sourceType to "module" for every linted file, including .cjs files which are always CJS and, if the project package.json has type set to "commonjs" (which is the default!) .js files are also CJS.

Less concerning, but setting ecmaVersion: 2018 also seems like it should not be the concern of this particular plugin as ecmaVersion relates to more things than just ESM syntax. Only the user configuring their project can know the intended ECMA version for their codebase. It's not good this plugin's recommended config downgrades an ECMA version higher than 2018 that may have been set by other ESLint configs.

jaydenseric avatar Sep 01 '23 06:09 jaydenseric

Order of config extends matters, and the end user should be setting these things anyways.

Separately, i don’t recommend using the recommended config from any eslint plugin, including this one - semver constraints mean it’s almost always not in an ideal state. You should be using this plugin via the Airbnb config.

ljharb avatar Sep 01 '23 14:09 ljharb

Heeey I believe languageOptions.parserOptions.ecmaVersion and settings.'import/parsers' should be removed. this is the only eslint plugin needing it, is it needed?? and in fact eslint-plugin-import is not recognizing parserPath from new flat-config that eslint now recommends!!

They detail and I share : https://eslint.org/docs/latest/use/configure/migration-guide More: https://eslint.org/blog/2022/08/new-config-system-part-2/ More: https://eslint.org/blog/2023/10/flat-config-rollout-plans/ More: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/

In this last post they are explicit that "parserOptions and parserPath being removed" i dont know what to do to fix in advance

Please have a nice day @dword-design @ljharb

Also yeah,

ghost avatar Jan 23 '24 02:01 ghost

No, that’s not correct; it’s needed for eslint itself and parsers.

We don’t yet support flat config.

ljharb avatar Jan 23 '24 03:01 ljharb

I believe that what @ghost tried to add to the discussion is a solution: currently, this ESLint plugin needs to read explicitly the lines "languageOptions.parserOptions.ecmaVersion" and "settings.'import/parsers'" in a ESLint config. Without these lines your plugin doesn't work. Meanwhile, other plugins don't need these lines to be declared in the config, although they may recommend it.

Your plugin could be rewritten to work without these lines explicitly declared in the config. In the scenario in which these lines are omitted in a custom ESLint config, instead of emitting an error, your plugin could provide a default value for these lines and proceed to analyze files.

This would contribute to solve the current issue.

ghost avatar Feb 15 '24 01:02 ghost

I'm not sure why both of those comments are from different deleted accounts - i smell LLM garbage, but can't be sure. Either way, I'm going to hide them all.

ljharb avatar Feb 15 '24 17:02 ljharb