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

Bad quote escape with "git-bash" (windows) #269

Closed
TotoLastro opened this issue May 5, 2022 · 6 comments · Fixed by #314
Closed

Bad quote escape with "git-bash" (windows) #269

TotoLastro opened this issue May 5, 2022 · 6 comments · Fixed by #314
Labels
Windows Windows case
Milestone

Comments

@TotoLastro
Copy link

Hi all,

After installing lefthook from npm, I did some tests.
And I see a problem with quotes (a bad escape ?).

For the example, this is the lefthook.yml :

pre-commit:
  parallel: false
  commands:
    echo-files:
      run: echo "{staged_files}"

And this is the result after running the command :

$ lefthook -v run pre-commit
RUNNING HOOKS GROUP: pre-commit
  waiting Files before filters:
 [lefthook.yml]
Files after filters:
 [lefthook.yml]
Files after escaping:
 [lefthook.yml]

  EXECUTE > echo-files
\lefthook.yml"


SUMMARY: (done in 0.17 seconds)

(we can see trailing chars : \ and ")

No problem if I use apostrophes (the echo command prints only the filename)

  • lefthook 0.7.7
  • Git Bash (x64) 2.36.0.1
  • Windows 10 Enterprise N 20H2
@mrexox
Copy link
Member

mrexox commented Jun 25, 2022

Hey! We've released new version of lefthook recently. Could you check if there's still a bug with the latest lefthook binary?

@TotoLastro
Copy link
Author

Nop, no changes after lefthook upgrade to 1.0.3 😞 (package @evilmartians/lefthook)

@Carduelis
Copy link

@mrexox Unfortunately, it doesn't work for me.
I'm using next.js and there is a common pattern to have the [slug].tsx filenames.
I'm on Windows and if I run the command with double quotes, it works:

yarn eslint "pages/blog/[slug].tsx"

But the lefthook uses single quotes which leads to the following error:

Oops! Something went wrong! :(

ESLint: 8.17.0

No files matching the pattern "'pages/blog/[slug].tsx'" were found.
Please check for typing mistakes in the pattern.

@Carduelis
Copy link

Carduelis commented Jul 8, 2022

My lefthook.yml is:

pre-commit:
  parallel: true
  commands:
    prettier:
      glob: '*.{js,ts,jsx,tsx}'
      run: yarn prettier --write {staged_files} && git add {staged_files}
    eslint:
      glob: '*.{js,ts,jsx,tsx}'
      run: yarn eslint {staged_files} --fix && git add {staged_files}

How can I replace ' with " in the output of {staged_files}?

@Carduelis
Copy link

Carduelis commented Aug 7, 2022

For those, who experience issues using next.js framework with Dynamic Routes, there is a temporal solution to ignoring files for optional wildcard routing.

If you use Typescript and next.js you can use the following regexp: \[(\[)?(\.\.\.)?\w+\](\])?.tsx

### Legend for regexp
### \[(\[)?     [ or [[
### (\.\.\.)?   optional dots ...
### \w+       slug name
### \](\])?     ] or ]]
### .tsx        we use only Typescript

Which will exclude from the check those files:

[slug].tsx
[[slug]].tsx
[...slug].tsx
[[...slug]].tsx

Example of lefthook.yml

pre-commit:
  parallel: true
  commands:
    prettier:
      glob: '*.{js,ts,jsx,tsx}'
      exclude: '\[(\[)?(\.\.\.)?\w+\](\])?.tsx' ### https://github.com/evilmartians/lefthook/issues/269
      run: yarn prettier --write {staged_files} && git add {staged_files}
    eslint:
      glob: '*.{js,ts,jsx,tsx}'
      exclude: '\[(\[)?(\.\.\.)?\w+\](\])?.tsx' ### https://github.com/evilmartians/lefthook/issues/269
      run: yarn eslint {staged_files} --fix && git add {staged_files}

@mrexox mrexox added the Windows Windows case label Aug 10, 2022
@mrexox
Copy link
Member

mrexox commented Aug 10, 2022

Hey, @TotoLastro , @Carduelis ! I have prepared a fix: #314. I hope it will fit in your cases but if you have time and will you can pull the code, build a lefthook executable, and test it.

Or if you have a public repo with the appropriate files and lefthook.yml, just send me a link, and I will test it myself.

I am going to release this fix with version 1.1.0 in about a week.

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

Successfully merging a pull request may close this issue.

3 participants