I'm cleaning up a repo with the lint-history
tool associated with git-filter-repo
, applying Prettier to all commits:
python lint-history --relevant 'filename.endswith(b".ts")' prettier -w
It manages to process a few hundred commits, then crashes:
[error] ../../../../../var/abc123/somefile.ts: Expected valid tag name
[error] 30 |
[error] 31 | <div>
[error] > 32 | <<<<<<< HEAD
[error] 33 |
Traceback (most recent call last):
File "xyz/lint-history", line 174, in <module>
filter.run()
...
File "xyz/lint-history", line 132, in lint_with_real_filenames
subprocess.check_call(lint_args.command + [filename.decode('utf-8')])
File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['prettier', '-w', '/var/abc13/somefile.ts']' returned non-zero exit status 2.
fatal: stream ends early
fast-import: dumping crash report to .git/fast_import_crash_5034
It looks like the commit in question has some merge symbols (<<<<<<< HEAD
and so on) that weren't resolved at the time. How can I make it so that Prettier leaves the file alone rather than exiting with an error code? Alternatively, can I get lint-history
to continue despite the error from Prettier?
I solved this by writing a script called maybe-prettier
:
#! /usr/bin/env zsh
# Prettier gives three exit codes:
# 0 file is good
# 1 needs formatting
# 2 error
# Check the file and get the exit code. If the file needs
# formatting but doesn't produce an error, then format it.
prettier -c $1
if [[ $? = 1 ]]; then
prettier -w $1
fi
Then I can run lint-history maybe-prettier
.