Skip to content

Commit 18ccfe8

Browse files
committed
feat: added further linting
ensure lock file consistency and ensure npm audit fix
1 parent 559bc9d commit 18ccfe8

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.config/.lintstagedrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"*.md": "markdownlint --config .config/.markdown-lint.yml --fix",
33
"test/fixtures/*.css": "npm run build:docs",
4-
"*.{js,ts,tsx,jsx,mjs,cjs}": "npm run lint:xo -- --fix"
4+
"*.{js,ts,tsx,jsx,mjs,cjs}": "npm run lint:xo -- --fix",
5+
"package-lock.json": "npm audit fix"
56
}

.husky/pre-push

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Configuration: Each entry is an array with [pattern, command, description]
2+
CHECKS=(
3+
# Format: "pattern" "command" "pattern description"
4+
'^(package\.json|package-lock\.json)$' 'npm install --package-lock-only --ignore-scripts' 'package.json or package-lock.json'
5+
)
6+
7+
# Check for changes in specified files before pushing and run corresponding commands
8+
## Get the upstream branch
9+
UPSTREAM=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)
10+
if [ -z "$UPSTREAM" ]; then
11+
echo "No upstream configured, skipping pre-push checks."
12+
exit 0
13+
fi
14+
15+
## Get the list of files changed between upstream and HEAD
16+
FILES=$(git diff --name-only $UPSTREAM..HEAD)
17+
18+
## Check each pattern and run corresponding command
19+
for ((i=0; i<${#CHECKS[@]}; i+=3)); do
20+
pattern="${CHECKS[i]}"
21+
command="${CHECKS[i+1]}"
22+
description="${CHECKS[i+2]}"
23+
24+
if echo "$FILES" | grep -qE "$pattern"; then
25+
echo "Detected changes in $description"
26+
27+
## Run the corresponding command
28+
eval "$command"
29+
30+
if [ $? -ne 0 ]; then
31+
echo "Command failed: $command. Aborting push."
32+
exit 1
33+
fi
34+
35+
# Exit after first match to avoid running multiple commands
36+
exit 0
37+
fi
38+
done
39+
40+
echo "No monitored file changes detected. Skipping checks."

0 commit comments

Comments
 (0)