Skip to content

Commit 2da8ec3

Browse files
joonseoleekamiazya
andauthored
chore: add pre-commit hooks for shellcheck, yamlint and shfmt (#301)
* feat: add pre-commit hooks for shellcheck, yamlint and shfmt * Add pre-commit hooks for shellcheck, yamlint, and shfmt --------- Co-authored-by: Yuki Yamazaki <35218186+kamiazya@users.noreply.github.com>
1 parent 6c03179 commit 2da8ec3

File tree

6 files changed

+151
-76
lines changed

6 files changed

+151
-76
lines changed

.changeset/fix-release-workflow-heredoc-syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"scopes": patch
33
---
44

5-
fix: Resolved a release workflow failure by correcting heredoc syntax in `release.yml` to prevent improper variable expansion.
5+
fix: Resolved a release workflow failure by correcting heredoc syntax in `release.yml` to prevent improper variable expansion.

.changeset/platform-bundle-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Replace the previous 28 individual release assets with organized bundle packages
99
- 1 unified offline package (~260MB) for enterprise/multi-platform deployments
1010
- SLSA provenance for supply chain security
1111

12-
This provides 92% reduction in download size for most users while maintaining all existing security features (SLSA Level 3, SHA256 verification) and preparing for future daemon binary distribution.
12+
This provides 92% reduction in download size for most users while maintaining all existing security features (SLSA Level 3, SHA256 verification) and preparing for future daemon binary distribution.

.changeset/thirty-boats-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"scopes": patch
3+
---
4+
5+
feat: add pre-commit hooks for shellcheck, yamlint and shfmt

lefthook.yml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pre-commit:
66
commands:
77
editorconfig:
88
glob: "*"
9-
exclude: '.claude/.*|tmp/.*|LICENSE|gradle/verification-metadata.xml'
9+
exclude: ".claude/.*|tmp/.*|LICENSE|gradle/verification-metadata.xml"
1010
run: |
1111
docker run --rm -v "$(pwd):/workspace" \
1212
-w /workspace \
@@ -39,6 +39,74 @@ pre-commit:
3939
- merge
4040
- rebase
4141

42+
shellcheck:
43+
glob: "**/*.sh"
44+
run: |
45+
if command -v shellcheck &> /dev/null; then
46+
echo "🔍 Running shellcheck on shell scripts..."
47+
shellcheck {staged_files}
48+
else
49+
echo "❌ shellcheck not found!"
50+
echo " Please install shellcheck to validate shell scripts:"
51+
echo " • macOS: brew install shellcheck"
52+
echo " • Ubuntu/Debian: sudo apt install shellcheck"
53+
echo " • CentOS/RHEL: sudo yum install shellcheck"
54+
echo " • Or download from: https://github.com/koalaman/shellcheck"
55+
echo ""
56+
echo " Skipping shell script validation for now..."
57+
exit 1
58+
fi
59+
skip:
60+
- merge
61+
- rebase
62+
63+
yamllint:
64+
glob: "**/*.{yml,yaml}"
65+
run: |
66+
if command -v yamllint &> /dev/null; then
67+
echo "🔍 Running yamllint on YAML files..."
68+
yamllint {staged_files}
69+
else
70+
echo "❌ yamllint not found!"
71+
echo " Please install yamllint to validate YAML files:"
72+
echo " • macOS: brew install yamllint"
73+
echo " • Ubuntu/Debian: sudo apt install yamllint"
74+
echo " • CentOS/RHEL: sudo yum install yamllint"
75+
echo " • Or install with pip: pip install yamllint"
76+
echo ""
77+
echo " Skipping YAML validation for now..."
78+
exit 1
79+
fi
80+
skip:
81+
- merge
82+
- rebase
83+
84+
shfmt:
85+
glob: "**/*.sh"
86+
run: |
87+
if command -v shfmt &> /dev/null; then
88+
echo "🔍 Checking shell script formatting with shfmt..."
89+
# Check if files need formatting
90+
if ! shfmt -d -i 2 -ci {staged_files}; then
91+
echo "❌ Shell scripts need formatting!"
92+
echo " Run: shfmt -w -i 2 -ci {staged_files}"
93+
exit 1
94+
fi
95+
echo "✅ Shell scripts are properly formatted"
96+
else
97+
echo "❌ shfmt not found!"
98+
echo " Please install shfmt to format shell scripts:"
99+
echo " • macOS: brew install shfmt"
100+
echo " • Ubuntu/Debian: sudo apt install shfmt"
101+
echo " • Or download from: https://github.com/mvdan/sh"
102+
echo ""
103+
echo " Skipping shell script formatting check for now..."
104+
exit 1
105+
fi
106+
skip:
107+
- merge
108+
- rebase
109+
42110
# Claude Code integration - runs after file edits
43111
post-tool-use-edit:
44112
parallel: true

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"name": "scopes",
3-
"version": "0.0.4",
4-
"private": true,
5-
"scripts": {
6-
"changeset": "changeset",
7-
"changeset:add": "changeset add",
8-
"changeset:status": "changeset status",
9-
"version-packages": "changeset version",
10-
"tag": "changeset tag"
2+
"name" : "scopes",
3+
"version" : "0.0.4",
4+
"private" : true,
5+
"scripts" : {
6+
"changeset" : "changeset",
7+
"changeset:add" : "changeset add",
8+
"changeset:status" : "changeset status",
9+
"version-packages" : "changeset version",
10+
"tag" : "changeset tag"
1111
},
12-
"author": "Yuki Yamazaki <yuki@kamiazya.tech>",
13-
"license": "Apache-2.0",
14-
"engines": {
15-
"node": ">=24"
12+
"author" : "Yuki Yamazaki <yuki@kamiazya.tech>",
13+
"license" : "Apache-2.0",
14+
"engines" : {
15+
"node" : ">=24"
1616
},
17-
"packageManager": "pnpm@10.6.5",
18-
"devDependencies": {
19-
"@changesets/changelog-github": "^0.5.1",
20-
"@changesets/cli": "^2.29.7"
17+
"packageManager" : "pnpm@10.6.5",
18+
"devDependencies" : {
19+
"@changesets/changelog-github" : "^0.5.1",
20+
"@changesets/cli" : "^2.29.7"
2121
}
2222
}

scripts/database-maintenance.sh

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,33 @@ mkdir -p "$(dirname "$LOG_FILE")"
1414

1515
# Logging function
1616
log() {
17-
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
17+
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
1818
}
1919

2020
# Error handling
2121
trap 'log "ERROR: Script failed at line $LINENO"' ERR
2222

2323
# Function to optimize a database
2424
optimize_database() {
25-
local db_path="$1"
26-
local db_name=$(basename "$db_path")
25+
local db_path="$1"
26+
local db_name
27+
db_name=$(basename "$db_path")
2728

28-
log "Starting optimization for $db_name"
29+
log "Starting optimization for $db_name"
2930

30-
if [[ ! -f "$db_path" ]]; then
31-
log "WARNING: Database $db_path not found, skipping"
32-
return 0
33-
fi
31+
if [[ ! -f "$db_path" ]]; then
32+
log "WARNING: Database $db_path not found, skipping"
33+
return 0
34+
fi
3435

35-
# Create backup before optimization using sqlite3 .backup for WAL safety
36-
local backup_path="${db_path}.backup.$(date '+%Y%m%d-%H%M%S')"
37-
log "Creating backup: $backup_path"
38-
sqlite3 "$db_path" ".backup '$backup_path'"
36+
# Create backup before optimization using sqlite3 .backup for WAL safety
37+
local backup_path
38+
backup_path="${db_path}.backup.$(date '+%Y%m%d-%H%M%S')"
39+
log "Creating backup: $backup_path"
40+
sqlite3 "$db_path" ".backup '$backup_path'"
3941

40-
# Run SQLite optimization commands
41-
sqlite3 "$db_path" <<EOF 2>&1 | tee -a "$LOG_FILE"
42+
# Run SQLite optimization commands
43+
if sqlite3 "$db_path" <<EOF 2>&1 | tee -a "$LOG_FILE"; then
4244
-- Analyze database for query optimizer
4345
PRAGMA analysis_limit=1000;
4446
ANALYZE;
@@ -60,27 +62,26 @@ PRAGMA freelist_count;
6062
SELECT 'Database size: ' || page_count * page_size / 1024 / 1024 || ' MB' FROM pragma_page_count(), pragma_page_size();
6163
SELECT 'Free pages: ' || freelist_count FROM pragma_freelist_count();
6264
EOF
63-
64-
if [[ $? -eq 0 ]]; then
65-
log "Successfully optimized $db_name"
66-
67-
# Remove old backups (keep last 7 days)
68-
find "$(dirname "$db_path")" -name "$(basename "$db_path").backup.*" -mtime +7 -delete 2>/dev/null || true
69-
log "Cleaned up old backups for $db_name"
70-
else
71-
log "ERROR: Failed to optimize $db_name"
72-
return 1
73-
fi
65+
log "Successfully optimized $db_name"
66+
67+
# Remove old backups (keep last 7 days)
68+
find "$(dirname "$db_path")" -name "$(basename "$db_path").backup.*" -mtime +7 -delete 2>/dev/null || true
69+
log "Cleaned up old backups for $db_name"
70+
else
71+
log "ERROR: Failed to optimize $db_name"
72+
return 1
73+
fi
7474
}
7575

7676
# Function to analyze database performance
7777
analyze_performance() {
78-
local db_path="$1"
79-
local db_name=$(basename "$db_path")
78+
local db_path="$1"
79+
local db_name
80+
db_name=$(basename "$db_path")
8081

81-
log "Analyzing performance for $db_name"
82+
log "Analyzing performance for $db_name"
8283

83-
sqlite3 "$db_path" <<EOF 2>&1 | tee -a "$LOG_FILE"
84+
sqlite3 "$db_path" <<EOF 2>&1 | tee -a "$LOG_FILE"
8485
-- Check for missing indexes
8586
SELECT 'Tables without any index:';
8687
SELECT name FROM sqlite_master
@@ -112,39 +113,40 @@ EOF
112113

113114
# Main execution
114115
main() {
115-
log "=== Starting database maintenance ==="
116-
log "Database directory: $DB_DIR"
116+
log "=== Starting database maintenance ==="
117+
log "Database directory: $DB_DIR"
117118

118-
if [[ ! -d "$DB_DIR" ]]; then
119-
log "ERROR: Database directory $DB_DIR not found"
120-
exit 1
121-
fi
119+
if [[ ! -d "$DB_DIR" ]]; then
120+
log "ERROR: Database directory $DB_DIR not found"
121+
exit 1
122+
fi
122123

123-
# Find all SQLite databases
124-
local databases=($(find "$DB_DIR" -name "*.db" -type f 2>/dev/null))
124+
# Find all SQLite databases
125+
local databases
126+
mapfile -t databases < <(find "$DB_DIR" -name "*.db" -type f 2>/dev/null)
125127

126-
if [[ ${#databases[@]} -eq 0 ]]; then
127-
log "No databases found in $DB_DIR"
128-
exit 0
129-
fi
128+
if [[ ${#databases[@]} -eq 0 ]]; then
129+
log "No databases found in $DB_DIR"
130+
exit 0
131+
fi
130132

131-
log "Found ${#databases[@]} database(s)"
132-
133-
# Process each database
134-
for db in "${databases[@]}"; do
135-
log "----------------------------------------"
136-
optimize_database "$db"
137-
analyze_performance "$db"
138-
done
133+
log "Found ${#databases[@]} database(s)"
139134

135+
# Process each database
136+
for db in "${databases[@]}"; do
140137
log "----------------------------------------"
141-
log "=== Database maintenance completed ==="
142-
143-
# Summary
144-
log ""
145-
log "Summary:"
146-
log "- Processed ${#databases[@]} database(s)"
147-
log "- Log file: $LOG_FILE"
138+
optimize_database "$db"
139+
analyze_performance "$db"
140+
done
141+
142+
log "----------------------------------------"
143+
log "=== Database maintenance completed ==="
144+
145+
# Summary
146+
log ""
147+
log "Summary:"
148+
log "- Processed ${#databases[@]} database(s)"
149+
log "- Log file: $LOG_FILE"
148150
}
149151

150152
# Run main function

0 commit comments

Comments
 (0)