Is it possible to add custom rules? For example, I'd like to add an extension to check for the Google Shell Style rules. It doesn't make sense to include them in core Shellcheck. I looked in the code but I couldn't see where it would be possible to plugin custom rules.
I've thought of adding a Custom.hs that's left blank upstream for easy patching downstream. Would that solve the problem?
@koalaman that would require a guy to know haskell, it would be better is it is somewhat like Posix sh.
I think a blank file is a good first step. Longer term, a plug-in system similar to code quality tools in other languages would be awesome. Why architect that now if we don't know other people will use it? I'm fine wth using Haskell. Documentation on creating new rules would be helpful.
Hi, @koalaman!
I'm also really interested in this feature! I don't mind writing them in Haskell, moreover, I'd enjoy this :) But it would be nice if we could install the shellcheck from a package (or via brew) as a binary separately from custom rules.
Something similar to pandoc's --filter=PROGRAM wouldn't be bad, I think. Have shellcheck dump the AST as JSON to stdin on the "plugin" process, and read node-ID/warning pairs from stdout of that process. The plugin writer can use any language they like with JSON parsing.
Maybe this is an easy thing to ask for but it's complicated to implement. I'm accustomed to linters for php and javascript that are not written in compiled languages. The strength of those linters are teams can mix and match rules or use predefined rulesets. How do you create similar versatility for a tool in a compiled language?
@mordant23, @LukeShu wrote above one of the typical patterns that can be used to solve this problem.
Shellcheck can be run with:
shellcheck --plugins=myplugin.bin
Execution:
shellcheck calls myplugin.bin and dumps AST to stdoutmyplugin.bin parses AST from stdin (it might use the same data structures as shellcheck uses, e.g. include shellcheck as a library)myplugin.bin dumps a set of warning to stdoutshellcheck includes them in the final output@SerCeMan Thank you for the explanation. What's the level of effort to make that change? From the plugin developer side, the more documentation the better. Shellcheck as a library would be useful if there was some documentation on how to use it as such. It's always possible to try to figure it out from source code, tests, or debugging, but it's easier to get up to speed if the APIs are thoroughly documented.
I'm seeing that the possibility of adding custom rules is already implemented. That's very nice. Thank you!
HOWEVER, I'm an absolute beginner in Haskell and I have a couple of suggestions to add checks. I would like to add them by myself in my local (I've forked the project) but it would take a while to figure out what do I need to do in order to add a new check.
So, my suggestion is to add a short explanation on the Wiki page on how to add the check to the custom program. Please, notice that I'm not asking for any explanations about the language; it's only about the application itself. Like a recipe in a cookbook.
Thank you very much!
Most helpful comment
@mordant23, @LukeShu wrote above one of the typical patterns that can be used to solve this problem.
Shellcheck can be run with:
Execution:
shellcheckcalls myplugin.bin and dumps AST to stdoutmyplugin.binparses AST from stdin (it might use the same data structures as shellcheck uses, e.g. include shellcheck as a library)myplugin.bindumps a set of warning to stdoutshellcheckincludes them in the final output