Git tips - lint + test pre-commit hook

• git, bash

A nice last minute sanity check I use is a pre-commit hook that auto runs test and lint commands from a makefile or package.json if they’re found:

 1#!/usr/bin/env bash
 2
 3if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^lint:')" ]; then
 4    echo "running make lint"
 5    make lint
 6elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"lint\":")" ]; then
 7    echo "running npm run lint"
 8    npm run lint
 9fi
10
11if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^test:')" ]; then
12    echo "running make test"
13    make test
14elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"test\":")" ]; then
15    echo "running npm run test"
16    npm run test
17fi

If the test or lint command fails then the git commit command fails. If I absolutely need to commit something in spite of the lint/test results I can do git commit --no-verify to skip the pre-commit hook.

Articles from blogs I follow

How far can you go with IX Route Servers only?

How far can you go with IX Route Servers only? On paper internet exchanges (IX) are very simple in their implementation, simply put together a bunch of routers on a shared layer 2 ethernet switch

via benjojo blog March 12, 2026

Pop quiz: what time was it?

Here’s a small quiz derived from some incorrect advice from an AI coding assistant. This program prints two timestamps; will they be a. Roughly the same time (ie, the same second)b. Roughly 10 seconds apartc. Something else Answer after the fold

via Dave Cheney December 18, 2025

Your CI should work off grid

A principle: You should be able to maintain your production system when your CI vendor is down. This doesn’t mean you must maintain reduntant CI systems, but rather define your build with an open toolkit and only use the CI vendor-specific definition langu…

via Jacob Davis-Hansson November 19, 2025

Generated by openring