This guide helps you integrate a11y into large codebases with minimal disruption.
npm install --save-dev eslint-plugin-a11y eslint// .eslintrc.js
module.exports = {
plugins: ['a11y'],
extends: ['plugin:a11y/minimal'],
ignorePatterns: [
'**/node_modules/**',
'**/dist/**',
'**/build/**'
]
}This enables only 3 critical rules:
button-label- Buttons must have labelsform-label- Form controls must have labelsimage-alt- Images must have alt text
# First run (slower)
npx eslint . --cache
# Subsequent runs (faster)
npx eslint . --cacheEnable minimal rules but only check new/modified files:
// .eslintrc.js
module.exports = {
plugins: ['a11y'],
extends: ['plugin:a11y/minimal']
}# Only check staged files (git)
npx eslint $(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|jsx|ts|tsx|vue)$')// .eslintrc.js
module.exports = {
plugins: ['a11y'],
extends: ['plugin:a11y/recommended']
}Focus on fixing violations in files you're actively working on.
Gradually expand to check entire codebase:
# Check specific directories first
npx eslint src/components/ --cache
npx eslint src/pages/ --cache
# Then expand to full codebase
npx eslint . --cacheAlways use --cache flag:
// package.json
{
"scripts": {
"lint": "eslint . --cache",
"lint:fix": "eslint . --cache --fix"
}
}# Check only source files
npx eslint src/ --cache
# Exclude test files
npx eslint src/ --cache --ignore-pattern '**/*.test.*'// .eslintrc.js
module.exports = {
plugins: ['a11y'],
extends: ['plugin:a11y/recommended'],
rules: {
// Disable if too slow on large files
'a11y/heading-order': 'off',
'a11y/landmark-roles': 'off'
}
}// .eslintrc.js
module.exports = {
plugins: ['a11y'],
extends: ['plugin:a11y/recommended'],
overrides: [
{
files: ['src/components/**/*.{js,jsx,ts,tsx}'],
rules: {
'a11y/**': 'error' // Strict in components
}
},
{
files: ['src/utils/**/*.{js,ts}'],
rules: {
'a11y/**': 'off' // Disable in utils
}
}
]
}# .github/workflows/lint.yml
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm run lint -- --cache --cache-location .eslintcacheSolutions:
- Use
--cacheflag - Limit file scope with
ignorePatterns - Start with
minimalconfig - Disable slow rules temporarily
- Use
--max-warningsto limit output
npx eslint . --cache --max-warnings 100Solutions:
- Start with
minimalconfig - Use
--max-warningsflag - Focus on new code first
- Gradually expand scope
- Install
a11y - Add minimal config to
.eslintrc.js - Add ignore patterns for build outputs
- Test on small directory first
- Enable ESLint cache
- Run on CI/CD
- Gradually expand to recommended config
- Fix violations incrementally