sinpro.dev
Docs
Assets
TTF to WOFF2
  • Company Information
    • Portfolio
    • About
    • Services
    • Events
  • Dev Environment
    • macOS Settings
    • Chrome Extensions
    • VSCode Workspace Settings
    • VSCode Workspace Extensions
    • Global NPM Packages
    • npm-check-updates
    • SvelteKit
    • Customize Zsh
    • ChatGPT Prompts
    • Tailwind CSS
    • Warp
    • Keyboard Shortcuts
  • Assets
    • Assets
    • JPG/PNG to AVIF
    • TTF to WOFF2
  • Clean Code
    • Clean Code
    • Format
    • Quality
    • Variables
    • Functions
    • Objects and Data Structures
    • Classes
    • Concurrency
    • Error handling
    • Comments
  • Code Style
    • TypeScript Config
    • Prettier
    • ESLint
    • Stylelint
  • Testing
    • Vitest
    • Playwright
  • Git
    • Git Branches and Commits
    • Git Hooks
    • Git User Profiles
    • Git for Windows
  • GitHub
    • GitHub Issues
    • GitHub Pull Requests
    • GitHub Repository Settings
    • GitHub Branch Protection
    • GitHub Actions
  • Code Quality
    • SonarCloud Coverage
  • Server
    • SSH
    • PM2
    • Caddy
    • Updating the server
    • ngrok
  • Team sinProject
    • Our Team Policy
    • Equipment and Supplies
    • Books
    • Slack
    • Locales
    • Funny Apps
    • Docs History
  • Talk
    • Talk
    • Creating a Project
    • App Structure

Git

Git Hooks

Edit this page

We use lint-staged and Husky for our Git Hooks.

  • lint-staged - Run linters against staged git files and don’t let 💩 slip into your code base!
  • Husky - Husky improves your commits and more 🐶 woof!

Installation

Bash
npm install --save-dev lint-staged
Bash
npx husky-init && npm install

pre-commit

Combine ESLint, Stylelint, Prettier, and lint-staged to format code.

package.json
{
	"scripts": {
		"lint": "eslint .",
	},

	// ...

	"lint-staged": {
		"*.{js,ts,svelte}": "eslint --cache --fix",
		"*.css": "stylelint --fix",
		"*.{js,css,md,ts,svelte,css,scss,json}": "prettier --write"
	}
}
.husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

current_branch=$(git branch --show-current)

if [ "$current_branch" = "main" ]; then
  echo "Error: You cannot commit directly to main branch!"
  exit 1
fi

npx lint-staged

npm run lint

pre-push

Perform TypeScript type checking, run tests with Vitest, and finally check for conflicts.

package.json
{
	"scripts": {
		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
		"test:unit:run": "vitest run",
		"typecheck": "tsc --noEmit"
	}
}
.husky/pre-push
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run typecheck
npm run check

npm run test:unit:run

git fetch origin
git merge --no-commit --no-ff origin/main
git reset --hard HEAD
Git Branches and Commits Git User Profiles
© sinProject. v0.73.0
On this page
  • Git Hooks
  • Installation
  • pre-commit
  • pre-push