-
Notifications
You must be signed in to change notification settings - Fork 115
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
Preprocessing before matching in custom rules? #671
Comments
With the way you have currently formatted it, no. The first option isn't possible as DevSkim only supports first running a path query and then a string compare/regex. The second option won't work without changing your formatting, as you won't be able to run a JSONPath query against that file because it isn't valid json. If you formatted it like this so the overall document is valid JSON I think you should be able to use a DevSkim JSON path query to select the value of the {
"name": "Example",
"data": [
".input | map({ key: .key, value: .value })"
]
} |
I was afraid so. But this is unfortunately correct JQ syntax. I thought of enclosing it as a string too, but it would require extra steps in my program before passing it to a JQ processor and be less readable with multiline etc. And also it would effectively make it valid JSON meaning I won't be able to do any JQ processing in VScode anymore, and JQ syntax highlighting etc. I think currently the only option to write rules for these As far as I know there is no formal language description of JQ (yet) as in ABNF or equivalent, so it won't be possible to get this implemented in DevSkim as a language. |
In that case, it sounds like your best option will unfortunately be falling back to regular regex parsing, which is a shame because it is very close to JSON syntax and JSONPath would I'm sure be helpful to strip down to just the jq portions for linting rather than writing regex against the structured data format. =\ |
I have a very specific use case where I would like to use custom DevSkim rules on.
I described the situation here: jqlang/jq#566 (comment) which I moved into a discussion here: jqlang/jq#3218.
For DevSkim purposes this for now can be considered a 'custom and unsupported language', JQ. JQ in itself is not valid JSON but in my use-case a large part of it is JSON. To avoid writing very complicated regular expressions on a complicated file structure only, if I enclosed it in placeholders like in below example.
Is there a way in DevSkim to first use regex to remove everything in between the placeholders, including the placeholders itself, and then use JSONpath on the remainder, which is now fully JSON?
Or visa versa remove everything outside the placeholders including the placeholders, and do another regex on the remainder (JQ only)?
The text was updated successfully, but these errors were encountered: