Skip to content

Commit d81386f

Browse files
chore: use prettier --write --ignore-unknown in lint-staged to avoid errors on unsupported files (#3888)
This prevents `prettier` from failing when `lint-staged` passes unknown/binary files, making the pre-commit hook more robust. In concrete terms this could happen, when we, for example, add a new PNG file. Since we rarely do this, it has not been noticed so far. This is recommended when using asterisk: https://github.com/lint-staged/lint-staged#automatically-fix-code-style-with-prettier-for-any-format-prettier-supports ## before ```bash $ npx lint-staged <-- after staging a new PNG file ✔ Backed up original state in git stash (c3247d4b) ✔ Hiding unstaged changes to partially staged files... ⚠ Running tasks for staged files... ❯ package.json — 2 files ❯ * — 2 files ✖ prettier --write [FAILED] ↓ *.js — no files ↓ *.css — no files ↓ Skipped because of errors from tasks. ↓ Skipped because of errors from tasks. ✔ Reverting to original state because of errors... ✔ Cleaning up temporary files... ✖ prettier --write: [error] No parser could be inferred for file "~/MagicMirror/test.png". ... ``` ## after ```bash $ npx lint-staged <-- after staging a new PNG file ✔ Backed up original state in git stash (0c3fe285) ✔ Running tasks for staged files... ✔ Applying modifications from tasks... ✔ Cleaning up temporary files... ```
1 parent 08d29c3 commit d81386f

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Thanks to: @dathbe.
3939
- Avoid potential port conflicts by using port 3001 for translator unit tests
4040
- Improve test reliability and maintainability
4141
- [tests] add alert module tests for different welcome_message configurations (#3867)
42+
- [lint-staged] use `prettier --write --ignore-unknown` in `lint-staged` to avoid errors on unsupported files (#3888)
4243

4344
### Updated
4445

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"test:unit": "NODE_ENV=test jest --selectProjects unit"
6565
},
6666
"lint-staged": {
67-
"*": "prettier --write",
67+
"*": "prettier --ignore-unknown --write",
6868
"*.js": "eslint --fix",
6969
"*.css": "stylelint --fix"
7070
},

0 commit comments

Comments
 (0)