admin管理员组文章数量:1287524
For eslint.config.js
(flat config), what mand should I use when linting *.js
files recursively from the mand 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 mand line is :
Invalid option '--ext' - perhaps you meant '-c'? You're using eslint.config.js, some mand line flags are no longer available. Please see 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 mand. 2
import eslintJs from '@eslint/js';
import globals from 'globals';
export default [
eslintJs.configs.remended,
{
// 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.
For eslint.config.js
(flat config), what mand should I use when linting *.js
files recursively from the mand 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 mand line is :
Invalid option '--ext' - perhaps you meant '-c'? You're using eslint.config.js, some mand line flags are no longer available. Please see https://eslint/docs/latest/use/mand-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 mand. 2
import eslintJs from '@eslint/js';
import globals from 'globals';
export default [
eslintJs.configs.remended,
{
// 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.
1 Answer
Reset to default 7What mand should I use when linting
*.js
files recursively from the mand line?
Try : 1
npx eslint **/*.js
This will lint all *.js
files in the current directory and all its subdirectories.
The mand npx eslint **/*.js
works just as fine for the old-school .eslintrc.*
type of files as it does for the new eslint.config.js
ones.
For your demo file, bad-code.js
, ESLint responds :
1:7 warning 'hiUnused' is assigned a value but never used no-unused-vars
3:7 warning 'unusedFunc' is assigned a value but never used no-unused-vars
3:29 warning 'unusedVariable' is defined but never used.
Allowed unused args must match /^_/u no-unused-vars
4:1 error 'consoler' is not defined no-undef
^ click to enlarge
1
This is from the documentation.
Just filter out all the config stuff.
(Disregard ESLINT_USE_FLAT_CONFIG=true
and --config some-other-file.js
.)
本文标签: javascriptFor flat confighow do I run ESLint from the command lineStack Overflow
版权声明:本文标题:javascript - For flat config, how do I run ESLint from the command line? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741309940a2371592.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论