For eslint.config.js
(flat config), what command should I use when linting *.js
files recursively from the command line? 1
With eslintrc.js
or eslintrc.json
, I have been using npx eslint . --ext .js
, as suggested here.
Until now, it always worked fine.
But when I try that with eslint.config.js
, the response in the command line is :
Invalid option '--ext' - perhaps you meant '-c'? You're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.
I didn't find any solution at the suggested link.
My eslint.config.js
is in the directory where I try to run the lint command. 2
import eslintJs from '@eslint/js';
import globals from 'globals';
export default [
eslintJs.configs.recommended,
{
// files: ['**/*.js', '**/*.cjs', '**/*.mjs'], // = default, not needed
languageOptions: { globals: { ...globals.node } },
rules: { 'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }] },
},
];
package.json
:
{
"name": "flat-config",
"devDependencies": {
"eslint": "^8.52.0"
},
"private": true,
"type": "module"
}
I ran npm install
before running npx eslint . --ext .js
.
For demo purposes, I have a small bad-code.js
file :
const hiUnused = 'hi there';
const hello='Hello world';
const unusedFunc = function(unusedVariable) { console.log('hi!') }
consoler.log(hello);
If and when ESLint works, I expect it to respond with three warnings and one error.
warning 'hiUnused' never used
warning 'unusedFunc' never used
warning 'unusedVariable' never used
error 'consoler' not defined
1 I include the typescript tag because I expect the corresponding question and answer(s) to be very similar for TypeScript.
2
I include the line files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
to indicate that by default, ESLint matches **/*.js
, **/*.cjs
, and **/*.mjs
.
Commenting out or leaving it in should therefore not make any difference.