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

Add support for double brackets in path and lint-staged #7081

Closed
olivervorasai opened this issue Jul 14, 2023 · 5 comments
Closed

Add support for double brackets in path and lint-staged #7081

olivervorasai opened this issue Jul 14, 2023 · 5 comments
Labels
status: needs discussion triage needs further discussion

Comments

@olivervorasai
Copy link

olivervorasai commented Jul 14, 2023

What minimal example or steps are needed to reproduce the bug?

When using lint-staged + husky + stylelint, files that have double brackets in their path throw the following error:

✖ stylelint:
Error: No files matching the pattern "C:/Users/OliverVorasai/Desktop/random/stylelint-bug/test-files/some/long/path/[[id]]/test.css" were found.
    at standalone (C:\Users\OliverVorasai\Desktop\random\stylelint-bug\node_modules\stylelint\lib\standalone.js:261:43)

What minimal configuration is needed to reproduce the bug?

https://github.com/olivervorasai/stylelint-bug

Steps:

  1. npm i
  2. Modify the test.css file
  3. Try to commit the changes

How did you run Stylelint?

pre-commit via husky and lint-staged

Which Stylelint-related dependencies are you using?

{
    "husky": "^8.0.3",
    "lint-staged": "^13.2.3",
    "stylelint": "^15.10.1",
    "stylelint-config-standard": "^34.0.0"
}

What did you expect to happen?

Stylelint to run without problems.

What actually happened?

Stylelint (or lint-staged) was unable to parse the file path.

Notes

Everything works fine for file paths that have single brackets.

For example: some/long/path/[id]/test.css

According this comment #4855 (comment) there are several workarounds relating to globs. However, I may be misunderstanding the comment but I am not using a glob in my example.

Context

I use single and double brackets for automatic page routing in web frameworks like Nuxt.

@shrey714
Copy link

The issue you're facing is related to the use of double brackets in file paths when using lint-staged, husky, and stylelint. This error occurs because the file path with double brackets is not being recognized by the underlying file system.

To resolve this issue, you can modify your configuration to escape the double brackets in the file path. Here's the modified configuration for lint-staged in your package.json file:

"lint-staged": { "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [ "stylelint --config .stylelintrc.json" ] }

By escaping the double brackets with backslashes (\\), you can ensure that the file path is properly recognized. Here's an example of the modified configuration for your specific file path:

"lint-staged": { "test-files/some/long/path/\\[\\[id\\]\\]/test.css": [ "stylelint --config .stylelintrc.json" ] }

With this modification, lint-staged should be able to find and process files with double brackets in their paths without throwing the "No files matching the pattern" error.

@jeddy3
Copy link
Member

jeddy3 commented Jul 18, 2023

@olivervorasai Thanks for the report, for using the template and for the minimal reproducible repo.
@shrey714 Thanks for chiming in with your solution.

It sounds like this is an issue with lint-staged rather than Stylelint.

Stylelint can lint the file from the CLI:

jeddy3@mac stylelint-bug-main % npx stylelint "**/*.css"

test-files/some/long/path/[[id]]/test.css
 2:10  ✖  Unexpected invalid hex color "#ff"  color-no-invalid-hex

1 problem (1 error, 0 warnings)

@jeddy3 jeddy3 added the status: needs discussion triage needs further discussion label Jul 18, 2023
@Mouvedia
Copy link
Contributor

It sounds like this is an issue with lint-staged rather than Stylelint.

lint-staged/lint-staged#676 is maybe related.

@jeddy3
Copy link
Member

jeddy3 commented Jul 22, 2023

And here's the pull request for how Prettier resolved the issue at their end. Shall we do the same?

@jeddy3 jeddy3 changed the title No files matching the pattern error when using double brackets in path Fix No files matching the pattern error when using double brackets in path Nov 5, 2023
@jeddy3 jeddy3 changed the title Fix No files matching the pattern error when using double brackets in path Add support for double brackets in path and lint-staged Dec 17, 2023
@olivervorasai
Copy link
Author

This is no longer an issue with these updated dependencies:

{
    "husky": "^8.0.3",
    "lint-staged": "^15.2.2",
    "stylelint": "^16.3.0",
    "stylelint-config-standard": "^36.0.0"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs discussion triage needs further discussion
Development

No branches or pull requests

4 participants