diff --git a/designs/2022-supress-ignored-file-warnings/README.md b/designs/2022-supress-ignored-file-warnings/README.md new file mode 100644 index 00000000..737cd542 --- /dev/null +++ b/designs/2022-supress-ignored-file-warnings/README.md @@ -0,0 +1,157 @@ +- Repo: eslint/eslint +- Start Date: 2022-05-13 +- RFC PR: +- Authors: Domantas Petrauskas + +# CLI option to supress ignored file warnings + +## Summary + + + +When ignored files are explicitly linted, ESLint shows a warning. This causes problems when using tools which pass the file list to ESLint automatically together with `--max-warnings 0` option. + +## Motivation + + + +While this is warning is reasonable in cases where filenames are passed to ESLint manually, it causes issues when the process is automated with tools like [lint-staged](https://github.com/okonet/lint-staged) and [pre-commit](https://github.com/pre-commit/pre-commit). These tools pass staged filenames to any command, not just ESLint. Therefore, they are not aware of the .eslintignore. Linting before commit is commonly set up with `--max-warnings 0`, therefore ESLint will exit with an error in such case. + +For example, with + +``` +// .eslintignore +foo.js +``` + +Running + +``` +eslint foo.js +``` + +Will result in + +``` +warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override +``` + +It is possible to filter out ignored files using ESLint `CLIEngine`. This was the main reasoning to reject the CLI flag idea during [TSC meeting in 2018](https://gitter.im/eslint/tsc-meetings/archives/2018/08/02). The commitee was only considering the use case of integrations. However, this problem affects end users as well. Lint-staged FAQ includes a section [how can I ignore files from .eslintignore](https://github.com/okonet/lint-staged#how-can-i-ignore-files-from-eslintignore), which suggests adding additional config file and using `CLIEngine.isPathIgnored` to filter out ignored files. Having a CLI flag for this would improve the end-user experience. + +## Detailed Design + + + +ESLint CLI should have an optional flag to disable the ignored file warning. The flag should be boolean. In order to stay consistent with current CLI flags, it should be called `--no-warning-on-ignored-files`. If it is present, ESLint should supress the `File ignored because of a matching ignore pattern.` warning. The flag should replicate `eslint.lintText`[warnIgnored option](https://eslint.org/docs/developer-guide/nodejs-api#-eslintlinttextcode-options) when it is set to `false`. + +The current warning should be updated to `File ignored because of a matching ignore pattern. Use "--no-warning-on-ignored-files to suppress this warning.` + +## Documentation + + + +The [CLI Documentation](https://eslint.org/docs/user-guide/command-line-interface) should be updated to include the new flag. + +## Drawbacks + + + +Adding additional CLI flags adds additional mental overhead for the users. It might be confusing for users who don't experience this problem. + +There will be multiple was of achieving the same goal. One with `CLIEngine`, and another with the flag. + +## Backwards Compatibility Analysis + + + +It should not affect existing users in any way. + +The `CLIEngine.isPathIgnored` solution will continue working, it is `lint-staged` and similar tools responsibility to communicate that it is possible to use the flag instead. + +## Alternatives + + + +It was considered to output the warning to `stderr` instead, but that would cause breaking changes. + + + + + + + + + + + + + +## Related Discussions + + + +Main issue: + +https://github.com/eslint/eslint/issues/15010 + +Related issues: + +https://github.com/eslint/eslint/issues/9977 + +https://github.com/eslint/eslint/issues/12206 + +https://github.com/eslint/eslint/issues/12249