eslint-plugin-quality-gates
v1.3.0
Published
ESLint plugin that enforces best practices in JavaScript/TypeScript codebases
Maintainers
Readme
eslint-plugin-quality-gates
An ESLint plugin that enforces best practices in JavaScript/TypeScript codebases. This plugin helps maintain code quality and consistency by enforcing common best practices and patterns.
Installation
npm install --save-dev eslint-plugin-quality-gatesRequirements
- ESLint >= 8.0.0
- Node.js >= 16.0.0
Usage
Basic Configuration
Add eslint-plugin-quality-gates to the plugins section of your ESLint configuration file:
{
"plugins": [
"eslint-plugin-quality-gates"
]
}Flat Config (ESLint 8.21.0+)
If you're using the new flat config format:
// eslint.config.js
import eslintPluginQualityGates from 'eslint-plugin-quality-gates';
export default [
{
plugins: {
'eslint-plugin-quality-gates': eslintPluginQualityGates,
},
rules: {
// Configure your rules here
},
},
];Rules
file-naming-convention
Enforces consistent file naming patterns across your codebase. By default, it ensures files follow camelCase naming, but you can specify any pattern for any folder.
Flexible Examples:
// .eslintrc.js
module.exports = {
rules: {
'eslint-plugin-quality-gates/file-naming-convention': ['error', {
patterns: [
{ pattern: '^[a-z][a-zA-Z0-9]*$', folders: ['src/components'] }, // camelCase
{ pattern: '^[A-Z][a-zA-Z0-9]*$', folders: ['src/pages'] }, // PascalCase
{ pattern: '^[a-z][a-z0-9-]*$', folders: ['src/utils'] }, // kebab-case
{ pattern: '^special-[a-z0-9-]+$', folders: ['src/special'] }, // special prefix
{ pattern: '^[a-z][a-zA-Z0-9]*$', folders: ['.'] } // fallback
]
}]
}
};This rule:
- Allows you to specify different naming conventions for different folders
- Supports fallback/default patterns
- Works with any valid regex pattern
- Helps maintain a consistent naming convention across your project
require-exports
Ensures that specified named exports are present in specific files. This is useful for maintaining consistent module interfaces across your codebase.
// In your ESLint config
module.exports = {
rules: {
'eslint-plugin-quality-gates/require-exports': ['error', {
exports: ['metadata', 'config'] // Specify required exports
}]
}
};This rule:
- Enforces the presence of specific exports in files
- Helps maintain consistent module interfaces
- Useful for ensuring configuration files have required exports
- Supports both variable and function exports
require-attributes
Enforces required attributes on HTML/JSX elements and validates their values. This is useful for ensuring consistent component interfaces and accessibility requirements.
// In your ESLint config
module.exports = {
rules: {
'eslint-plugin-quality-gates/require-attributes': ['error', {
elements: [
{
tag: 'form',
attributes: [{ name: 'noValidate', required: true }]
},
{
tag: 'input',
attributes: [
{ name: 'type', value: 'checkbox' },
{ name: 'checked', value: false }
]
}
]
}]
}
};This rule:
- Enforces required attributes on specific HTML/JSX elements
- Validates attribute values (string, boolean, or number)
- Supports both direct literals and JSX expressions
- Helps maintain consistent component interfaces
- Useful for enforcing accessibility requirements
Contributing
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Install dependencies (
npm install) - Make your changes
- Run tests (
npm test) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Install dependencies
npm install
# Run tests
npm test
# Run linting
npm run lint
# Build the project
npm run buildAdding New Rules
- Create a new file in
src/rules/for your rule - Export your rule following the pattern in existing rules
- Add your rule to
src/index.ts - Add tests in
src/rules/__tests__/ - Update this README with documentation for your rule
Author
License
ISC
