Skip to main content

package.json

Created on Sat Apr 22 2023Last updated on Sun Jan 21 2024
{  
// 1. Use these exact dependencies
"devDependencies": {
"husky": "=8.0.3",
"lint-staged": "=13.2.1"
}

// 2. Make sure it installs when people install dependencies
"scripts": {
"prepare": "husky install"
}

// 3. Configure checks to run simultaneously (only 1 that writes)
"lint-staged": {
"*.@(ts|tsx)": "bash -c 'tsc --skipLibCheck --noEmit'", // the `bash -c` part is to make sure tsc picks up tsconfig.json (See: https://github.com/okonet/lint-staged/issues/825#issuecomment-674575655)
"*.@(ts|tsx|js|jsx)": "eslint --max-warnings 0", // if you want to fail on warnings too, otherwise simply `eslint`
"*.@(ts|tsx|js|jsx|json|jsonc|json5|md|mdx|yaml|yml)": "prettier --write" // automatically fix formatting errors
}
}

pre-commit.sh

Created on Sat Apr 22 2023Last updated on Sun Jan 21 2024
# .husky/pre-commit

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# If tty is available, apply fix from https://github.com/typicode/husky/issues/968#issuecomment-1176848345
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then exec >/dev/tty 2>&1; fi

# Heavy checks should only be done on staged files
yarn lint-staged