npm-groovy-lint
npm-groovy-lint copied to clipboard
embedded shell scripts
A lot of the bugs that we end up with in our groovy scripts (Jenkins pipelines) are embedded shell scripts that should be caught by a shell linter. Is there a way from within npm-groovy-lint to pass the script from the sh function to a bash linter (such as shellcheck) and return that as part of the results?
As an example, what I'm testing right now is something like this (which still doesn't work with multi line, and I'm sure my regex can be fine-tuned):
grep -Po "(?<=sh\(\"|sh\(script: \").*(?=\")" . -r | sed 's/[${}]//g' | while read -r line; do shellcheck -s bash <(echo "$line"); done
That would be a hug evolution for npm-groovy-lint... but it would require some workforce !
- Parse Jenkinsfile to extract shell commands
- Call shellcheck (that should be shipped with npm-groovy-lint)
- Get shellcheck results and convert them into npm-groovy-lint results
I don't have enough available time to make it happen before a while, but if you or someone else would like to make a PR I'll be glad to assist by providing support :)
I'll start working on this. I wanted to make sure it was an acceptable feature before putting time in. Though it will probably take me some time as well :-)
Such feature would probably make npm-groovy-lint the best Jenkinsfile linter in the universe, sure it's acceptable 😃
@simzacks I'm about to release npm-groovy-lint v10.0.0, if you make such enhancement I'll release a 11.0.0 :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
@simzacks do you still plan to implement this great evolution? :)
I wrote it in python (mother tongue). https://github.com/simzacks/groovy_shell_lint Now I have to figure out how to migrate this to javascript and convert them into npm-groovy-lint results
That's great :) About shellcheck, actionlint already embedded it to analyze shell scripts, if it can help
https://github.com/rhysd/actionlint/blob/main/rule_shellcheck.go
Can let you convert in Js then I'll assist you to plug it within npm-groovy-lint ?
Can let you convert in Js then I'll assist you to plug it within npm-groovy-lint ?
Nothing like a little motivation :-)
I'll try to have that done by the end of the week
I'm having some problem with js regex. Still working on it :-(
Show me the issues you have, I may help :)
I figured out a way around it, and should have the rest of the script finished today or tomorrow. The problems I was facing were: The ultimate goal: I couldn't figure out a regex that would find a whole word sh and then (ignoring the optional parenthesis) a valid quotation mark delimiter (either 3 double/single quotes or single double/single quote) and an identical end delimiter and capture everything in between .
Being that I couldn't figure that out, I found the whole word sh that doesn't have a "." before it, then I search for the quotation delimiters. In python, I was able to then search for the same delimiter that it found (if it found a single quote, it should search for a single quote, if it found 3 double quotes, it should search for 3 double quotes). When I tried setting a regex for the value found, I got an error that indicated the quotes weren't escaped (which is probably a language bug). i.e.
endq = "(?<!\\)" + start_quote[0];
p_endq = new RegExp(endq, "g");
^
SyntaxError: Invalid regular expression: /(?<!\)"""/: Unterminated group
I slept on it and the solution was to loop search for the delimiter using exec until a match was found that was identical to the first match it found.
Glad you unblocked yourself :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
not closed, still hoping to see a PR about it someday :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this issue should stay open, please remove the O: stale 🤖
label or comment on the issue.