Tool that runs linters on git staged files to ensure only quality code is committed
Core Idea: Lint-staged runs linters (like ESLint) only on files that are staged for git commit, improving performance by avoiding full codebase linting and ensuring all committed code meets quality standards.
Key Elements
-
Key Features:
- Targets only git staged files
- Significant performance improvement for large codebases
- Supports multiple linters and formatters
- Can be combined with other git hooks tools
- Prevents low-quality code from entering the repository
-
Technical Specifications:
- Node.js based tool
- Configurable via package.json or dedicated config file
- Can be run manually or through git hooks
- Supports file type matching patterns
- Can run different commands for different file types
-
Use Cases:
- Pre-commit code quality enforcement
- Ensuring consistent code style in team environments
- Preventing test failures before committing
- Running type checking on specific files
- Optimizing performance in large projects
-
Implementation Steps:
- Install lint-staged:
npm install --save-dev lint-staged
- Configure lint-staged in package.json:
{ "lint-staged": { "*.{js,jsx,ts,tsx}": "eslint --fix", "*.{json,md}": "prettier --write" } }
- Install lint-staged:
3. Integrate with git hooks tool like Husky
4. Run automatically before commits or manually as needed
- **Code Example**:
```js
// package.json configuration example
{
"scripts": {
"lint-staged": "lint-staged"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"jest --findRelatedTests"
],
"*.{json,css,md}": "prettier --write"
}
}
```
## Connections
- **Related Concepts**: ESLint (tool commonly run by lint-staged), Husky Pre-commit Hooks (triggers lint-staged before commits)
- **Broader Context**: Git Workflow Automation (part of automated git workflow)
- **Applications**: Code Quality Automation (enforces quality standards automatically)
- **Components**: Git Hooks (mechanism that enables lint-staged to work)
## References
1. Lint-staged GitHub Repository: https://github.com/okonet/lint-staged
2. "Modern JavaScript Tools and Practices" by Cory House
#git #automation #code-quality #linting #developer-workflow
---
**Connections:**
-
---
**Sources:**
- From: Syntax - Lint como un desarrollador senior con eslint + husky + lint staged + acciones de github