import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.51k stars 1.57k forks source link

[no-unused-modules] Error with ESLint configuration non-standard name #2678

Open regseb opened 1 year ago

regseb commented 1 year ago

The import/no-unused-modules rule doesn't work when the ESLint configuration file doesn't have a standard name. In my projects, I group the configuration files in a directory to avoid having too many files in the root (example with Cast Kodi).

  1. npm install
  2. npx eslint -c my_eslint.js index.js

    Oops! Something went wrong! :(
    
    ESLint: 9.12.0
    
    ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
    
       npm init @eslint/config@latest
    
    ESLint looked for configuration files in /home/sregne/Téléchargements/import and its ancestors. If it found none, it then looked in your home directory.
    
    If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat
ljharb commented 1 year ago

This seems like an issue with eslint itself, and not with eslint-plugin-import - this plugin doesn't do anything with eslint config.

(typically you'd only ever have one eslint config file in any repo, at the root, and you'd use overrides to configure subdirectories, but either way it's specific to eslint)

regseb commented 1 year ago

@ljharb I created an issue at ESLint and eslint-plugin-import use indirectly ESLint config:

ljharb commented 1 year ago

Yes, everything uses it indirectly - the bug is only with something that uses it directly.

ljharb commented 1 year ago

Reopening per the comment on the linked issue.

tetarchus commented 1 year ago

This also seems to be an issue with the new eslint flat config file. When I enable this rule, I get the message:

Oops! Something went wrong! :(

ESLint: 8.38.0

ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:

    npm init @eslint/config

ESLint looked for configuration files in [<rootDir>]/[<childDir>] and its ancestors. If it found none, it then looked in your home directory.

If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat

Flat config is in the root directory of the project, with no -c flag provided in the eslint command. Without this rule, everything runs fine, but as soon as I enable it, the above error flags up.