-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the recommended work around for autoformatters like prettier? #614
Comments
Side effects don't seem supported so I thought just ensuring Prettier was manually run (or automatically if you have text editor plugins) was good enough: ./.git-hooks/pre_commit/prettier.rb:
overcommit.yml:
|
thank you @hatched-danny, that's what I'll do |
I couldn't that file above to work... instead adding an executable script Prettier:
enabled: true
required_executable: './bin/prettirun' #!/bin/sh
# grep for file changes, exit early for ruby folks
FILES=$(git diff --name-only --diff-filter=ACMR -- '*.js' '*.jsx' | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Be nice: and run the yarn install for folks that haven't done it yet
if [[ ! -f ./node_modules/.bin/prettier ]]
then
# yarn add --dev --exact prettier
echo "Running Yarn install..."
open "https://prettier.io/docs/en/editors.html"
command yarn install
fi
# Prettier CHECK all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --ignore-unknown --check This will warn and output any diff'ed files that are not prettier |
@blairanderson I was able to fix the solution of @hatched-danny # frozen_string_literal: true
module Overcommit
module Hook
module PreCommit
class Prettier < Base
BOLD_RED_COLOR = '1;31'
PRETTIER_WARNING = '[warn] Code style issues found in the above file(s). Forgot to run Prettier?'
def run
result = execute(command, args: applicable_files)
output = result.stderr.chomp
has_warning = output.split("\n").any?(PRETTIER_WARNING)
return :fail, warning_message(output) if has_warning
:pass
end
private
def warning_message(message)
"\e[#{BOLD_RED_COLOR}m#{message}\e[0m"
end
end
end
end
end notable changes:
|
Hello, we are using Overcommit to run some pre-commit hooks such as eslint. From what I understand, overcommit does not support any pre-commit hooks that perform side effects on files. I also saw issue #238 which sounds like the official support is not going to be available any time soon. Does anyone have recommended work arounds for how I can still run
prettier --write
ideally before any of the overcommit pre-commit hooks run?Many thanks
The text was updated successfully, but these errors were encountered: