Lint-staged Workflow for OWOX Data Marts
Overview
Section titled βOverviewβOWOX Data Marts uses distributed lint-staged configurations following official best practices for multi-package monorepos.
π Workflow Diagram
Section titled βπ Workflow DiagramβsequenceDiagram participant Dev as Developer participant Git as Git Hook participant LS as lint-staged participant Config as .lintstagedrc.json participant ESL as ESLint participant Prettier as Prettier
Dev->>Git: git commit -m "..." Git->>LS: Trigger pre-commit hook LS->>LS: Detect staged files
Note over LS,Config: Automatic config discovery LS->>Config: Find nearest .lintstagedrc.json Config-->>LS: Return configuration rules
LS->>ESL: Run ESLint validation ESL-->>LS: Return results
alt ESLint has errors LS->>Dev: β Commit blocked Note right of Dev: Fix errors manually Dev->>Dev: git add fixes Dev->>Git: git commit (retry) else ESLint passes LS->>Prettier: Format files Prettier-->>LS: Files formatted LS->>Git: β
Continue commit Git->>Dev: π Commit successful end
ποΈ Architecture
Section titled βποΈ ArchitectureβConfiguration Discovery
Section titled βConfiguration Discoveryβlint-staged automatically finds the nearest configuration file to each staged file:
π project-root/βββ .lintstagedrc.json # Root config (fallback)βββ π apps/β βββ π backend/β β βββ .lintstagedrc.json # Backend-specific rulesβ β βββ src/app.module.ts # β Uses backend configβ βββ π web/β βββ .lintstagedrc.json # Frontend-specific rulesβ βββ src/App.tsx # β Uses web configβββ π packages/ βββ π ui/ β βββ .lintstagedrc.json # UI-specific rules β βββ src/button.tsx # β Uses UI config βββ README.md # β Uses root config
How It Works
Section titled βHow It Worksβ- File Detection: Git detects staged files
- Config Discovery: lint-staged finds nearest
.lintstagedrc.json
for each file - Workspace Isolation: Each workspace runs with its own rules
- Tool Execution: ESLint validates β Prettier formats (if validation passes)
- Commit Control: Commit blocked if any errors found
π Configuration Examples
Section titled βπ Configuration ExamplesβBackend TypeScript (apps/backend/.lintstagedrc.json
)
Section titled βBackend TypeScript (apps/backend/.lintstagedrc.json)β{ "*.{ts,tsx}": [ "eslint --config ./eslint.config.mjs", "prettier --config ./prettier.config.mjs --write" ], "*.json": ["prettier --config ./prettier.config.mjs --write"], "*.md": ["prettier --config ./prettier.config.mjs --write"]}
Frontend React (apps/web/.lintstagedrc.json
)
Section titled βFrontend React (apps/web/.lintstagedrc.json)β{ "*.{ts,tsx,js,jsx}": [ "eslint --config ./eslint.config.js", "prettier --config ./prettier.config.js --write" ], "*.json": ["prettier --config ./prettier.config.js --write"], "*.{css,scss}": ["prettier --config ./prettier.config.js --write"]}
Root Fallback (.lintstagedrc.json
)
Section titled βRoot Fallback (.lintstagedrc.json)β{ "*.json": "prettier --write", "*.{yml,yaml}": "prettier --write"}
π οΈ Setup
Section titled βπ οΈ SetupβThe setup is handled automatically by the tools/setup-husky.js
script:
# Manual setup (if needed)npm run setup:husky
# Automatic setup (runs on npm install)npm install # β triggers postinstall β setup:husky
What the setup does:
Section titled βWhat the setup does:β- Initializes Husky: Creates
.husky/
directory - Creates pre-commit hook: Runs
npm run pre-commit
- Makes hook executable: Sets proper permissions
π« Bypassing Pre-commit Hooks
Section titled βπ« Bypassing Pre-commit HooksβSometimes you need to commit without running lint-staged:
Temporary Bypass (Single Commit)
Section titled βTemporary Bypass (Single Commit)β# Emergency commit (skip all hooks)git commit --no-verify -m "Emergency hotfix"
# Alternative short formgit commit -n -m "Emergency hotfix"
Temporary Disable (Multiple Commits)
Section titled βTemporary Disable (Multiple Commits)β# Disable pre-commit hookmv .husky/pre-commit .husky/pre-commit.disabled
# Make your commitsgit commit -m "WIP: Large refactoring"git commit -m "WIP: Continue refactoring"
# Re-enable hookmv .husky/pre-commit.disabled .husky/pre-commit
π Troubleshooting
Section titled βπ TroubleshootingβCommon Issues
Section titled βCommon Issuesβ1. Hooks Not Running
Section titled β1. Hooks Not Runningβ# Check if hooks are executablels -la .husky/pre-commit
# Fix permissions (Unix/macOS)chmod +x .husky/pre-commit
# Reinstall hooksnpm run setup:husky
2. ESLint Configuration Not Found
Section titled β2. ESLint Configuration Not Foundββ ESLint couldn't find a configuration file.
# Solution: Ensure workspace has eslint.config.js/mjsls apps/backend/eslint.config.mjsls apps/web/eslint.config.js
3. Prettier Configuration Issues
Section titled β3. Prettier Configuration Issuesββ Prettier configuration not found
# Solution: Ensure workspace has prettier.config.js/mjsls apps/backend/prettier.config.mjsls apps/web/prettier.config.js
Debug Mode
Section titled βDebug Modeβ# Run lint-staged with debug outputDEBUG=lint-staged* npm run pre-commit
# Check what files would be processednpx lint-staged --dry-run
π― Best Practices
Section titled βπ― Best Practicesββ Recommended Workflow
Section titled ββ Recommended Workflowβ- Write code with ESLint IDE integration
- Stage changes:
git add .
- Commit:
git commit -m "descriptive message"
- If blocked: Fix errors and retry
β Fixing ESLint Errors
Section titled ββ Fixing ESLint Errorsβ# See what's wrongnpm run lint
# Auto-fix simple issuesnpm run lint:fix
# Format after fixingnpm run format
# Stage fixes and retrygit add . && git commit
β Anti-patterns
Section titled ββ Anti-patternsβ- Donβt blindly use
--no-verify
to skip hooks - Donβt disable ESLint rules without team discussion
- Donβt commit with
lint:fix
without reviewing changes
π Adding New Workspaces
Section titled βπ Adding New WorkspacesβTo add lint-staged to a new workspace:
-
Create configuration file:
packages/new-package/.lintstagedrc.json {"*.{ts,tsx}": ["eslint --config ./eslint.config.js", "prettier --write"],"*.json": ["prettier --write"]} -
Test the configuration:
Terminal window cd packages/new-packageecho "test" > test.tsgit add test.tsgit commit -m "test" # Should use new config automatically -
No additional setup needed - lint-staged discovers configs automatically!