From d81386f3d964974b86b9943ed3d214a81cb6859d Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:34:08 +0200 Subject: [PATCH] chore: use `prettier --write --ignore-unknown` in `lint-staged` to avoid errors on unsupported files (#3888) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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... ``` --- CHANGELOG.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d0a462..eed2625c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Thanks to: @dathbe. - Avoid potential port conflicts by using port 3001 for translator unit tests - Improve test reliability and maintainability - [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 diff --git a/package.json b/package.json index 9d47abf0..91f010e1 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "test:unit": "NODE_ENV=test jest --selectProjects unit" }, "lint-staged": { - "*": "prettier --write", + "*": "prettier --ignore-unknown --write", "*.js": "eslint --fix", "*.css": "stylelint --fix" },