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

Unable to process files with a $ in their path #651

Closed
eikowagenknecht opened this issue Feb 28, 2024 · 5 comments
Closed

Unable to process files with a $ in their path #651

eikowagenknecht opened this issue Feb 28, 2024 · 5 comments
Labels
bug Something isn't working Windows Windows case

Comments

@eikowagenknecht
Copy link

eikowagenknecht commented Feb 28, 2024

🔧 Summary

Mostly the same as #303, but instead of
No files matching the pattern "some/path/to..tsx" were found. I get
No files matching the pattern "'some/path/$file.tsx'" were found.

I'm using Windows.

Lefthook version

1.6.3 0845abb

Steps to reproduce

  1. Have a file with $ in its name.
  2. Run lefthook

lefthook.yml:

pre-commit:
  parallel: false
  commands:
    eslint:
      glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx}"
      run: npx eslint {staged_files}

Expected results

File is processed.

Actual results

Oops! Something went wrong! :(

ESLint: 8.57.0

No files matching the pattern "'src/routes/manage/$cardId.tsx'" were found.
Please check for typing mistakes in the pattern.

Possible Solution

It seems like there are too many quotes arount the staged files. From the console:

  • npx eslint 'src/routes/manage/$cardId.tsx' -> works
  • npx eslint "src/routes/manage/$cardId.tsx" or npx eslint src/routes/manage/$cardId.tsx -> No files matching the pattern "src/routes/manage/.tsx" were found.

Logs / Screenshots

...
│ [lefthook] out: lefthook.yml
src/routes/manage/$cardId.tsx

│ [lefthook] files before filters:
[lefthook.yml src/routes/manage/$cardId.tsx]
│ [lefthook] files after filters:
[src/routes/manage/$cardId.tsx]
│ [lefthook] files after escaping:
['src/routes/manage/$cardId.tsx']
│ [lefthook] executing: npx eslint 'src/routes/manage/$cardId.tsx'
⠇ waiting: eslint-fix
Oops! Something went wrong! :(

ESLint: 8.57.0

No files matching the pattern "'src/routes/manage/$cardId.tsx'" were found.
Please check for typing mistakes in the pattern.
...

I especially notice the line [lefthook] executing: npx eslint 'src/routes/manage/$cardId.tsx', which is exactly what I run from the console. And there it works?

This issue documents the problem for eslint only, but I have the same problem with Biome for example, where a " × The system cannot find the path specified. (os error 3)" error is thrown instead of the message eslint gives. For this as well, running npx biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true 'src/routes/manage/$cardId.tsx' from the console works fine.

The suggested workaround

    eslint-fix:
      glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx}"
      run: node_modules/.bin/eslint {staged_files}

does not work for me and only gives the error message 'node_modules' is not recognized as an internal or external command, operable program or batch file.

@eikowagenknecht eikowagenknecht added the bug Something isn't working label Feb 28, 2024
@mrexox mrexox added the Windows Windows case label Feb 28, 2024
@mrexox
Copy link
Member

mrexox commented Feb 28, 2024

Thank you for the issue. I think the problem occurs because for windows the argument includes the quotes, while on Linux/macOS those quotes are treated differently because the actual command is wrapped with sh. Currently I don't have a workaround for this issue, but I will try to figure it out.

@wonu
Copy link

wonu commented Mar 18, 2024

"{staged_files}" works, '{staged_files}' causes the same error.

@mrexox
Copy link
Member

mrexox commented Mar 19, 2024

@eikowagenknecht , does wrapping {staged_files} in " helps?

pre-commit:
  parallel: false
  commands:
    eslint:
      glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx}"
      run: npx eslint "{staged_files}"

@eikowagenknecht
Copy link
Author

Indeed, "{staged_files}" fixes it :-)

@mrexox
Copy link
Member

mrexox commented Mar 20, 2024

I'm closing this issue since there's a workaround found. Thank you, @wonu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows Windows case
Projects
None yet
Development

No branches or pull requests

3 participants