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

Escape filter list in a way that can be copied and pasted into a shell with NOMATCH #97

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

bwrsandman
Copy link
Contributor

No description provided.

@ZedThree
Copy link
Owner

Please could you give an example of before and after? I'm not quite sure what the issue is!

@bwrsandman
Copy link
Contributor Author

bwrsandman commented Oct 11, 2023

Currently it will print this

clang-tidy-15 -p=cmake-build-presets/ninja-multi-vcpkg --config-file=".clang-tidy" -line-filter=["{'name': 'src/Game.cpp', 'lines': [[677, 677], [712, 712]]}"] "src/Game.cpp" --export-fixes=clang_tidy_review.yaml/mnt 

This causes issues with interpreters with NOMATCH such as mac's bash and zsh on linux which both complain, presumably about the [ character which can be used to match patterns.

zsh: no matches found: -line-filter=[{'name': 'src/Game.cpp', 'lines': [[677, 677], [712, 712]]}]

Escaping line filter properly gives a slightly uglier command but you can the use it in your script.

clang-tidy-15 -p=cmake-build-presets/ninja-multi-vcpkg --config-file=.clang-tidy '-line-filter=[{'"'"'name'"'"': '"'"'src/Game.cpp'"'"', '"'"'lines'"'"': [[677, 677], [712, 712]]}]' src/Game.cpp --export-fixes=clang_tidy_review.yaml/mnt

The uglyness is because of the way it escapes quotes:

...'... -> '...'"'"'...'

Is just the concatenation of '...' + "'" + '...'. It closes the string with ' quotes, open a string with " quotes in order to use the literal ', closes it and then opens another ' string.

@bwrsandman bwrsandman force-pushed the running_string branch 5 times, most recently from 753b3c9 to 0e7a301 Compare October 11, 2023 12:26
@bwrsandman
Copy link
Contributor Author

Still need to test this version of the fix

@bwrsandman bwrsandman marked this pull request as draft October 11, 2023 12:28
@bwrsandman bwrsandman force-pushed the running_string branch 3 times, most recently from d90e239 to adb19f2 Compare October 11, 2023 13:17
@bwrsandman
Copy link
Contributor Author

bwrsandman commented Oct 11, 2023

I've refined the fix.
The issue was a string conversion of the dict of each line change entry was introducing a quotes ["{}", "{}"] where they shouldn't be.

Not only is that an invalid json list of json objects (being instead a json list of strings), but it leaves the [...] free of quotes which can be interpreted by interpreters with NOMATCH as a regex pattern.

Using shlex.quote, the quote is now in the right place "[{}, {}]" for a json.
I've also improved the way the file names are joined using shlex.join so now quotes are inserted in a smart way

["src/test.cpp", "src/test directory/test.cpp"] -> "src/test.cpp 'src/test directory/test.cpp'"

Join file names using shell aware `shlex.join`
Remove string conversion for each file entry in line filter.
Escape quotes in line filter using `shlex.quote`.
@bwrsandman bwrsandman changed the title Escape clang-tidy command in a way that can be copied and pasted into a shell Escape filter list in a way that can be copied and pasted into a shell with NOMATCH Oct 11, 2023
Copy link
Owner

@ZedThree ZedThree left a comment

Choose a reason for hiding this comment

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

Thanks @bwrsandman, this looks great!

@ZedThree ZedThree merged commit e7f5af5 into ZedThree:master Oct 11, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants