Skip to content
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

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

Open
regseb opened this issue Jan 14, 2023 · 5 comments
Open

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

regseb opened this issue Jan 14, 2023 · 5 comments

Comments

@regseb
Copy link

regseb commented Jan 14, 2023

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).

  • index.js

    console.log("foo");
  • my_eslint.json

    import pluginImport from "eslint-plugin-import";
    
    export default [{
        plugins: { "import": pluginImport },
    
        rules: {
            "no-console": "warn",
            "import/no-unused-modules": ["error", { unusedExports: true }]
        }
    }];
  • package.json

    {
        "name": "testcase",
        "version": "1.0.0",
        "type": "module",
        "dependencies": {
            "eslint-plugin-import": "2.31.0",
            "eslint": "9.12.0"
        }
    }
  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
Copy link
Member

ljharb commented Jan 14, 2023

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
Copy link
Author

regseb commented Jan 15, 2023

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

@ljharb
Copy link
Member

ljharb commented Jan 15, 2023

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

@ljharb
Copy link
Member

ljharb commented Jan 15, 2023

Reopening per the comment on the linked issue.

@ljharb ljharb reopened this Jan 15, 2023
@tetarchus
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants