I'm currently moving our CI pipeline from CircleCI to GitHub Actions and I'm having issues with Prettier. We use Prettier to enforce consistent code style in our project and it is a step in the CI pipeline. The pipeline runs on Linux, MacOS and Windows.
I execute npx prettier --check "{src,test,examples}/**/*.ts"
to check the files for formatting issues. Weirdly, this check passes on ubuntu-latest and macos-latest, but fails on windows-latest.
You can see an example output for windows-latest here:
Run npm run format:check
> [email protected] format:check D:\a\H5P-Nodejs-library\H5P-Nodejs-library
> npx prettier --check "{src,test,examples}/**/*.ts"
Checking formatting...
test\TemporaryFileManager.test.ts
[... nearly all our files...]
Code style issues found in the above file(s). Forgot to run Prettier?
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] format:check: `npx prettier --check "{src,test,examples}/**/*.ts"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] format:check script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\npm\cache\_logs\2020-05-22T14_42_05_193Z-debug.log
##[error]Process completed with exit code 1.
(see https://github.com/Lumieducation/H5P-Nodejs-library/runs/699946934?check_suite_focus=true for complete log)
Does Prettier behave differently on Windows? My main dev machine runs Windows 10 an prettier checks pass on it... Does anyone have any ideas why the check fails?
I found the cause of the problem: It's the way Git checks out line endings on Windows Server. The answer can be found at: https://github.com/prettier/prettier/issues/7825.
Solution: Add * text=auto eol=lf
to the repo's .gitattributes
file.