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?

  1. Run eslint CLI with no positional parameters.
  2. 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

Most upvoted comments

I’m starting work on this. In eslintrc mode, eslint will now error; in flat config mode, eslint will now be equivalent to eslint ..

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?

I believe the latter would mean that when no positional arguments (file/dir/glob lint targets) are specified, the default is ["."].

Agree with that. Feels quite intuitive 👍

Just happened that one of our packages was successfully linting a package for years because we missed the . in eslint ..

eslint should either

  • lint . (or files parameter in eslint config)
  • exit with an error no parameter passed

Current behavior is misleading.

--pass-on-no-patterns sounds good to me for both eslintrc and flat config modes.

I believe the latter would mean that when no positional arguments (file/dir/glob lint targets) are specified, the default is [“.”].

Not exactly. It would mean that ESLint wouldn’t assuming anything and instead take all of the files patterns from eslint.config.js and use those as the glob patterns. So files:["**/*.js"] plus eslint equals eslint **/*.js.