Skip to content

Opt-in to auto-corrections? Custom fix commands that are different than the run command? #469

Closed Answered by mrexox
technicalpickles asked this question in Q&A
Discussion options

You must be logged in to vote

I guess I got it. So, you want to control these steps:

  1. Run the linter
  2. If it fails, run a fixing command
  3. Control whether to stage changes or not

If that's correct I can suggest a workaround since this flow is not usual. The idea is to call call lefthook from within itself.

# lefthook.yml

pre-commit:
  commands:
    lint:
      run: yarn lint || ([ -n "${AUTOFIX}" ] && lefthook run lint-fix || exit 1)
      # in case fixing command triggers git hooks (and then lefthook)
      # env:
      #   LEFTHOOK: 0 

lint-fix:
  commands:
    lint-fix:
      run: yarn run lint --fix
      # stage_fixed: true
# Run with no auto fixing
git commit

# Run with auto fixing
AUTOFIX=true git commit

The on…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@technicalpickles
Comment options

@mrexox
Comment options

Answer selected by technicalpickles
@technicalpickles
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants