You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Occasionally it is necessary to use -- to signify options that take an argument. When -- is used, any file arguments are ignored.
Description
I am using oclint, which identifies potential problems in c code. -- is required to specify compiler options. This is my current configuration:
[-- skipped for brevity --]
- repo: localhooks:
- id: oclintname: oclintdescription: Find warnings/errors in C/CPP codeentry: oclinttypes: [c]pass_filenames: trueargs: [-enable-clang-static-analyzer,-enable-global-analysis,--,-report-type=json,-DCMAKE_EXPORT_COMPILE_COMMANDS=ON,]language: system
When running on a valid c file, I get this output:
oclint...................................................................Failed
hookid: oclint
oclint: Not enough positional command line arguments specified!
Must specify at least 1 positional argument: See: /usr/local/bin/oclint -help
Solution
Looking at the code, it looks like you are appending file arguments to the end instead of infixing them before --. A pull request that fixes this will be coming in a few.
Do you have an example that's broken? I'm not sure I understand your problem statement -- typically -- just means "don't parse these arguments as normal" and doesn't have any special significance for file or not -- I don't think it would be correct for pre-commit to attach any special behaviour to that
makes sense, I still think the current behaviour is as correct as it could be without potentially breaking existing things. oclint's usage of -- isn't universally applicable
One thing that you can do is use a script to redirect the arguments where you want them, for instance (untested):
Guideline 10:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
No it does not say "put filename arguments before --", If anything it says to put them after as filenames could start with a -, take for instance the usage with grep:
$ echo hi > ./-p
$ grep h -pgrep: invalid option -- 'p'Usage: grep [OPTION]... PATTERN [FILE]...Try 'grep --help' for more information.
$ grep h -- -phi
I appreciate you taking the time to write up a solution. I'm not familiar with ==. Is this something that pre-commit will treat as "end of options"?
In other news, I created a pull request and it passes tests that it should fail. Instead I created a pre-commit-hooks repo that contains these scripts that I'll be pushing shortly.
I just hit the same challenge while working with Angular-cli's built-in ng lint program. Thanks for leaving the notes as they proved helpful in getting pre-commit-nglint working. 😄
Yeah I do that all the time. Can you add the wontfix label to this question? You use labels so effectively with other tickets - I figure one would be appropriate here too 🙂.
Activity
asottile commentedon Apr 19, 2019
Do you have an example that's broken? I'm not sure I understand your problem statement -- typically
--just means "don't parse these arguments as normal" and doesn't have any special significance for file or not -- I don't think it would be correct for pre-commit to attach any special behaviour to thatpocc commentedon Apr 19, 2019
I've updated the question with additional context.
asottile commentedon Apr 19, 2019
makes sense, I still think the current behaviour is as correct as it could be without potentially breaking existing things.
oclint's usage of--isn't universally applicableOne thing that you can do is use a script to redirect the arguments where you want them, for instance (untested):
(If you don't want to inline that all in the yaml, it could easily be moved out to another script)
Even something like this might work (again untested, might be off-by-one somewhere):
pocc commentedon Apr 20, 2019
It's a POSIX standard (see guideline 10), so it's as universally applicable as POSIX is.
The entry syntax as shown produces the same error (no files found).
I am using
pre-commitbecause I had lint scripts but wanted to centralize them.I am making a pull request that infixes file arguments if there are options after
--. I have verified that it passes all tests.asottile commentedon Apr 20, 2019
Yes it's a standard
No it does not say "put filename arguments before
--", If anything it says to put them after as filenames could start with a-, take for instance the usage withgrep:asottile commentedon Apr 20, 2019
I fixed up the wrapper script as well, I was missing the
==in the arglist that I was keying off ofpocc commentedon Apr 24, 2019
I appreciate you taking the time to write up a solution. I'm not familiar with
==. Is this something that pre-commit will treat as "end of options"?In other news, I created a pull request and it passes tests that it should fail. Instead I created a pre-commit-hooks repo that contains these scripts that I'll be pushing shortly.
asottile commentedon Apr 24, 2019
nah I just used it a delimiter so the shim script could reorder the filenames and options
pocc commentedon Apr 25, 2019
For future reference, this will rotate args in bash:
pocc commentedon Apr 25, 2019
Closing as I have created
https://github.com/pocc/pre-commit-hooksto deal with this instead.asottile commentedon Apr 25, 2019
sweet, glad we could come to a solution 🎉
pocc commentedon Apr 25, 2019
The
--issue may pop up again, but given that it's mostly used with C/C++ compilation, my hooks will likely obviate the need for further changes.dwightgunning commentedon May 2, 2019
I just hit the same challenge while working with Angular-cli's built-in
ng lintprogram. Thanks for leaving the notes as they proved helpful in getting pre-commit-nglint working. 😄pocc commentedon May 2, 2019
Reopening this issue as this is a problem with multiple people and linter domains.
pocc commentedon May 2, 2019
You've hardclosed this issue without a response. It sounds like you're acknowledging that this is an issue, but that
Would you mind adding the
wontfixtag to this issue to better document it?asottile commentedon May 2, 2019
oops! I did type out a comment but it apparently got lost :S
it was basically that there's nothing to standardize here and a valid way to reorder the args -- though the first comment had slightly more words 😆
but you're correct, this is wontfix
pocc commentedon May 2, 2019
Yeah I do that all the time. Can you add the
wontfixlabel to this question? You use labels so effectively with other tickets - I figure one would be appropriate here too 🙂.asottile commentedon May 2, 2019
we used to use a
[wontfix]label but found that it frustrated question askers so I removed it a while back 🤷♂pocc commentedon May 2, 2019
No problem. Thanks for the context.