Skip to content
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

Merged
merged 10 commits into from Feb 7, 2022

Conversation

dev-zuo
Copy link
Contributor

@dev-zuo dev-zuo commented Nov 9, 2021

For old projects, this error is a puzzling error, try to fix #4712

.stylelintignore

src/test.css

npx stylelint src/test.css

image

Solution:

  1. Adding ignoreFiles to your .stylelintrc, and remove from your .stylelintignore
{
  "ignoreFiles": [
    "src/test.css"
  ]
}
  1. stylelint --allow-empty-input
  2. Merge this PR, not throw error when stylelint .stylelintignore files

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.
Copy link
Member

@jeddy3 jeddy3 left a 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.

@dev-zuo dev-zuo requested a review from jeddy3 November 9, 2021 20:12
@dev-zuo
Copy link
Contributor Author

dev-zuo commented Nov 9, 2021

@jeddy3 done, npm run test PASS

@dev-zuo dev-zuo changed the title Fix ignore files must add —allow-empty-input (#4712) Fix .stylelintignore files prompting "No files matching the pattern xx were found." (#4712) Dec 19, 2021
@ybiquitous
Copy link
Member

@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
  • .stylelintrc.yml
  • a.css
# .stylelintignore
*.css
# .stylelintrc.yml
rules:
  block-no-empty: true
/* a.css has a `block-no-empty` problem. */
a {}

Run stylelint a.css. The command silently exits with no errors or warnings; it is just ignored.

$ 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 .stylelignore has long lines, users may forget that *.css is ignored and mistakenly assume there are no errors.

@ybiquitous
Copy link
Member

ybiquitous commented Dec 27, 2021

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

@dev-zuo
Copy link
Contributor Author

dev-zuo commented Dec 27, 2021

@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: File "${pattern}" ignored because of a matching ignore pattern. Move ignore config to .stylelintrc or use "--allow-empty-input" to override.

image

@jeddy3
Copy link
Member

jeddy3 commented Feb 7, 2022

@ybiquitous Does the behaviour now align with your suggestion in #5709 (comment)?

@ybiquitous
Copy link
Member

@zuoxiaobai
cc @jeddy3

Sorry for the late response. The new solution looks good to me. 👍🏼

Comment on lines 10 to 12
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.`;
Copy link
Member

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?

Suggested change
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.`;

Copy link
Member

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.

Copy link
Member

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! 👍🏼

@jeddy3 jeddy3 changed the title Fix .stylelintignore files prompting "No files matching the pattern xx were found." (#4712) Fix all files ignored prompting "No files matching the pattern xx were found." Feb 7, 2022
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

@jeddy3 jeddy3 merged commit 4094ad8 into stylelint:main Feb 7, 2022
@jeddy3
Copy link
Member

jeddy3 commented Feb 7, 2022

  • Fixed: throwing more informative error when all input files are ignored (#5709).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix ignore files must add —allow-empty-input
3 participants