Accessibility Auto-Fixer is a powerful tool that scans your code for accessibility issues and automatically fixes common problems, helping you build more inclusive web applications.
π Complete Usage Guide - Detailed documentation with examples, configuration, and best practices
- π Comprehensive Scanning - Detects 14+ types of accessibility issues
- π οΈ Auto-Fix - Automatically fixes common issues without manual intervention
- π Beautiful Reports - Generate HTML or JSON reports with detailed issue breakdowns
- π― Multi-Format Support - Works with HTML, JSX, TSX, and React files
- βοΈ React & TypeScript Support - React hooks, components, and TypeScript types included
- π¨ Runtime Checking - Check accessibility issues at runtime in your React apps
- βοΈ Configurable - Customize rules, severity levels, and ignore patterns
- π High Performance - Parallel processing and file caching for 3-5x faster scans
- β¨ AST-Based Auto-Fix - More reliable JSX/TSX fixes using Abstract Syntax Tree transformations
- β‘ Parallel Processing - 3-5x faster scans with configurable concurrency
- πΎ File Caching - 95%+ faster on unchanged files with smart cache invalidation
- π― Expanded Auto-Fix - Now fixes ARIA labels and form labels automatically
- βοΈ Optimized React Hooks - Debouncing prevents excessive accessibility checks
npm install -g accessibility-auto-fixera11y-fix "**/*.html" "**/*.jsx" "**/*.tsx"a11y-fix "**/*.html" "**/*.jsx" --fixa11y-fix "**/*.html" --report --output a11y-report.htmla11y-fix <patterns...> [options]<patterns...>- File patterns to scan (e.g.,"**/*.html","**/*.jsx")
-f, --fix- Automatically fix issues where possible-r, --report- Generate a report file-o, --output <path>- Output path for report (default:a11y-report.html)-c, --config <path>- Path to config file--json- Output report as JSON--ignore <patterns...>- Patterns to ignore
import { AccessibilityAutoFixer } from 'accessibility-auto-fixer';
const scanner = new AccessibilityAutoFixer({
fix: true,
report: true,
reportPath: 'a11y-report.html',
ignore: ['**/node_modules/**'],
});
const results = await scanner.scanFiles(['**/*.html', '**/*.jsx']);
results.forEach((result) => {
console.log(`File: ${result.file}`);
console.log(`Issues: ${result.total}`);
console.log(`Fixed: ${result.fixed}`);
});This package includes React hooks and components for runtime accessibility checking in your React applications.
π See USAGE_GUIDE.md for complete React integration examples
Check accessibility issues on a specific element:
import { useAccessibility } from 'accessibility-auto-fixer/react';
import { useRef } from 'react';
function MyComponent() {
const ref = useRef<HTMLDivElement>(null);
const { issues, checkAccessibility, clearIssues } = useAccessibility(ref, {
enabled: true,
checkOnMount: true,
onIssueFound: (issues) => {
console.log('Found issues:', issues);
},
});
return (
<div ref={ref}>
<img src="/logo.png" /> {/* Missing alt text will be detected */}
{issues.length > 0 && (
<div>Found {issues.length} accessibility issues</div>
)}
</div>
);
}Convenience hook that combines useRef with useAccessibility:
import { useAccessibilityRef } from 'accessibility-auto-fixer/react';
function MyComponent() {
const { ref, issues, checkAccessibility } = useAccessibilityRef<HTMLDivElement>({
enabled: process.env.NODE_ENV === 'development',
});
return <div ref={ref}>Content</div>;
}Wrap your app or components to automatically check for accessibility issues:
import { AccessibilityChecker } from 'accessibility-auto-fixer/react';
function App() {
return (
<AccessibilityChecker enabled={true} showIssues={true}>
<div>
<h1>My App</h1>
<img src="/logo.png" /> {/* Will show missing alt text */}
<button onClick={handleClick}>Click me</button>
</div>
</AccessibilityChecker>
);
}Use context to share accessibility state across your app:
import { AccessibilityProvider, useAccessibilityContext } from 'accessibility-auto-fixer/react';
function App() {
return (
<AccessibilityProvider>
<MyComponent />
</AccessibilityProvider>
);
}
function MyComponent() {
const { issues, addIssue, clearIssues } = useAccessibilityContext();
return (
<div>
<p>Total issues: {issues.length}</p>
<button onClick={clearIssues}>Clear Issues</button>
</div>
);
}A button component that enforces accessibility best practices:
import { AccessibleButton } from 'accessibility-auto-fixer/react';
function MyComponent() {
return (
<AccessibleButton
ariaLabel="Close dialog"
onClick={handleClose}
type="button"
>
Close
</AccessibleButton>
);
}An image component that requires alt text:
import { AccessibleImage } from 'accessibility-auto-fixer/react';
function MyComponent() {
return (
<>
{/* Required alt text */}
<AccessibleImage
src="/logo.png"
alt="Company logo"
width={200}
height={100}
/>
{/* Decorative image */}
<AccessibleImage
src="/pattern.png"
alt=""
decorative={true}
/>
</>
);
}Full TypeScript support is included with type definitions:
import {
AccessibilityIssue,
UseAccessibilityOptions,
AccessibilityCheckerProps
} from 'accessibility-auto-fixer/react';The tool detects and can fix the following accessibility issues:
| Issue Type | Severity | Auto-Fixable | Description |
|---|---|---|---|
missing-alt-text |
Error | β Yes | Images missing alt attribute |
missing-aria-label |
Warning | β Yes* | Interactive elements missing aria-label |
missing-form-label |
Error | β Yes* | Form inputs missing associated labels |
missing-button-type |
Warning | β Yes | Buttons missing type attribute |
duplicate-id |
Error | β No | Duplicate ID attributes found |
missing-lang-attribute |
Error | β Yes | HTML element missing lang attribute |
missing-heading-hierarchy |
Warning | β No | Incorrect heading hierarchy |
missing-landmark |
Info | β No | Missing ARIA landmarks |
invalid-role |
Error | β No | Invalid ARIA role values |
invalid-aria-attribute |
Error | β No | Invalid ARIA attributes |
* New in v1.0.1 - Configurable auto-fix (can be disabled in config)
π See USAGE_GUIDE.md for configuration options
Create a .a11yrc.json file in your project root:
{
"fix": true,
"report": true,
"reportPath": "a11y-report.html",
"ignore": [
"**/node_modules/**",
"**/dist/**",
"**/build/**"
],
"performance": {
"cache": true,
"parallel": true,
"maxConcurrency": 10
},
"autoFix": {
"generateAriaLabels": true,
"wrapInputsWithLabels": true
},
"rules": {
"missing-alt-text": {
"enabled": true,
"severity": "error"
},
"missing-aria-label": {
"enabled": true,
"severity": "warning"
}
}
}π See USAGE_GUIDE.md for complete configuration options and examples
The tool provides a color-coded console output:
π Accessibility Scan Report
============================================================
π src/components/Button.tsx
Total Issues: 2 | Fixed: 1
β ERROR [missing-button-type] Line 15:10
Button missing type attribute
π‘ Auto-fix available: Add type="button" to button
β οΈ WARNING [missing-aria-label] Line 23:5
Interactive element missing aria-label or accessible text
Generate a beautiful HTML report with:
a11y-fix "**/*.html" --reportThe HTML report includes:
- Summary statistics
- Detailed issue breakdown per file
- Code snippets showing issues
- Auto-fix suggestions
- Color-coded severity indicators
a11y-fix "**/*.html" --fixa11y-fix "src/**/*.jsx" "src/**/*.tsx" --report --output reports/a11y.htmlAdd to your package.json:
{
"scripts": {
"a11y:check": "a11y-fix \"src/**/*.{html,jsx,tsx}\"",
"a11y:fix": "a11y-fix \"src/**/*.{html,jsx,tsx}\" --fix",
"a11y:report": "a11y-fix \"src/**/*.{html,jsx,tsx}\" --report"
}
}Then run:
npm run a11y:check
npm run a11y:fix
npm run a11y:reportThe following issues can be automatically fixed:
- β
Missing alt text - Adds
alt=""attribute (for decorative images) - β
Missing button type - Adds
type="button"attribute - β
Missing lang attribute - Adds
lang="en"to HTML element
Note: Some issues require manual intervention as they need context about your content (e.g., meaningful alt text for images).
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
This tool is inspired by the need for better accessibility tooling in the web development ecosystem. Special thanks to the ARIA working group and WCAG guidelines.
- π Complete Usage Guide - Comprehensive guide with examples and best practices
Made with β€οΈ for a more accessible web