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...
```
This commit is contained in:
Kristjan ESPERANTO
2025-09-11 18:34:08 +02:00
committed by GitHub
parent 08d29c3083
commit d81386f3d9
2 changed files with 2 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ Thanks to: @dathbe.
- Avoid potential port conflicts by using port 3001 for translator unit tests - Avoid potential port conflicts by using port 3001 for translator unit tests
- Improve test reliability and maintainability - Improve test reliability and maintainability
- [tests] add alert module tests for different welcome_message configurations (#3867) - [tests] add alert module tests for different welcome_message configurations (#3867)
- [lint-staged] use `prettier --write --ignore-unknown` in `lint-staged` to avoid errors on unsupported files (#3888)
### Updated ### Updated

View File

@@ -64,7 +64,7 @@
"test:unit": "NODE_ENV=test jest --selectProjects unit" "test:unit": "NODE_ENV=test jest --selectProjects unit"
}, },
"lint-staged": { "lint-staged": {
"*": "prettier --write", "*": "prettier --ignore-unknown --write",
"*.js": "eslint --fix", "*.js": "eslint --fix",
"*.css": "stylelint --fix" "*.css": "stylelint --fix"
}, },