lefthook
lefthook copied to clipboard
Feature request: runner prefixes in local configs
We use Lefthook in hybrid development environments: some engineers use local setup, some use Docker/Dip.
The base configuration is local-first, so Docker devs use lefthook-local.yml
with the following contents:
pre-commit:
commands:
rubocop:
runner: dip {cmd}
reek:
runner: dip {cmd}
slimlint:
runner: dip {cmd}
yamllint:
runner: dip {cmd}
prettier:
runner: dip {cmd}
eslint:
runner: dip {cmd}
scsslint:
runner: dip {cmd}
I would like to have something like:
runner_prefix: "dip "
# or at the group level
pre-commit:
commands:
runner_prefix:
prefix: "dip"
except:
- some-non-psrefixable-command
Or similar.
@Arkweid What do you think?
Looks good. But I have my doubts. A new configuration word is being put into config, plus 2 subset words. Three new keywords to achieve some visual improvement. Potential range of users quite narrow = docker + dip users + "visual beauty requirement".
Well, that's the price for flexibility. Putting this declaration into a top-level namespace wouldn't cause any problems due to keywords usages.
I have a crazier idea which could also help to solve this particular issue (but not only): configuration parameters.
# lefthook.yml
parameters:
prefix: ""
something_else: "bla"
pre-commit:
commands:
rubocop: "{prefix} bundle exec rubocop"
# this one doesn't need a prefix
gitlint: "gitlint"
# lefthook-local.yml
parameters:
prefix: "dip"
More explicit and more flexible at the same time. WDYT?
Yea, that second variant looks awesome. It looks cleaner and potentially has a wider range of users.
For someone, who like me tryin to make it right now (for hybrid dip/non-dip env's)
run: "( [[ -f $(command -v dip) ]] && echo 'dip bundle' || echo 'bundle' ) | xargs -t -I % bash -c '% exec rubocop -c .rubocop.yml --force-exclusion {staged_files}'"
if you can rewrite it more elegantly, feel free