Feature Request: Support linting of shebang recipes
- Dominant language
- Rust
- Stars
- 35.8k
- Forks
- 846
- Avg merge
- 27m
- Merged PRs (30d)
- 3
Description
I like that `just` lets me put a lot of what I would normally write as a mass of shell scripts into a Justfile. But when recipe logic and documentation as code leads me to write a shebang recipe it is not long before I wish I could use a linter to make sure I have not blundered in writing that. Since most of my shebang recipes are using `bash` I personally would like some way to have `just` save a recipe to its temporary file and then, instead of executing it, have it run a locally installed linter like [ShellCheck](https://github.com/koalaman/shellcheck) against that file. Those using other languages would likely need a way to specify their own linters of choice, however.
Implementation-wise, perhaps a new just variable **linter** could be defined as a companion to **shell** to specify the default linter for recipe lines.
As an initial implementation perhaps it would be sufficient to have a `just --lint [recipe]` option that would write the designated recipe's body to the "temporary file" and have `just` simply output the path to that for users to lint manually. That might enable the maximum flexibility for users and other tools that might incorporate `just` capabilities. Or maybe a --linter option would work similarly to --shell to invoke the designated linter on recipe bodies. Another possibility might have `just` recursively call itself to invoke `lint: target:` recipes. Maybe recipe attributes could be extended to cover different shebang languages, i.e.,
[bash]
lint target:
shellcheck {{target}}
[python3]
lint target:
pylint {{target}}
where again, the target path would come from `just`'s temporary path generation. Perhaps `~/.user.justfile ` is a mechanism to leverage to specify user preferences for shell/linter correspondences via a map/associative array or recipe attributes as above.
I could do something with `junk -s [recipe] | tail -n +3 | shellcheck -` but then I have to figure out how to deal with variable substitutions. I'm not a rust developer nor familiar with `just` internals so I'm spit-balling here as a happy `just` user wanting to be happier.
Finally, perhaps this request overlaps somewhat with #1094 Question: Language Server, though that seems to me like a much bigger ask. Thanks for considering it, and for just.
Contributor guide
Research direction
Start by reading how just handles shebang recipes, creates temporary files, performs variable substitution, and parses command-line options. The issue presents several competing designs, including --lint, --linter, and lint recipes, so first narrow the scope to one approach. Done should include a defined linting workflow for recipe bodies, with substitutions handled correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, python, rust
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100