eslint-plugin-tailwind-a11y 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 chamroro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # eslint-plugin-tailwind-a11y
2
+
3
+ ESLint rules that catch [WCAG](https://www.w3.org/WAI/WCAG21/quickref/) accessibility
4
+ violations in Tailwind CSS class combinations — color contrast, touch target size, and
5
+ focus indicator removal — as part of your normal `eslint` run, instead of a separate CLI
6
+ you have to remember to invoke.
7
+
8
+ This plugin is a thin ESLint adapter over the [`tailwind-a11y`](https://github.com/chamroro/tailwind-a11y/tree/main/packages/tailwind-a11y)
9
+ engine, which does the actual work: resolving Tailwind utility classes back into real
10
+ computed values (colors, sizes) via AST analysis. Every rule here calls straight into
11
+ that engine and reports its violations — there's no separate implementation to drift out
12
+ of sync, and no wording that differs between `npx tailwind-a11y` and `eslint .`.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install --save-dev eslint-plugin-tailwind-a11y
18
+ ```
19
+
20
+ Requires ESLint 9 or 10 (flat config).
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ // eslint.config.js
26
+ import tailwindA11y from "eslint-plugin-tailwind-a11y";
27
+
28
+ export default [
29
+ ...tailwindA11y.configs.recommended,
30
+ ];
31
+ ```
32
+
33
+ `configs.recommended` scopes itself to `**/*.jsx`/`**/*.tsx` and enables all three rules
34
+ as errors. To register rules manually instead:
35
+
36
+ ```js
37
+ import tailwindA11y from "eslint-plugin-tailwind-a11y";
38
+
39
+ export default [
40
+ {
41
+ files: ["**/*.jsx", "**/*.tsx"],
42
+ plugins: { "tailwind-a11y": tailwindA11y },
43
+ rules: {
44
+ "tailwind-a11y/contrast": "error",
45
+ "tailwind-a11y/touch-target": "warn",
46
+ "tailwind-a11y/focus-indicator": "error",
47
+ },
48
+ },
49
+ ];
50
+ ```
51
+
52
+ ## Rules
53
+
54
+ | Rule | WCAG | Catches |
55
+ |---|---|---|
56
+ | `tailwind-a11y/contrast` | 1.4.3 (AA) | `text-*`/`bg-*` pairs below the 4.5:1 contrast ratio, same-element or direct-parent |
57
+ | `tailwind-a11y/touch-target` | 2.5.8 (AA) | Interactive elements sized under 24×24px via `w-*`/`h-*` |
58
+ | `tailwind-a11y/focus-indicator` | 2.4.7 (AA) | `focus:outline-none` with no visible replacement style |
59
+
60
+ Each rule's exact scope and known limitations are documented in the
61
+ [engine's README](https://github.com/chamroro/tailwind-a11y/tree/main/packages/tailwind-a11y#what-it-deliberately-doesnt-catch-v1-scope) —
62
+ this plugin doesn't change what's checked, only how it's surfaced.
63
+
64
+ ## `.tsx` files and parsers
65
+
66
+ The underlying engine parses each file's source independently with Babel (`jsx` +
67
+ `typescript` plugins), so `.tsx` syntax is understood regardless of what parser your
68
+ ESLint config uses. But ESLint itself still needs to parse the file *first* to run any
69
+ rule at all — if your config doesn't already set a TypeScript-aware
70
+ `languageOptions.parser` (e.g. `typescript-eslint`) for `.tsx` files, ESLint will fail to
71
+ parse them before this plugin ever runs. If you already lint `.tsx` files today, you have
72
+ this covered; nothing extra to add for this plugin specifically.
73
+
74
+ ## Relationship to the `tailwind-a11y` CLI
75
+
76
+ Same checks, same engine, two ways to run them: `eslint-plugin-tailwind-a11y` for
77
+ inline, per-file feedback during normal linting; [`tailwind-a11y`](https://github.com/chamroro/tailwind-a11y/tree/main/packages/tailwind-a11y)
78
+ (the CLI) for a one-shot scan, e.g. in a CI step that doesn't otherwise run ESLint. Use
79
+ either, or both — they'll never disagree, since the plugin doesn't reimplement anything.
80
+
81
+ ## Development
82
+
83
+ This package lives in the [`tailwind-a11y` monorepo](https://github.com/chamroro/tailwind-a11y)
84
+ (npm workspaces) alongside the engine it depends on:
85
+
86
+ ```bash
87
+ npm install # from the monorepo root
88
+ npm run build --workspaces # or: npm run build -w tailwind-a11y -w eslint-plugin-tailwind-a11y
89
+ npm test --workspaces --if-present
90
+ ```
91
+
92
+ After changing the engine (`packages/tailwind-a11y`), rebuild it before running this
93
+ package's tests — the workspace dependency resolves through its `dist/`, not its `src/`.
94
+
95
+ ## License
96
+
97
+ MIT
@@ -0,0 +1,3 @@
1
+ import type { ESLint } from "eslint";
2
+ declare const plugin: ESLint.Plugin;
3
+ export default plugin;
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { createRequire } from "node:module";
2
+ import contrast from "./rules/contrast.js";
3
+ import touchTarget from "./rules/touch-target.js";
4
+ import focusIndicator from "./rules/focus-indicator.js";
5
+ // `../package.json` resolves correctly from both `src/` (dev) and `dist/`
6
+ // (published), so the plugin version can't drift from the package version.
7
+ const require = createRequire(import.meta.url);
8
+ const { version } = require("../package.json");
9
+ const plugin = {
10
+ meta: {
11
+ name: "eslint-plugin-tailwind-a11y",
12
+ version,
13
+ namespace: "tailwind-a11y",
14
+ },
15
+ rules: {
16
+ contrast,
17
+ "touch-target": touchTarget,
18
+ "focus-indicator": focusIndicator,
19
+ },
20
+ configs: {},
21
+ };
22
+ // Assigned after `plugin` exists so the config can reference the plugin
23
+ // itself. Scoped to jsx/tsx to match cli.ts's default glob, and to avoid
24
+ // the engine's unparsable-file console warning firing as confusing noise
25
+ // inside an unrelated linter run.
26
+ Object.assign(plugin.configs, {
27
+ recommended: [
28
+ {
29
+ name: "tailwind-a11y/recommended",
30
+ files: ["**/*.jsx", "**/*.tsx"],
31
+ // Espree (ESLint's default parser) doesn't parse JSX unless told to —
32
+ // without this, ESLint fails to parse .jsx files at all before any
33
+ // rule here runs. Doesn't cover TypeScript syntax in .tsx files; see
34
+ // README for the TS-parser caveat.
35
+ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
36
+ plugins: { "tailwind-a11y": plugin },
37
+ rules: {
38
+ "tailwind-a11y/contrast": "error",
39
+ "tailwind-a11y/touch-target": "error",
40
+ "tailwind-a11y/focus-indicator": "error",
41
+ },
42
+ },
43
+ ],
44
+ });
45
+ export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "eslint";
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,39 @@
1
+ import { extractChecks, checkContrast } from "tailwind-a11y";
2
+ const rule = {
3
+ meta: {
4
+ type: "problem",
5
+ docs: {
6
+ description: "Enforce WCAG 1.4.3 AA color contrast between Tailwind text-* and bg-* classes",
7
+ recommended: true,
8
+ url: "https://github.com/chamroro/tailwind-a11y/tree/main/packages/eslint-plugin-tailwind-a11y#contrast",
9
+ },
10
+ schema: [],
11
+ messages: {
12
+ contrast: "{{textClass}} on {{bgClass}} — ratio {{ratio}}, needs {{required}} ({{level}})",
13
+ },
14
+ },
15
+ create(context) {
16
+ return {
17
+ // Runs once per file — the engine does its own independent Babel
18
+ // parse of the raw source, so this never participates in ESLint's
19
+ // own AST traversal.
20
+ Program() {
21
+ const violations = checkContrast(extractChecks(context.sourceCode.getText(), context.filename));
22
+ for (const v of violations) {
23
+ context.report({
24
+ loc: { line: v.line, column: 0 },
25
+ messageId: "contrast",
26
+ data: {
27
+ textClass: v.textClass,
28
+ bgClass: v.bgClass,
29
+ ratio: v.ratio.toFixed(2),
30
+ required: v.required,
31
+ level: v.level,
32
+ },
33
+ });
34
+ }
35
+ },
36
+ };
37
+ },
38
+ };
39
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "eslint";
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,30 @@
1
+ import { extractFocusIndicatorChecks, checkFocusIndicators } from "tailwind-a11y";
2
+ const rule = {
3
+ meta: {
4
+ type: "problem",
5
+ docs: {
6
+ description: "Enforce WCAG 2.4.7 AA visible focus indicators — flag focus:outline-none with no visible replacement",
7
+ recommended: true,
8
+ url: "https://github.com/chamroro/tailwind-a11y/tree/main/packages/eslint-plugin-tailwind-a11y#focus-indicator",
9
+ },
10
+ schema: [],
11
+ messages: {
12
+ focusIndicator: "<{{tagName}}> removes the focus outline ({{removalClass}}) with no visible replacement (focus:ring-*/border-*/shadow-*/bg-*/outline-*)",
13
+ },
14
+ },
15
+ create(context) {
16
+ return {
17
+ Program() {
18
+ const violations = checkFocusIndicators(extractFocusIndicatorChecks(context.sourceCode.getText(), context.filename));
19
+ for (const v of violations) {
20
+ context.report({
21
+ loc: { line: v.line, column: 0 },
22
+ messageId: "focusIndicator",
23
+ data: { tagName: v.tagName, removalClass: v.removalClass },
24
+ });
25
+ }
26
+ },
27
+ };
28
+ },
29
+ };
30
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "eslint";
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,36 @@
1
+ import { extractTouchTargetChecks, checkTouchTargets } from "tailwind-a11y";
2
+ const rule = {
3
+ meta: {
4
+ type: "problem",
5
+ docs: {
6
+ description: "Enforce WCAG 2.5.8 AA minimum 24x24px touch targets on interactive elements sized with Tailwind w-*/h-* classes",
7
+ recommended: true,
8
+ url: "https://github.com/chamroro/tailwind-a11y/tree/main/packages/eslint-plugin-tailwind-a11y#touch-target",
9
+ },
10
+ schema: [],
11
+ messages: {
12
+ touchTarget: "<{{tagName}}> is {{widthPx}}×{{heightPx}}px ({{widthClass}} {{heightClass}}) — WCAG 2.5.8 requires >= 24×24px",
13
+ },
14
+ },
15
+ create(context) {
16
+ return {
17
+ Program() {
18
+ const violations = checkTouchTargets(extractTouchTargetChecks(context.sourceCode.getText(), context.filename));
19
+ for (const v of violations) {
20
+ context.report({
21
+ loc: { line: v.line, column: 0 },
22
+ messageId: "touchTarget",
23
+ data: {
24
+ tagName: v.tagName,
25
+ widthPx: v.widthPx,
26
+ heightPx: v.heightPx,
27
+ widthClass: v.widthClass,
28
+ heightClass: v.heightClass,
29
+ },
30
+ });
31
+ }
32
+ },
33
+ };
34
+ },
35
+ };
36
+ export default rule;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "eslint-plugin-tailwind-a11y",
3
+ "version": "0.1.0",
4
+ "description": "ESLint rules that catch WCAG accessibility violations — color contrast, touch target size, and focus indicator removal — in Tailwind CSS class combinations.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": ["dist"],
16
+ "engines": {
17
+ "node": "^20.19.0 || ^22.13.0 || >=24"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "prepublishOnly": "npm run build && npm test"
24
+ },
25
+ "keywords": [
26
+ "eslint",
27
+ "eslintplugin",
28
+ "eslint-plugin",
29
+ "tailwindcss",
30
+ "accessibility",
31
+ "a11y",
32
+ "wcag",
33
+ "wcag22",
34
+ "contrast",
35
+ "touch-target",
36
+ "focus-visible"
37
+ ],
38
+ "author": "chamroro",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/chamroro/tailwind-a11y.git",
43
+ "directory": "packages/eslint-plugin-tailwind-a11y"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/chamroro/tailwind-a11y/issues"
47
+ },
48
+ "homepage": "https://github.com/chamroro/tailwind-a11y/tree/main/packages/eslint-plugin-tailwind-a11y#readme",
49
+ "dependencies": {
50
+ "tailwind-a11y": "^0.1.0"
51
+ },
52
+ "peerDependencies": {
53
+ "eslint": "^9.0.0 || ^10.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^22.0.0",
57
+ "eslint": "^10.8.0",
58
+ "typescript": "^5.5.0",
59
+ "vitest": "^2.1.0"
60
+ }
61
+ }