eslint: Omiting any file/dir positional parameter to CLI does not give an error
- ESLint Version: 7.23.0
- Node Version: 15.4.0
- npm Version: 7.1.1
- Operating System: linux 5.4.0-70-generic
- Parser: @babel/eslint-parser
Configuration
module.exports = {
root: true,
parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 2018,
sourceType: 'module'
},
extends: [
'standard',
'plugin:vue/recommended'
],
plugins: ['vue'],
rules: {
'max-len': ['warn', { code: 120 }],
'vue/no-v-html': 'off'
}
}
ESLint CLI usage:
eslint --cache --ext .js,.vue --max-warnings 0
What did you expect to happen?
I expected to have and error in console: 'patterns' must be a non-empty string or an array of non-empty strings
.
Instead, I got no response at all (and no actual linting performed, of course).
$ eslint --cache --ext .js,.vue --max-warnings 0
Done in 0.23s.
How to replicate?
- Run
eslint
CLI with no positional parameters. - No error is shown .
More details
The condition in ESLint engine code is accepting an empty list as a valid list of non empty strings. It boils down to the fact that a call to .every(...)
method of an empty list is always true (see isArrayOfNonEmptyString
function)
I’m more than OK to prepare a PR to fix this.
Thanks!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (12 by maintainers)
Commits related to this issue
- fix: Behavior of CLI when no arguments are passed Fixes #14308 — committed to eslint/eslint by nzakas 9 months ago
- feat(cli): run oxlint with no file arguments closes #1190 See: `https://github.com/eslint/eslint/issues/14308` — committed to oxc-project/oxc by Boshen 8 months ago
- feat(cli): run oxlint with no file arguments (#1201) closes #1190 See: `https://github.com/eslint/eslint/issues/14308` — committed to oxc-project/oxc by Boshen 8 months ago
- fix: Behavior of CLI when no arguments are passed Fixes #14308 — committed to eslint/eslint by nzakas 9 months ago
- fix!: Behavior of CLI when no arguments are passed (#17644) * fix: Behavior of CLI when no arguments are passed Fixes #14308 * Removed unnecessary check * Fix edge cases * Add --pass-on-n... — committed to eslint/eslint by nzakas 6 months ago
I’m starting work on this. In eslintrc mode,
eslint
will now error; in flat config mode,eslint
will now be equivalent toeslint .
.In order to have a way to opt back in to the current behavior, where you can pass zero file patterns to ESLint and it won’t error, we’re thinking to add a
--no-error-on-no-patterns
flag. Thoughts?Agree with that. Feels quite intuitive 👍
Just happened that one of our packages was successfully linting a package for years because we missed the
.
ineslint .
.eslint
should either.
(orfiles
parameter in eslint config)no parameter passed
Current behavior is misleading.
--pass-on-no-patterns
sounds good to me for both eslintrc and flat config modes.Not exactly. It would mean that ESLint wouldn’t assuming anything and instead take all of the
files
patterns fromeslint.config.js
and use those as the glob patterns. Sofiles:["**/*.js"]
pluseslint
equalseslint **/*.js
.