lefthook icon indicating copy to clipboard operation
lefthook copied to clipboard

Feature request: runner prefixes in local configs

Open palkan opened this issue 4 years ago • 4 comments

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?

palkan avatar May 14 '20 08:05 palkan

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".

Arkweid avatar May 19 '20 14:05 Arkweid

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?

palkan avatar May 19 '20 14:05 palkan

Yea, that second variant looks awesome. It looks cleaner and potentially has a wider range of users.

Arkweid avatar May 19 '20 14:05 Arkweid

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

fobiasmog avatar Mar 15 '22 16:03 fobiasmog