pre-commit checking of json,yaml,rb files

This commit is contained in:
Dylan Knutson
2025-07-13 01:37:31 +00:00
parent 6fc3f772c3
commit 51e7f9545b
5 changed files with 76 additions and 14 deletions

View File

@@ -15,24 +15,79 @@ pre-commit:
fail_text: "Sorbet type checking failed"
tapioca-gems:
run: bundle exec tapioca gems
glob: "{Gemfile,Gemfile.lock}"
run: bundle exec tapioca gem --verify
pass_filenames: false
fail_text: "Tapioca gems check failed"
fail_text: "RBI files are out of date. Please run: bundle exec tapioca gems"
trailing-whitespace:
glob: "*.{rb,yml,yaml,json,md}"
glob: "*.{rb,yml,yaml,json,md,rbi,rbs,gemspec}"
run: sed -i 's/[[:space:]]*$//' {staged_files}
stage_fixed: true
commit-msg:
commands:
# Add commit message linting if desired
# conventional-commits:
# run: echo "Commit message validation passed"
rspec:
run: bundle exec rspec
fail_text: "RSpec tests failed"
bundler-audit:
run: bundle exec bundler-audit check --update
pass_filenames: false
fail_text: "Security vulnerabilities found"
yaml-lint:
glob: "*.{yml,yaml}"
run: |
for file in {staged_files}; do
echo "Checking $file"
ruby -e "require 'yaml'; YAML.load_file('$file')" || exit 1
done
fail_text: "YAML syntax error"
json-lint:
glob: "*.json"
run: |
for file in {staged_files}; do
echo "Checking $file"
ruby -e "require 'json'; JSON.parse(File.read('$file'))" || exit 1
done
fail_text: "JSON syntax error"
gemspec-lint:
glob: "*.gemspec"
run: |
for file in {staged_files}; do
echo "Checking $file"
ruby -c "$file" || exit 1
done
fail_text: "Gemspec syntax error"
no-debug:
glob: "*.rb"
run: |
for file in {staged_files}; do
echo "Checking $file"
if grep -n "binding\.pry\|debugger\|byebug\|puts.*DEBUG\|p \|pp " "$file"; then
exit 1
fi
done
fail_text: "Debug statements found - please remove before committing"
file-size:
glob: "*"
run: |
for file in {staged_files}; do
if [ -f "$file" ]; then
size=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null)
if [ "$size" -gt 1048576 ]; then
echo "File $file is larger than 1MB"
exit 1
fi
fi
done
fail_text: "Large files detected (>1MB)"
pre-push:
commands:
# Run more comprehensive checks before pushing
# tests:
# run: bundle exec rspec
# fail_text: "Tests failed"
rspec:
run: bundle exec rspec
fail_text: "Tests failed"