New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix all files ignored prompting "No files matching the pattern xx were found." #5709
Conversation
When commit the ignore file, stylelint —fix failed: No files matching the pattern xx wren found. should add —allow-empty-input args. So I add a handler to fix this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request.
Let's add a test for this.
@jeddy3 done, npm run test PASS |
@zuoxiaobai Thanks for creating the PR! To be honest, I'm afraid that this change may confuse users. 🤔 Assume that there are 3 files below:
# .stylelintignore
*.css # .stylelintrc.yml
rules:
block-no-empty: true /* a.css has a `block-no-empty` problem. */
a {} Run $ stylelint a.css Run the same command changing an ignore file: $ stylelint a.css --ignore-path .gitignore
a.css
2:3 ✖ Unexpected empty block block-no-empty If |
The ESLint behavior might be helpful. ESLint emits a warning instead of exiting silently. See below: # .eslintrc.yml
ignorePatterns: ["*.js"]
rules: {} $ eslint a.js
/tmp/eslint-example/a.js
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override
✖ 1 problem (0 errors, 1 warning) EDIT: See the doc: https://eslint.org/docs/user-guide/configuring/ignoring-code#ignored-file-warnings |
@ybiquitous Thanks for your help. It's a bit difficult for me to add warning function to all ignored files like ESLint. So I changed my mind. Since this situation will only happen when all input files are ignored, it is relatively rare. I tried to make the smallest changes. When this happens, give the correct error message: |
@ybiquitous Does the behaviour now align with your suggestion in #5709 (comment)? |
Sorry for the late response. The new solution looks good to me. 👍🏼 |
lib/utils/allFilesIgnoredError.js
Outdated
const pattern = fileList.filter((i) => !i.startsWith('!')).join(', '); | ||
|
||
this.message = `File "${pattern}" ignored because of a matching ignore pattern. Move ignore config to .stylelintrc or use "--allow-empty-input" to override.`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggest] It may be better to wrap each file with double quotes. What do you think?
const pattern = fileList.filter((i) => !i.startsWith('!')).join(', '); | |
this.message = `File "${pattern}" ignored because of a matching ignore pattern. Move ignore config to .stylelintrc or use "--allow-empty-input" to override.`; | |
const pattern = fileList.filter((i) => !i.startsWith('!')).map((i) => `"${i}"`).join(', '); | |
this.message = `File ${pattern} ignored because of a matching ignore pattern. Move ignore config to .stylelintrc or use "--allow-empty-input" to override.`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ybiquitous Thanks for confirming the pull request is heading in the right direction.
Am I right in thinking that this error will only show if all the files matching the input are ignored?
And, if the input glob touches a lot of files, the fileList
could be long?
Shall we make the error message simple, e.g. "All input files were ignored because of the ignore pattern. Either change your input, ignore pattern or use "--allow-empty-input" to allow no inputs." Rather than have the possibility of outputting a long list of files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeddy3 That's a good idea! 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏼
|
For old projects, this error is a puzzling error, try to fix #4712
.stylelintignore
npx stylelint src/test.css
Solution: