eslint / config-inspector

A visual tool for inspecting and understanding your ESLint flat configs.
https://www.npmjs.com/package/@eslint/config-inspector
Apache License 2.0
518 stars 15 forks source link

Support Object-only config files #38

Closed nzakas closed 2 months ago

nzakas commented 2 months ago

Flat config files can export either an array or an object. Right now, config inspector throws an error when attempting to load a config file with an object config like this:

export default {
    rules: {
        "no-undef": "error"
    }
};

Error:

Failed to load `eslint.config.js`.
Note that `@eslint/config-inspector` only works with the flat config format:
https://eslint.org/docs/latest/use/configure/configuration-files-new
TypeError: rawConfigs is not iterable
    at readConfig (file:///C:/Users/nzaka/AppData/Local/npm-cache/_npx/37ca41379bd26461/node_modules/@eslint/config-inspector/dist/cli.mjs:99:22)
    at async Object.getData (file:///C:/Users/nzaka/AppData/Local/npm-cache/_npx/37ca41379bd26461/node_modules/@eslint/config-inspector/dist/cli.mjs:200:16)
    at async Object.handler (file:///C:/Users/nzaka/AppData/Local/npm-cache/_npx/37ca41379bd26461/node_modules/@eslint/config-inspector/dist/cli.mjs:232:46)
    at async Object.handler (file:///C:/Users/nzaka/AppData/Local/npm-cache/_npx/37ca41379bd26461/node_modules/h3/dist/index.mjs:1962:19) 
    at async Server.toNodeHandle (file:///C:/Users/nzaka/AppData/Local/npm-cache/_npx/37ca41379bd26461/node_modules/h3/dist/index.mjs:2249:7)

It probably makes sense to just treat a config file that exports an object as an array with one item?

antfu commented 2 months ago

Interesting, I didn't know that. Thanks!