This document outlines the code quality tools and practices used in the GitHub Toolkit project to maintain high standards of code consistency, type safety, and formatting.
The project implements a comprehensive code quality setup with three main pillars:
- Linting - Static code analysis with ESLint
- Code Formatting - Automatic code formatting with Prettier
- Type Safety - TypeScript type checking
- Pre-commit Hooks - Automated checks before commits with Husky
ESLint is used to identify and report patterns found in ECMAScript/JavaScript and TypeScript code. It helps catch bugs and enforces code style consistency.
- Config File:
.eslintrc.json - Ignore File:
.eslintignore
Recommended Rules Extended:
@typescript-eslint/recommended- TypeScript best practicesplugin:react/recommended- React best practicesplugin:react-hooks/recommended- React Hooks rulesnext/core-web-vitals- Next.js core web vitalsprettier- Integration with Prettier to avoid conflicts
- Unused Variables: Variables starting with
_are ignored (e.g.,_unused) - Any Type: Using
anyis warned (not errored) to allow gradual migration - React in JSX: Not required to import React in Next.js
- Prettier Integration: Formatting issues are reported as ESLint errors for unified workflow
# Lint all TypeScript and JavaScript files
yarn lint
# Lint and automatically fix issues
yarn lint:fixPrettier is an opinionated code formatter that enforces a consistent code style across the entire codebase.
- Config File:
.prettierrc - Ignore File:
.prettierignore
{
"semi": true, // Add semicolons
"trailingComma": "es5", // Trailing commas in ES5 syntax
"singleQuote": true, // Use single quotes
"printWidth": 100, // Line length limit
"tabWidth": 2, // Indentation size
"useTabs": false, // Use spaces instead of tabs
"arrowParens": "always" // Always include arrow function parentheses
}# Format all files
yarn format
# Check formatting without making changes
yarn format:checkTypeScript provides static type checking to catch errors during development and improve code reliability.
- Config File:
tsconfig.json
# Check for type errors without emitting output
yarn type-checkHusky enables running scripts on Git hooks, while lint-staged runs linters only on staged files to improve performance.
- Hook File:
.husky/pre-commit - Lint-Staged Config: Defined in
package.json
The pre-commit hook automatically runs:
-
Lint-Staged: Lints and formats all staged files
- TypeScript/JavaScript files: ESLint + Prettier
- JSON/Markdown/YAML files: Prettier only
-
Type Check: Verifies no TypeScript errors exist
If any check fails, the commit is prevented. Fix the issues and try again.
"lint-staged": {
"*.{ts,tsx,js,jsx}": ["eslint --fix", "prettier --write"],
"*.{json,md,yaml,yml}": ["prettier --write"]
}-
Stage your changes:
git add . -
The pre-commit hook will automatically:
- Run ESLint and fix auto-fixable issues
- Format code with Prettier
- Check TypeScript for errors
-
If errors occur:
- Manual errors that can't be auto-fixed must be corrected
- Re-stage the corrected files
- Try committing again
- Enable ESLint in your IDE: Most IDEs (VS Code, etc.) recognize
.eslintrc.jsonautomatically - Enable Prettier formatting: Use the Prettier extension in your IDE
- Run checks manually: Use
yarn lint:fixandyarn formatto pre-fix issues before committing
For the best development experience with VS Code, consider installing:
Add this to your .vscode/settings.json:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"eslint.validate": ["typescript", "typescriptreact"],
"eslint.run": "onSave"
}Problem: ESLint errors that can't be auto-fixed
- Solution: Review the error messages and fix them manually
- Check the ESLint documentation
Problem: ESLint and Prettier formatting conflicts
- Solution: This should not happen due to
eslint-config-prettierintegration - Run
yarn lint:fixfollowed byyarn format
Problem: Commits blocked by pre-commit hook
- Solution:
- Fix the reported errors
- Stage the corrected files
- Commit again
Problem: TypeScript errors preventing commits
- Solution:
- Run
yarn type-checkto see all errors - Fix type errors according to TypeScript diagnostics
- Stage corrected files and retry
- Run
- Keep ESLint Configuration Updated: Review and update rules as the project evolves
- Use IDE Extensions: Install ESLint and Prettier extensions for real-time feedback
- Run Checks Locally: Use
yarn lint:fix,yarn format:check, andyarn type-checkbefore pushing - Don't Disable Rules Globally: Use inline comments only when necessary (
// eslint-disable-line) - Review Rule Violations: Understand why a rule exists before ignoring it