Skip to content

Commit

Permalink
lint-staged doesnt actually support async, their github lies
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Oct 26, 2024
1 parent b04598f commit 49651af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
5 changes: 3 additions & 2 deletions bin/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ if \git --no-pager diff-index -z --name-only --no-renames --cached HEAD | \
\grep -qzE '\.(json|scss|ts)$'; then
# NOTE! grep must be kept in sync with lint-staged in package.json!

LINT_STAGED="$(dirname -- "$0")/../../node_modules/.bin/lint-staged"
BIN_DIR="$(dirname -- $0)/.."
LINT_STAGED="$BIN_DIR/../node_modules/.bin/lint-staged"

# pnpm or npx adds .25s overhead. exec further reduces overhead.
if [ -x "$LINT_STAGED" ]; then
exec "$LINT_STAGED"
exec "$LINT_STAGED" --config "$BIN_DIR/lint-staged.config.mjs"
else
exec pnpm lint-staged
fi
Expand Down
17 changes: 3 additions & 14 deletions bin/lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import { lstat } from 'fs/promises';

async function filterSymlinks(files) {
const checks = await Promise.all(
files.map(async file =>
lstat(file)
.then(s => s && !s.isSymbolicLink() && file)
.catch(() => null),
),
);
return checks.filter(Boolean);
}
import { lstatSync } from 'fs';

export default {
'*.{json,scss,ts}': async files => {
const regularFiles = await filterSymlinks(files);
'*.{json,scss,ts}': files => {
const regularFiles = files.filter(f => !lstatSync(f).isSymbolicLink());
return regularFiles.length ? `prettier --write ${regularFiles.join(' ')}` : 'true';
},
};

0 comments on commit 49651af

Please sign in to comment.