@terra-symposium/hygiene 0.0.0-stage → 2.4.5
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/README.md +70 -2
- package/dist/accessibility.d.ts +39 -0
- package/dist/accessibility.d.ts.map +1 -0
- package/dist/accessibility.js +524 -0
- package/dist/accessibility.js.map +1 -0
- package/dist/app/workspace-test-runner.d.ts +6 -0
- package/dist/app/workspace-test-runner.d.ts.map +1 -0
- package/dist/app/workspace-test-runner.js +39 -0
- package/dist/app/workspace-test-runner.js.map +1 -0
- package/dist/capabilities/core/analysis.d.ts +22 -0
- package/dist/capabilities/core/analysis.d.ts.map +1 -0
- package/dist/capabilities/core/analysis.js +44 -0
- package/dist/capabilities/core/analysis.js.map +1 -0
- package/dist/capabilities/core/cli.d.ts +19 -0
- package/dist/capabilities/core/cli.d.ts.map +1 -0
- package/dist/capabilities/core/cli.js +58 -0
- package/dist/capabilities/core/cli.js.map +1 -0
- package/dist/capabilities/core/config.d.ts +49 -0
- package/dist/capabilities/core/config.d.ts.map +1 -0
- package/dist/capabilities/core/config.js +88 -0
- package/dist/capabilities/core/config.js.map +1 -0
- package/dist/capabilities/core/index.d.ts +11 -0
- package/dist/capabilities/core/index.d.ts.map +1 -0
- package/dist/capabilities/core/index.js +11 -0
- package/dist/capabilities/core/index.js.map +1 -0
- package/dist/capabilities/core/lib/files.d.ts +55 -0
- package/dist/capabilities/core/lib/files.d.ts.map +1 -0
- package/dist/capabilities/core/lib/files.js +287 -0
- package/dist/capabilities/core/lib/files.js.map +1 -0
- package/dist/capabilities/core/lib/progress.d.ts +25 -0
- package/dist/capabilities/core/lib/progress.d.ts.map +1 -0
- package/dist/capabilities/core/lib/progress.js +40 -0
- package/dist/capabilities/core/lib/progress.js.map +1 -0
- package/dist/capabilities/core/lib/source-kind.d.ts +14 -0
- package/dist/capabilities/core/lib/source-kind.d.ts.map +1 -0
- package/dist/capabilities/core/lib/source-kind.js +29 -0
- package/dist/capabilities/core/lib/source-kind.js.map +1 -0
- package/dist/capabilities/core/types.d.ts +156 -0
- package/dist/capabilities/core/types.d.ts.map +1 -0
- package/dist/capabilities/core/types.js +35 -0
- package/dist/capabilities/core/types.js.map +1 -0
- package/dist/capabilities/documentation/cli.d.ts +3 -0
- package/dist/capabilities/documentation/cli.d.ts.map +1 -0
- package/dist/capabilities/documentation/cli.js +14 -0
- package/dist/capabilities/documentation/cli.js.map +1 -0
- package/dist/capabilities/documentation/index.d.ts +5 -0
- package/dist/capabilities/documentation/index.d.ts.map +1 -0
- package/dist/capabilities/documentation/index.js +5 -0
- package/dist/capabilities/documentation/index.js.map +1 -0
- package/dist/capabilities/documentation/lib/documentation.d.ts +108 -0
- package/dist/capabilities/documentation/lib/documentation.d.ts.map +1 -0
- package/dist/capabilities/documentation/lib/documentation.js +1007 -0
- package/dist/capabilities/documentation/lib/documentation.js.map +1 -0
- package/dist/capabilities/formatting/cli.d.ts +3 -0
- package/dist/capabilities/formatting/cli.d.ts.map +1 -0
- package/dist/capabilities/formatting/cli.js +15 -0
- package/dist/capabilities/formatting/cli.js.map +1 -0
- package/dist/capabilities/formatting/index.d.ts +8 -0
- package/dist/capabilities/formatting/index.d.ts.map +1 -0
- package/dist/capabilities/formatting/index.js +8 -0
- package/dist/capabilities/formatting/index.js.map +1 -0
- package/dist/capabilities/formatting/lib/collapse.d.ts +13 -0
- package/dist/capabilities/formatting/lib/collapse.d.ts.map +1 -0
- package/dist/capabilities/formatting/lib/collapse.js +179 -0
- package/dist/capabilities/formatting/lib/collapse.js.map +1 -0
- package/dist/capabilities/formatting/lib/inline-if.d.ts +13 -0
- package/dist/capabilities/formatting/lib/inline-if.d.ts.map +1 -0
- package/dist/capabilities/formatting/lib/inline-if.js +49 -0
- package/dist/capabilities/formatting/lib/inline-if.js.map +1 -0
- package/dist/capabilities/formatting/lib/run-formatting.d.ts +14 -0
- package/dist/capabilities/formatting/lib/run-formatting.d.ts.map +1 -0
- package/dist/capabilities/formatting/lib/run-formatting.js +134 -0
- package/dist/capabilities/formatting/lib/run-formatting.js.map +1 -0
- package/dist/capabilities/imports/cli.d.ts +3 -0
- package/dist/capabilities/imports/cli.d.ts.map +1 -0
- package/dist/capabilities/imports/cli.js +9 -0
- package/dist/capabilities/imports/cli.js.map +1 -0
- package/dist/capabilities/imports/index.d.ts +6 -0
- package/dist/capabilities/imports/index.d.ts.map +1 -0
- package/dist/capabilities/imports/index.js +6 -0
- package/dist/capabilities/imports/index.js.map +1 -0
- package/dist/capabilities/imports/lib/imports.d.ts +19 -0
- package/dist/capabilities/imports/lib/imports.d.ts.map +1 -0
- package/dist/capabilities/imports/lib/imports.js +88 -0
- package/dist/capabilities/imports/lib/imports.js.map +1 -0
- package/dist/capabilities/languages/cli.d.ts +3 -0
- package/dist/capabilities/languages/cli.d.ts.map +1 -0
- package/dist/capabilities/languages/cli.js +9 -0
- package/dist/capabilities/languages/cli.js.map +1 -0
- package/dist/capabilities/languages/index.d.ts +6 -0
- package/dist/capabilities/languages/index.d.ts.map +1 -0
- package/dist/capabilities/languages/index.js +6 -0
- package/dist/capabilities/languages/index.js.map +1 -0
- package/dist/capabilities/languages/lib/language-profiles.d.ts +110 -0
- package/dist/capabilities/languages/lib/language-profiles.d.ts.map +1 -0
- package/dist/capabilities/languages/lib/language-profiles.js +509 -0
- package/dist/capabilities/languages/lib/language-profiles.js.map +1 -0
- package/dist/capabilities/languages/lib/run-language-checks.d.ts +12 -0
- package/dist/capabilities/languages/lib/run-language-checks.d.ts.map +1 -0
- package/dist/capabilities/languages/lib/run-language-checks.js +109 -0
- package/dist/capabilities/languages/lib/run-language-checks.js.map +1 -0
- package/dist/capabilities/naming/cli.d.ts +3 -0
- package/dist/capabilities/naming/cli.d.ts.map +1 -0
- package/dist/capabilities/naming/cli.js +15 -0
- package/dist/capabilities/naming/cli.js.map +1 -0
- package/dist/capabilities/naming/index.d.ts +5 -0
- package/dist/capabilities/naming/index.d.ts.map +1 -0
- package/dist/capabilities/naming/index.js +5 -0
- package/dist/capabilities/naming/index.js.map +1 -0
- package/dist/capabilities/naming/lib/naming.d.ts +169 -0
- package/dist/capabilities/naming/lib/naming.d.ts.map +1 -0
- package/dist/capabilities/naming/lib/naming.js +908 -0
- package/dist/capabilities/naming/lib/naming.js.map +1 -0
- package/dist/capabilities/patterns/cli.d.ts +3 -0
- package/dist/capabilities/patterns/cli.d.ts.map +1 -0
- package/dist/capabilities/patterns/cli.js +30 -0
- package/dist/capabilities/patterns/cli.js.map +1 -0
- package/dist/capabilities/patterns/index.d.ts +5 -0
- package/dist/capabilities/patterns/index.d.ts.map +1 -0
- package/dist/capabilities/patterns/index.js +5 -0
- package/dist/capabilities/patterns/index.js.map +1 -0
- package/dist/capabilities/patterns/lib/patterns.d.ts +102 -0
- package/dist/capabilities/patterns/lib/patterns.d.ts.map +1 -0
- package/dist/capabilities/patterns/lib/patterns.js +1584 -0
- package/dist/capabilities/patterns/lib/patterns.js.map +1 -0
- package/dist/capabilities/refactoring/cli.d.ts +3 -0
- package/dist/capabilities/refactoring/cli.d.ts.map +1 -0
- package/dist/capabilities/refactoring/cli.js +15 -0
- package/dist/capabilities/refactoring/cli.js.map +1 -0
- package/dist/capabilities/refactoring/index.d.ts +6 -0
- package/dist/capabilities/refactoring/index.d.ts.map +1 -0
- package/dist/capabilities/refactoring/index.js +6 -0
- package/dist/capabilities/refactoring/index.js.map +1 -0
- package/dist/capabilities/refactoring/lib/object-forwarding.d.ts +42 -0
- package/dist/capabilities/refactoring/lib/object-forwarding.d.ts.map +1 -0
- package/dist/capabilities/refactoring/lib/object-forwarding.js +166 -0
- package/dist/capabilities/refactoring/lib/object-forwarding.js.map +1 -0
- package/dist/capabilities/refactoring/lib/single-use.d.ts +61 -0
- package/dist/capabilities/refactoring/lib/single-use.d.ts.map +1 -0
- package/dist/capabilities/refactoring/lib/single-use.js +1791 -0
- package/dist/capabilities/refactoring/lib/single-use.js.map +1 -0
- package/dist/capabilities/reports/cli.d.ts +3 -0
- package/dist/capabilities/reports/cli.d.ts.map +1 -0
- package/dist/capabilities/reports/cli.js +34 -0
- package/dist/capabilities/reports/cli.js.map +1 -0
- package/dist/capabilities/reports/index.d.ts +10 -0
- package/dist/capabilities/reports/index.d.ts.map +1 -0
- package/dist/capabilities/reports/index.js +10 -0
- package/dist/capabilities/reports/index.js.map +1 -0
- package/dist/capabilities/reports/lib/github-report.d.ts +94 -0
- package/dist/capabilities/reports/lib/github-report.d.ts.map +1 -0
- package/dist/capabilities/reports/lib/github-report.js +499 -0
- package/dist/capabilities/reports/lib/github-report.js.map +1 -0
- package/dist/capabilities/reports/lib/history-report.d.ts +58 -0
- package/dist/capabilities/reports/lib/history-report.d.ts.map +1 -0
- package/dist/capabilities/reports/lib/history-report.js +300 -0
- package/dist/capabilities/reports/lib/history-report.js.map +1 -0
- package/dist/capabilities/reports/lib/node-reporter.d.ts +79 -0
- package/dist/capabilities/reports/lib/node-reporter.d.ts.map +1 -0
- package/dist/capabilities/reports/lib/node-reporter.js +244 -0
- package/dist/capabilities/reports/lib/node-reporter.js.map +1 -0
- package/dist/capabilities/reports/lib/playwright-reporter.d.ts +100 -0
- package/dist/capabilities/reports/lib/playwright-reporter.d.ts.map +1 -0
- package/dist/capabilities/reports/lib/playwright-reporter.js +122 -0
- package/dist/capabilities/reports/lib/playwright-reporter.js.map +1 -0
- package/dist/capabilities/security/cli.d.ts +3 -0
- package/dist/capabilities/security/cli.d.ts.map +1 -0
- package/dist/capabilities/security/cli.js +9 -0
- package/dist/capabilities/security/cli.js.map +1 -0
- package/dist/capabilities/security/index.d.ts +5 -0
- package/dist/capabilities/security/index.d.ts.map +1 -0
- package/dist/capabilities/security/index.js +5 -0
- package/dist/capabilities/security/index.js.map +1 -0
- package/dist/capabilities/security/lib/security.d.ts +19 -0
- package/dist/capabilities/security/lib/security.d.ts.map +1 -0
- package/dist/capabilities/security/lib/security.js +115 -0
- package/dist/capabilities/security/lib/security.js.map +1 -0
- package/dist/capabilities/ui/cli.d.ts +3 -0
- package/dist/capabilities/ui/cli.d.ts.map +1 -0
- package/dist/capabilities/ui/cli.js +22 -0
- package/dist/capabilities/ui/cli.js.map +1 -0
- package/dist/capabilities/ui/index.d.ts +8 -0
- package/dist/capabilities/ui/index.d.ts.map +1 -0
- package/dist/capabilities/ui/index.js +8 -0
- package/dist/capabilities/ui/index.js.map +1 -0
- package/dist/capabilities/ui/lib/accessibility.d.ts +37 -0
- package/dist/capabilities/ui/lib/accessibility.d.ts.map +1 -0
- package/dist/capabilities/ui/lib/accessibility.js +676 -0
- package/dist/capabilities/ui/lib/accessibility.js.map +1 -0
- package/dist/capabilities/ui/lib/display-name.d.ts +42 -0
- package/dist/capabilities/ui/lib/display-name.d.ts.map +1 -0
- package/dist/capabilities/ui/lib/display-name.js +277 -0
- package/dist/capabilities/ui/lib/display-name.js.map +1 -0
- package/dist/capabilities/ui/lib/error-boundaries.d.ts +30 -0
- package/dist/capabilities/ui/lib/error-boundaries.d.ts.map +1 -0
- package/dist/capabilities/ui/lib/error-boundaries.js +401 -0
- package/dist/capabilities/ui/lib/error-boundaries.js.map +1 -0
- package/dist/capabilities/ui/lib/ui-recommendations.d.ts +45 -0
- package/dist/capabilities/ui/lib/ui-recommendations.d.ts.map +1 -0
- package/dist/capabilities/ui/lib/ui-recommendations.js +183 -0
- package/dist/capabilities/ui/lib/ui-recommendations.js.map +1 -0
- package/dist/display-name.d.ts +44 -0
- package/dist/display-name.d.ts.map +1 -0
- package/dist/display-name.js +256 -0
- package/dist/display-name.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accessibility.d.ts +5 -0
- package/dist/lib/accessibility.d.ts.map +1 -0
- package/dist/lib/accessibility.js +5 -0
- package/dist/lib/accessibility.js.map +1 -0
- package/dist/lib/collapse.d.ts +5 -0
- package/dist/lib/collapse.d.ts.map +1 -0
- package/dist/lib/collapse.js +5 -0
- package/dist/lib/collapse.js.map +1 -0
- package/dist/lib/dev.d.ts +3 -0
- package/dist/lib/dev.d.ts.map +1 -0
- package/dist/lib/dev.js +126 -0
- package/dist/lib/dev.js.map +1 -0
- package/dist/lib/display-name.d.ts +5 -0
- package/dist/lib/display-name.d.ts.map +1 -0
- package/dist/lib/display-name.js +5 -0
- package/dist/lib/display-name.js.map +1 -0
- package/dist/lib/documentation.d.ts +5 -0
- package/dist/lib/documentation.d.ts.map +1 -0
- package/dist/lib/documentation.js +5 -0
- package/dist/lib/documentation.js.map +1 -0
- package/dist/lib/error-boundaries-astro.d.ts +6 -0
- package/dist/lib/error-boundaries-astro.d.ts.map +1 -0
- package/dist/lib/error-boundaries-astro.js +6 -0
- package/dist/lib/error-boundaries-astro.js.map +1 -0
- package/dist/lib/error-boundaries-react.d.ts +6 -0
- package/dist/lib/error-boundaries-react.d.ts.map +1 -0
- package/dist/lib/error-boundaries-react.js +6 -0
- package/dist/lib/error-boundaries-react.js.map +1 -0
- package/dist/lib/error-boundaries.d.ts +5 -0
- package/dist/lib/error-boundaries.d.ts.map +1 -0
- package/dist/lib/error-boundaries.js +5 -0
- package/dist/lib/error-boundaries.js.map +1 -0
- package/dist/lib/eslint-api.d.ts +13 -0
- package/dist/lib/eslint-api.d.ts.map +1 -0
- package/dist/lib/eslint-api.js +24 -0
- package/dist/lib/eslint-api.js.map +1 -0
- package/dist/lib/files.d.ts +5 -0
- package/dist/lib/files.d.ts.map +1 -0
- package/dist/lib/files.js +5 -0
- package/dist/lib/files.js.map +1 -0
- package/dist/lib/formatting.d.ts +5 -0
- package/dist/lib/formatting.d.ts.map +1 -0
- package/dist/lib/formatting.js +5 -0
- package/dist/lib/formatting.js.map +1 -0
- package/dist/lib/github-report.d.ts +5 -0
- package/dist/lib/github-report.d.ts.map +1 -0
- package/dist/lib/github-report.js +5 -0
- package/dist/lib/github-report.js.map +1 -0
- package/dist/lib/history-report.d.ts +5 -0
- package/dist/lib/history-report.d.ts.map +1 -0
- package/dist/lib/history-report.js +5 -0
- package/dist/lib/history-report.js.map +1 -0
- package/dist/lib/imports.d.ts +5 -0
- package/dist/lib/imports.d.ts.map +1 -0
- package/dist/lib/imports.js +5 -0
- package/dist/lib/imports.js.map +1 -0
- package/dist/lib/index.d.ts +20 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +20 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/inline-if.d.ts +5 -0
- package/dist/lib/inline-if.d.ts.map +1 -0
- package/dist/lib/inline-if.js +5 -0
- package/dist/lib/inline-if.js.map +1 -0
- package/dist/lib/language-checks.d.ts +5 -0
- package/dist/lib/language-checks.d.ts.map +1 -0
- package/dist/lib/language-checks.js +5 -0
- package/dist/lib/language-checks.js.map +1 -0
- package/dist/lib/language-profiles.d.ts +5 -0
- package/dist/lib/language-profiles.d.ts.map +1 -0
- package/dist/lib/language-profiles.js +5 -0
- package/dist/lib/language-profiles.js.map +1 -0
- package/dist/lib/naming.d.ts +5 -0
- package/dist/lib/naming.d.ts.map +1 -0
- package/dist/lib/naming.js +5 -0
- package/dist/lib/naming.js.map +1 -0
- package/dist/lib/node-reporter.d.ts +6 -0
- package/dist/lib/node-reporter.d.ts.map +1 -0
- package/dist/lib/node-reporter.js +6 -0
- package/dist/lib/node-reporter.js.map +1 -0
- package/dist/lib/object-forwarding.d.ts +5 -0
- package/dist/lib/object-forwarding.d.ts.map +1 -0
- package/dist/lib/object-forwarding.js +5 -0
- package/dist/lib/object-forwarding.js.map +1 -0
- package/dist/lib/patterns.d.ts +5 -0
- package/dist/lib/patterns.d.ts.map +1 -0
- package/dist/lib/patterns.js +5 -0
- package/dist/lib/patterns.js.map +1 -0
- package/dist/lib/playwright-reporter.d.ts +6 -0
- package/dist/lib/playwright-reporter.d.ts.map +1 -0
- package/dist/lib/playwright-reporter.js +6 -0
- package/dist/lib/playwright-reporter.js.map +1 -0
- package/dist/lib/port.d.ts +21 -0
- package/dist/lib/port.d.ts.map +1 -0
- package/dist/lib/port.js +81 -0
- package/dist/lib/port.js.map +1 -0
- package/dist/lib/progress.d.ts +5 -0
- package/dist/lib/progress.d.ts.map +1 -0
- package/dist/lib/progress.js +5 -0
- package/dist/lib/progress.js.map +1 -0
- package/dist/lib/reports.d.ts +5 -0
- package/dist/lib/reports.d.ts.map +1 -0
- package/dist/lib/reports.js +5 -0
- package/dist/lib/reports.js.map +1 -0
- package/dist/lib/runner.d.ts +150 -0
- package/dist/lib/runner.d.ts.map +1 -0
- package/dist/lib/runner.js +4522 -0
- package/dist/lib/runner.js.map +1 -0
- package/dist/lib/security.d.ts +5 -0
- package/dist/lib/security.d.ts.map +1 -0
- package/dist/lib/security.js +5 -0
- package/dist/lib/security.js.map +1 -0
- package/dist/lib/single-use.d.ts +6 -0
- package/dist/lib/single-use.d.ts.map +1 -0
- package/dist/lib/single-use.js +5 -0
- package/dist/lib/single-use.js.map +1 -0
- package/dist/lib/source-kind.d.ts +5 -0
- package/dist/lib/source-kind.d.ts.map +1 -0
- package/dist/lib/source-kind.js +5 -0
- package/dist/lib/source-kind.js.map +1 -0
- package/dist/lib/spinner-worker.d.ts +6 -0
- package/dist/lib/spinner-worker.d.ts.map +1 -0
- package/dist/lib/spinner-worker.js +33 -0
- package/dist/lib/spinner-worker.js.map +1 -0
- package/dist/lib/ui-quality.d.ts +5 -0
- package/dist/lib/ui-quality.d.ts.map +1 -0
- package/dist/lib/ui-quality.js +5 -0
- package/dist/lib/ui-quality.js.map +1 -0
- package/dist/lib/ui-recommendations.d.ts +5 -0
- package/dist/lib/ui-recommendations.d.ts.map +1 -0
- package/dist/lib/ui-recommendations.js +5 -0
- package/dist/lib/ui-recommendations.js.map +1 -0
- package/dist/spinner-worker.d.ts +6 -0
- package/dist/spinner-worker.d.ts.map +1 -0
- package/dist/spinner-worker.js +39 -0
- package/dist/spinner-worker.js.map +1 -0
- package/package.json +160 -5
- package/quality-configs/checkstyle.xml +29 -0
- package/quality-configs/pmd-rules.xml +11 -0
- package/quality.schema.json +392 -0
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/hygiene/src/capabilities/ui/lib/accessibility.ts
|
|
3
|
+
* Finds JSX controls without a source-evident accessible name and applies only
|
|
4
|
+
* title-to-aria-label fixes whose meaning can be copied without inference.
|
|
5
|
+
*/
|
|
6
|
+
/*//////////////////////////////////////////////////
|
|
7
|
+
IMPORTS
|
|
8
|
+
//////////////////////////////////////////////////*/
|
|
9
|
+
// API
|
|
10
|
+
import ts from 'typescript';
|
|
11
|
+
import { displayPath, srcFiles } from '@terra-symposium/hygiene/core';
|
|
12
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
13
|
+
/*//////////////////////////////////////////////////
|
|
14
|
+
REGEX
|
|
15
|
+
//////////////////////////////////////////////////*/
|
|
16
|
+
const A_Z_A_Z_D_REGEX = /^[a-z][a-z\d-]*$/;
|
|
17
|
+
/*//////////////////////////////////////////////////
|
|
18
|
+
CONSTANTS
|
|
19
|
+
//////////////////////////////////////////////////*/
|
|
20
|
+
const JSX_EXTS = /\.(?:jsx|tsx|js|ts)$/i;
|
|
21
|
+
// hygiene-ignore single-use -- Reuse the native labelable set across every inspected JSX element.
|
|
22
|
+
const NATIVE_LABELABLE = new Set(['button', 'input', 'select', 'textarea']);
|
|
23
|
+
// hygiene-ignore single-use -- Reuse the input button type set across every inspected JSX element.
|
|
24
|
+
const INPUT_BUTTON_TYPES = new Set(['button', 'submit', 'reset']);
|
|
25
|
+
// hygiene-ignore single-use -- Reuse the interactive role set across every inspected JSX element.
|
|
26
|
+
const INTERACTIVE_ROLES = new Set([
|
|
27
|
+
'button',
|
|
28
|
+
'checkbox',
|
|
29
|
+
'combobox',
|
|
30
|
+
'gridcell',
|
|
31
|
+
'link',
|
|
32
|
+
'listbox',
|
|
33
|
+
'menuitem',
|
|
34
|
+
'menuitemcheckbox',
|
|
35
|
+
'menuitemradio',
|
|
36
|
+
'option',
|
|
37
|
+
'radio',
|
|
38
|
+
'searchbox',
|
|
39
|
+
'slider',
|
|
40
|
+
'spinbutton',
|
|
41
|
+
'progressbar',
|
|
42
|
+
'switch',
|
|
43
|
+
'tab',
|
|
44
|
+
'textbox',
|
|
45
|
+
'treeitem',
|
|
46
|
+
]);
|
|
47
|
+
const INTERACTIVE_NATIVE = new Set(['button', 'input', 'select', 'textarea', 'summary']);
|
|
48
|
+
/*//////////////////////////////////////////////////
|
|
49
|
+
HELPERS
|
|
50
|
+
//////////////////////////////////////////////////*/
|
|
51
|
+
// hygiene-ignore single-use -- Keep the documented scriptKind declaration so its parameter and return contract remains attached.
|
|
52
|
+
/**
|
|
53
|
+
* Selects a TypeScript parser mode for a JSX-capable source path.
|
|
54
|
+
*
|
|
55
|
+
* @param fileName Source path whose extension selects JSX or TSX parsing.
|
|
56
|
+
*
|
|
57
|
+
* @return JSX parsing for JavaScript paths and TSX parsing for TypeScript paths.
|
|
58
|
+
*/
|
|
59
|
+
function scriptKind(fileName) {
|
|
60
|
+
if (/\.tsx?$/i.test(fileName))
|
|
61
|
+
return ts.ScriptKind.TSX;
|
|
62
|
+
return ts.ScriptKind.JSX;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns JSX attributes from either an element or self-closing element.
|
|
66
|
+
*
|
|
67
|
+
* @param el JSX element or self-closing element whose attributes are requested.
|
|
68
|
+
*
|
|
69
|
+
* @return The JSX attribute collection attached to the element.
|
|
70
|
+
*/
|
|
71
|
+
function attrsOf(el) {
|
|
72
|
+
return ts.isJsxElement(el) ? el.openingElement.attributes : el.attributes;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns JSX child nodes from either an element or self-closing element.
|
|
76
|
+
*
|
|
77
|
+
* @param el JSX element or self-closing element whose children are requested.
|
|
78
|
+
*
|
|
79
|
+
* @return Child nodes, or an empty array for a self-closing element.
|
|
80
|
+
*/
|
|
81
|
+
function childrenOf(el) {
|
|
82
|
+
return ts.isJsxElement(el) ? el.children : [];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns the JSX tag name as written in source.
|
|
86
|
+
*
|
|
87
|
+
* @param el JSX element or self-closing element whose tag should be read.
|
|
88
|
+
*
|
|
89
|
+
* @return Tag name as written in the source file.
|
|
90
|
+
*/
|
|
91
|
+
function tagOf(el) {
|
|
92
|
+
return ts.isJsxElement(el) ? el.openingElement.tagName.getText() : el.tagName.getText();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Finds a named JSX attribute without interpreting spreads.
|
|
96
|
+
*
|
|
97
|
+
* @param el JSX element whose attributes are searched.
|
|
98
|
+
* @param name Attribute identifier to match exactly.
|
|
99
|
+
*
|
|
100
|
+
* @return Matching JSX attribute, or `undefined` when absent.
|
|
101
|
+
*/
|
|
102
|
+
function attrOf(el, name) {
|
|
103
|
+
return attrsOf(el).properties.find((p) => ts.isJsxAttribute(p) && ts.isIdentifier(p.name) && p.name.text === name);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Reads a statically available string-like JSX attribute and preserves its expression source for safe copying.
|
|
107
|
+
*
|
|
108
|
+
* @param attr JSX attribute whose literal or expression value is inspected.
|
|
109
|
+
*
|
|
110
|
+
* @return Static value with source text when safe to copy, or an empty/unknown state.
|
|
111
|
+
*/
|
|
112
|
+
function staticAttr(attr) {
|
|
113
|
+
if (!attr?.initializer)
|
|
114
|
+
return { state: 'empty' };
|
|
115
|
+
if (ts.isStringLiteral(attr.initializer)) {
|
|
116
|
+
const value = attr.initializer.text;
|
|
117
|
+
return meaningful(value) ? { state: 'static', value, source: attr.initializer.getText() } : { state: 'empty' };
|
|
118
|
+
}
|
|
119
|
+
if (!ts.isJsxExpression(attr.initializer) || !attr.initializer.expression)
|
|
120
|
+
return { state: 'unknown' };
|
|
121
|
+
const expr = attr.initializer.expression;
|
|
122
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr) || ts.isNumericLiteral(expr)) {
|
|
123
|
+
const value = expr.text;
|
|
124
|
+
return meaningful(value) ? { state: 'static', value, source: attr.initializer.getText() } : { state: 'empty' };
|
|
125
|
+
}
|
|
126
|
+
if (expr.kind === ts.SyntaxKind.TrueKeyword)
|
|
127
|
+
return { state: 'static', value: 'true', source: attr.initializer.getText() };
|
|
128
|
+
if (expr.kind === ts.SyntaxKind.FalseKeyword || expr.kind === ts.SyntaxKind.NullKeyword)
|
|
129
|
+
return { state: 'empty' };
|
|
130
|
+
return { state: 'unknown' };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reads a title only when its source is a string literal or a template literal without substitutions.
|
|
134
|
+
*
|
|
135
|
+
* @param attr `title` attribute whose value is tested for a literal string.
|
|
136
|
+
*
|
|
137
|
+
* @return Literal title with copyable source text, or an empty/unknown state.
|
|
138
|
+
*/
|
|
139
|
+
function literalTitle(attr) {
|
|
140
|
+
if (!attr?.initializer)
|
|
141
|
+
return { state: 'empty' };
|
|
142
|
+
if (ts.isStringLiteral(attr.initializer)) {
|
|
143
|
+
const value = attr.initializer.text;
|
|
144
|
+
return meaningful(value) ? { state: 'static', value, source: attr.initializer.getText() } : { state: 'empty' };
|
|
145
|
+
}
|
|
146
|
+
if (!ts.isJsxExpression(attr.initializer) || !attr.initializer.expression)
|
|
147
|
+
return { state: 'unknown' };
|
|
148
|
+
const expr = attr.initializer.expression;
|
|
149
|
+
if (!ts.isStringLiteral(expr) && !ts.isNoSubstitutionTemplateLiteral(expr))
|
|
150
|
+
return { state: 'unknown' };
|
|
151
|
+
return meaningful(expr.text) ? { state: 'static', value: expr.text, source: attr.initializer.getText() } : { state: 'empty' };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Checks for meaningful text after trimming whitespace and zero-width padding.
|
|
155
|
+
*
|
|
156
|
+
* @param value Text to check for visible content after whitespace normalization.
|
|
157
|
+
*
|
|
158
|
+
* @return Whether at least one non-whitespace, non-zero-width character remains.
|
|
159
|
+
*/
|
|
160
|
+
function meaningful(value) {
|
|
161
|
+
return value.replace(/[\s\u00a0\u200b\ufeff]/g, '').replace(/&(?:nbsp|#0*160|#x0*a0);/gi, '').length > 0;
|
|
162
|
+
}
|
|
163
|
+
// hygiene-ignore single-use -- Keep the documented hiddenAttrState declaration so its parameter and return contract remains attached.
|
|
164
|
+
/**
|
|
165
|
+
* Returns whether the HTML hidden attribute is present, false, or uncertain.
|
|
166
|
+
*
|
|
167
|
+
* @param el JSX element whose `hidden` attribute is evaluated.
|
|
168
|
+
*
|
|
169
|
+
* @return `named` when hidden, `empty` when explicitly visible or absent, otherwise `unknown`.
|
|
170
|
+
*/
|
|
171
|
+
function hiddenAttrState(el) {
|
|
172
|
+
const attr = attrOf(el, 'hidden');
|
|
173
|
+
if (!attr)
|
|
174
|
+
return 'empty';
|
|
175
|
+
if (!attr.initializer)
|
|
176
|
+
return 'named';
|
|
177
|
+
if (ts.isStringLiteral(attr.initializer))
|
|
178
|
+
return 'named';
|
|
179
|
+
if (!ts.isJsxExpression(attr.initializer) || !attr.initializer.expression)
|
|
180
|
+
return 'unknown';
|
|
181
|
+
const expr = attr.initializer.expression;
|
|
182
|
+
if (expr.kind === ts.SyntaxKind.TrueKeyword)
|
|
183
|
+
return 'named';
|
|
184
|
+
if (expr.kind === ts.SyntaxKind.FalseKeyword || expr.kind === ts.SyntaxKind.NullKeyword)
|
|
185
|
+
return 'empty';
|
|
186
|
+
if (ts.isNumericLiteral(expr))
|
|
187
|
+
return Number(expr.text) === 0 ? 'empty' : 'named';
|
|
188
|
+
return 'unknown';
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Determines whether an element or an ancestor is hidden from the accessibility tree.
|
|
192
|
+
*
|
|
193
|
+
* @param el JSX element whose hidden and `aria-hidden` states are combined.
|
|
194
|
+
*
|
|
195
|
+
* @return `named` when hidden from the accessibility tree, `empty` when visible, otherwise `unknown`.
|
|
196
|
+
*/
|
|
197
|
+
function hiddenState(el) {
|
|
198
|
+
const hidden = hiddenAttrState(el);
|
|
199
|
+
const ariaHiddenAttr = attrOf(el, 'aria-hidden');
|
|
200
|
+
const ariaHidden = ariaHiddenAttr && !ariaHiddenAttr.initializer ? { state: 'static', value: 'true', source: 'true' } : staticAttr(ariaHiddenAttr);
|
|
201
|
+
if (hidden === 'named' || (ariaHidden.state === 'static' && ariaHidden.value.toLowerCase() === 'true'))
|
|
202
|
+
return 'named';
|
|
203
|
+
if (hidden === 'unknown' || ariaHidden.state === 'unknown')
|
|
204
|
+
return 'unknown';
|
|
205
|
+
return 'empty';
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads the static value of an input type, using HTML's default text type.
|
|
209
|
+
*
|
|
210
|
+
* @param el Input element whose `type` attribute is read.
|
|
211
|
+
*
|
|
212
|
+
* @return Static input type, with HTML's default `text` type when no attribute exists.
|
|
213
|
+
*/
|
|
214
|
+
function inputType(el) {
|
|
215
|
+
const type = attrOf(el, 'type');
|
|
216
|
+
return type ? staticAttr(type) : { state: 'static', value: 'text', source: '"text"' };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Combines child text evidence; a definite name takes precedence over uncertain extra children.
|
|
220
|
+
*
|
|
221
|
+
* @param states Child-name evidence values to combine.
|
|
222
|
+
*
|
|
223
|
+
* @return `named` if any child names the element, else `unknown` if evidence is uncertain, else `empty`.
|
|
224
|
+
*/
|
|
225
|
+
function combine(states) {
|
|
226
|
+
if (states.includes('named'))
|
|
227
|
+
return 'named';
|
|
228
|
+
if (states.includes('unknown'))
|
|
229
|
+
return 'unknown';
|
|
230
|
+
return 'empty';
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Determines whether a JSX element has static text or image alternative text in its children.
|
|
234
|
+
*
|
|
235
|
+
* @param el JSX element whose child nodes are inspected.
|
|
236
|
+
* @param forLabel Whether interactive descendants are being interpreted inside a label.
|
|
237
|
+
*
|
|
238
|
+
* @return Combined name evidence from the element's children.
|
|
239
|
+
*/
|
|
240
|
+
function contentState(el, forLabel = false) {
|
|
241
|
+
const children = childrenOf(el);
|
|
242
|
+
if (!children.length)
|
|
243
|
+
return 'empty';
|
|
244
|
+
return combine(children.map(c => childContentState(c, forLabel)));
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Examines one JSX child for visible static text without guessing about component output.
|
|
248
|
+
*
|
|
249
|
+
* @param child JSX child node to inspect.
|
|
250
|
+
* @param forLabel Whether interactive descendants are being interpreted inside a label.
|
|
251
|
+
*
|
|
252
|
+
* @return Evidence that the child provides static accessible-name text.
|
|
253
|
+
*/
|
|
254
|
+
function childContentState(child, forLabel) {
|
|
255
|
+
if (ts.isJsxText(child))
|
|
256
|
+
return meaningful(child.text) ? 'named' : 'empty';
|
|
257
|
+
if (ts.isJsxExpression(child)) {
|
|
258
|
+
const expr = child.expression;
|
|
259
|
+
if (!expr)
|
|
260
|
+
return 'empty';
|
|
261
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr) || ts.isNumericLiteral(expr))
|
|
262
|
+
return meaningful(expr.text) ? 'named' : 'empty';
|
|
263
|
+
if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword || expr.kind === ts.SyntaxKind.NullKeyword)
|
|
264
|
+
return 'empty';
|
|
265
|
+
return 'unknown';
|
|
266
|
+
}
|
|
267
|
+
if (ts.isJsxElement(child))
|
|
268
|
+
return elContentState(child, forLabel);
|
|
269
|
+
if (ts.isJsxSelfClosingElement(child))
|
|
270
|
+
return elContentState(child, forLabel);
|
|
271
|
+
if (ts.isJsxFragment(child))
|
|
272
|
+
return combine(child.children.map(n => childContentState(n, forLabel)));
|
|
273
|
+
return 'unknown';
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Examines a nested element, honoring hidden content, image alt, SVG names, and custom components.
|
|
277
|
+
*
|
|
278
|
+
* @param el Nested JSX element to inspect.
|
|
279
|
+
* @param forLabel Whether interactive descendants are being interpreted inside a label.
|
|
280
|
+
*
|
|
281
|
+
* @return Name evidence after hidden, image, SVG, native-control, and component checks.
|
|
282
|
+
*/
|
|
283
|
+
function elContentState(el, forLabel) {
|
|
284
|
+
const hidden = hiddenState(el);
|
|
285
|
+
if (hidden === 'named')
|
|
286
|
+
return 'empty';
|
|
287
|
+
if (hidden === 'unknown')
|
|
288
|
+
return 'unknown';
|
|
289
|
+
const tag = tagOf(el);
|
|
290
|
+
if (tag === 'img') {
|
|
291
|
+
const alt = staticAttr(attrOf(el, 'alt'));
|
|
292
|
+
return alt.state === 'static' ? 'named' : alt.state === 'unknown' ? 'unknown' : 'empty';
|
|
293
|
+
}
|
|
294
|
+
if (!A_Z_A_Z_D_REGEX.test(tag))
|
|
295
|
+
return 'unknown';
|
|
296
|
+
if (INTERACTIVE_NATIVE.has(tag))
|
|
297
|
+
return forLabel ? 'empty' : 'unknown';
|
|
298
|
+
if (tag === 'svg') {
|
|
299
|
+
const label = staticAttr(attrOf(el, 'aria-label'));
|
|
300
|
+
if (label.state === 'static')
|
|
301
|
+
return 'named';
|
|
302
|
+
if (label.state === 'unknown')
|
|
303
|
+
return 'unknown';
|
|
304
|
+
const title = literalTitle(attrOf(el, 'title'));
|
|
305
|
+
if (title.state === 'static')
|
|
306
|
+
return 'named';
|
|
307
|
+
if (title.state === 'unknown')
|
|
308
|
+
return 'unknown';
|
|
309
|
+
}
|
|
310
|
+
return contentState(el, forLabel);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Determines whether a source element supplies a usable name through ARIA attributes.
|
|
314
|
+
*
|
|
315
|
+
* @param el JSX element whose `aria-label` value is inspected.
|
|
316
|
+
*
|
|
317
|
+
* @return `named` for static non-empty text, `empty` when absent/empty, otherwise `unknown`.
|
|
318
|
+
*/
|
|
319
|
+
function ariaNameState(el) {
|
|
320
|
+
const label = staticAttr(attrOf(el, 'aria-label'));
|
|
321
|
+
if (label.state !== 'empty')
|
|
322
|
+
return label.state === 'static' ? 'named' : 'unknown';
|
|
323
|
+
return 'empty';
|
|
324
|
+
}
|
|
325
|
+
// hygiene-ignore single-use -- Keep the documented idContentStates declaration so its parameter and return contract remains attached.
|
|
326
|
+
/**
|
|
327
|
+
* Builds conservative source evidence for literal JSX ids and their referenced text.
|
|
328
|
+
*
|
|
329
|
+
* @param src Parsed JSX source containing controls and candidate labels.
|
|
330
|
+
*
|
|
331
|
+
* @return Map from unique literal ids to accessible-name evidence; duplicate ids are `unknown`.
|
|
332
|
+
*/
|
|
333
|
+
function idContentStates(src) {
|
|
334
|
+
const ids = new Map();
|
|
335
|
+
const duplicates = new Set();
|
|
336
|
+
const visit = (node) => {
|
|
337
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
338
|
+
const id = staticAttr(attrOf(node, 'id'));
|
|
339
|
+
if (id.state === 'static') {
|
|
340
|
+
if (ids.has(id.value))
|
|
341
|
+
duplicates.add(id.value);
|
|
342
|
+
else
|
|
343
|
+
ids.set(id.value, (function referencedContentState(el) {
|
|
344
|
+
const tag = tagOf(el);
|
|
345
|
+
if (!A_Z_A_Z_D_REGEX.test(tag) || tag.includes('-'))
|
|
346
|
+
return 'unknown';
|
|
347
|
+
const label = staticAttr(attrOf(el, 'aria-label'));
|
|
348
|
+
if (label.state === 'static')
|
|
349
|
+
return 'named';
|
|
350
|
+
if (label.state === 'unknown')
|
|
351
|
+
return 'unknown';
|
|
352
|
+
if (tag === 'img') {
|
|
353
|
+
const alt = staticAttr(attrOf(el, 'alt'));
|
|
354
|
+
return alt.state === 'static' ? 'named' : alt.state === 'unknown' ? 'unknown' : 'empty';
|
|
355
|
+
}
|
|
356
|
+
if (staticAttr(attrOf(el, 'aria-labelledby')).state !== 'empty')
|
|
357
|
+
return 'unknown';
|
|
358
|
+
return combine(childrenOf(el).map(c => childContentState(c, false)));
|
|
359
|
+
})(node));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
ts.forEachChild(node, visit);
|
|
363
|
+
};
|
|
364
|
+
visit(src);
|
|
365
|
+
for (const id of duplicates)
|
|
366
|
+
ids.set(id, 'unknown');
|
|
367
|
+
return ids;
|
|
368
|
+
}
|
|
369
|
+
// hygiene-ignore single-use -- Keep the documented associatedLabels declaration so its parameter and return contract remains attached.
|
|
370
|
+
/**
|
|
371
|
+
* Finds labels associated by a literal id and records whether each label has meaningful text.
|
|
372
|
+
*
|
|
373
|
+
* @param src Parsed JSX source containing label elements and their controls.
|
|
374
|
+
*
|
|
375
|
+
* @return Map from literal `for`/`htmlFor` targets to their label-content evidence.
|
|
376
|
+
*/
|
|
377
|
+
function associatedLabels(src) {
|
|
378
|
+
const labels = new Map();
|
|
379
|
+
const visit = (node, hidden) => {
|
|
380
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
381
|
+
const state = hiddenState(node);
|
|
382
|
+
if (!(hidden || state === 'named' || state === 'unknown') && tagOf(node) === 'label') {
|
|
383
|
+
const target = staticAttr(attrOf(node, 'htmlFor') ?? attrOf(node, 'for'));
|
|
384
|
+
if (target.state === 'static') {
|
|
385
|
+
const content = contentState(node, true);
|
|
386
|
+
const prev = labels.get(target.value);
|
|
387
|
+
labels.set(target.value, prev === 'named' || content === 'named' ? 'named' : prev === 'unknown' || content === 'unknown' ? 'unknown' : 'empty');
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// hygiene-ignore single-use -- Compute inherited hidden state once before visiting each child.
|
|
392
|
+
const currentHidden = hidden || ((ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) && hiddenState(node) !== 'empty');
|
|
393
|
+
ts.forEachChild(node, c => visit(c, currentHidden));
|
|
394
|
+
};
|
|
395
|
+
visit(src, false);
|
|
396
|
+
return labels;
|
|
397
|
+
}
|
|
398
|
+
// hygiene-ignore single-use -- Keep the documented elementNameState declaration so its parameter and return contract remains attached.
|
|
399
|
+
/**
|
|
400
|
+
* Returns accessible-name evidence for one control, including nested and id-associated labels.
|
|
401
|
+
*
|
|
402
|
+
* @param el Interactive JSX element whose accessible name is evaluated.
|
|
403
|
+
* @param kind Element role and whether native label association applies.
|
|
404
|
+
* @param labels Literal id-to-label evidence collected from the source file.
|
|
405
|
+
* @param nestedLabel Label evidence inherited from a wrapping `<label>` element.
|
|
406
|
+
*
|
|
407
|
+
* @return Accessible-name state plus any safe title repair candidate and icon-only classification.
|
|
408
|
+
*/
|
|
409
|
+
function elNameState(el, kind, labels, nestedLabel) {
|
|
410
|
+
const aria = ariaNameState(el);
|
|
411
|
+
if (aria !== 'empty')
|
|
412
|
+
return { state: aria, iconOnly: false };
|
|
413
|
+
const id = kind.labelable ? staticAttr(attrOf(el, 'id')) : { state: 'empty' };
|
|
414
|
+
if (id.state === 'static') {
|
|
415
|
+
const label = labels.get(id.value) ?? 'empty';
|
|
416
|
+
if (label !== 'empty')
|
|
417
|
+
return { state: label, iconOnly: false };
|
|
418
|
+
}
|
|
419
|
+
else if (id.state === 'unknown')
|
|
420
|
+
return { state: 'unknown', iconOnly: false };
|
|
421
|
+
if (kind.labelable && nestedLabel !== 'empty')
|
|
422
|
+
return { state: nestedLabel, iconOnly: false };
|
|
423
|
+
const tag = tagOf(el);
|
|
424
|
+
if (tag === 'input') {
|
|
425
|
+
const type = inputType(el);
|
|
426
|
+
if (type.state === 'unknown')
|
|
427
|
+
return { state: 'unknown', iconOnly: false };
|
|
428
|
+
const inputTypeValue = type.state === 'static' ? type.value.toLowerCase() : 'text';
|
|
429
|
+
if (inputTypeValue === 'image') {
|
|
430
|
+
const alt = staticAttr(attrOf(el, 'alt'));
|
|
431
|
+
if (alt.state === 'static')
|
|
432
|
+
return { state: 'named', iconOnly: false };
|
|
433
|
+
if (alt.state === 'unknown')
|
|
434
|
+
return { state: 'unknown', iconOnly: false };
|
|
435
|
+
}
|
|
436
|
+
else if (INPUT_BUTTON_TYPES.has(inputTypeValue)) {
|
|
437
|
+
const value = staticAttr(attrOf(el, 'value'));
|
|
438
|
+
if (value.state === 'static')
|
|
439
|
+
return { state: 'named', iconOnly: false };
|
|
440
|
+
if (value.state === 'unknown')
|
|
441
|
+
return { state: 'unknown', iconOnly: false };
|
|
442
|
+
if ((inputTypeValue === 'submit' || inputTypeValue === 'reset') && !attrOf(el, 'value'))
|
|
443
|
+
return { state: 'named', iconOnly: false };
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (tag === 'area') {
|
|
447
|
+
const alt = staticAttr(attrOf(el, 'alt'));
|
|
448
|
+
if (alt.state === 'static')
|
|
449
|
+
return { state: 'named', iconOnly: false };
|
|
450
|
+
if (alt.state === 'unknown')
|
|
451
|
+
return { state: 'unknown', iconOnly: false };
|
|
452
|
+
}
|
|
453
|
+
const role = staticAttr(attrOf(el, 'role'));
|
|
454
|
+
const childState = tag !== 'progress' && !(role.state === 'static' && role.value.toLowerCase() === 'progressbar') ? contentState(el) : 'empty';
|
|
455
|
+
if (childState === 'named' || childState === 'unknown')
|
|
456
|
+
return { state: childState, iconOnly: false };
|
|
457
|
+
if (attrsOf(el).properties.some(ts.isJsxSpreadAttribute))
|
|
458
|
+
return { state: 'unknown', iconOnly: false };
|
|
459
|
+
const title = literalTitle(attrOf(el, 'title'));
|
|
460
|
+
if (title.state === 'unknown')
|
|
461
|
+
return { state: 'unknown', title, iconOnly: false };
|
|
462
|
+
return { state: 'empty', title, emptyAriaLabel: attrOf(el, 'aria-label'), iconOnly: true };
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Finds unnamed, non-focusable inline SVG images inside a named native control.
|
|
466
|
+
*
|
|
467
|
+
* @param el Named control whose descendants are searched for decorative SVGs.
|
|
468
|
+
*
|
|
469
|
+
* @return SVG descendants that have no name, hidden state, focusability, or uncertain spread attributes.
|
|
470
|
+
*/
|
|
471
|
+
function decorativeIcons(el) {
|
|
472
|
+
const icons = [];
|
|
473
|
+
const visit = (node) => {
|
|
474
|
+
if (!ts.isJsxElement(node) && !ts.isJsxSelfClosingElement(node)) {
|
|
475
|
+
ts.forEachChild(node, visit);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const tag = tagOf(node);
|
|
479
|
+
if (tag === 'svg') {
|
|
480
|
+
if (staticAttr(attrOf(node, 'role')).state === 'empty' &&
|
|
481
|
+
ariaNameState(node) === 'empty' &&
|
|
482
|
+
literalTitle(attrOf(node, 'title')).state === 'empty' &&
|
|
483
|
+
contentState(node) === 'empty' &&
|
|
484
|
+
hiddenState(node) === 'empty' &&
|
|
485
|
+
!(attrsOf(node).properties.some(ts.isJsxSpreadAttribute) || ['focusable', 'tabIndex'].some(n => attrOf(node, n))))
|
|
486
|
+
icons.push(node);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (!A_Z_A_Z_D_REGEX.test(tag) || hiddenState(node) !== 'empty')
|
|
490
|
+
return;
|
|
491
|
+
if (ts.isJsxElement(node))
|
|
492
|
+
node.children.forEach(visit);
|
|
493
|
+
};
|
|
494
|
+
childrenOf(el).forEach(visit);
|
|
495
|
+
return icons;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Collects findings and candidate source edits for one parsed source file.
|
|
499
|
+
*
|
|
500
|
+
* @param cfg Quality configuration used to report repository-relative locations.
|
|
501
|
+
* @param file Absolute source path being analyzed.
|
|
502
|
+
* @param parsed Parsed JSX source tree for the file.
|
|
503
|
+
*
|
|
504
|
+
* @return Accessibility findings and the source edits that can safely repair them.
|
|
505
|
+
*/
|
|
506
|
+
function inspectFile(cfg, file, parsed) {
|
|
507
|
+
if (parsed.parseDiagnostics?.length)
|
|
508
|
+
return { findings: [], candidates: [], decorativeCandidates: [] };
|
|
509
|
+
// hygiene-ignore single-use -- Build the label map once before the JSX visitor looks up each element.
|
|
510
|
+
const labels = associatedLabels(parsed);
|
|
511
|
+
// hygiene-ignore single-use -- Build the ID map once before the JSX visitor resolves labelled-by references.
|
|
512
|
+
const ids = idContentStates(parsed);
|
|
513
|
+
const findings = [];
|
|
514
|
+
const candidates = [];
|
|
515
|
+
const decorativeCandidates = [];
|
|
516
|
+
const visit = (node, hidden, nestedLabel) => {
|
|
517
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
518
|
+
// hygiene-ignore single-use -- Inspect this element even when an ancestor is already hidden.
|
|
519
|
+
const elHidden = hiddenState(node);
|
|
520
|
+
const currentHidden = hidden || elHidden !== 'empty';
|
|
521
|
+
let childLabel = nestedLabel;
|
|
522
|
+
if (tagOf(node) === 'label')
|
|
523
|
+
childLabel = contentState(node, true);
|
|
524
|
+
const kind = (function targetKind(el) {
|
|
525
|
+
const tag = tagOf(el);
|
|
526
|
+
if (A_Z_A_Z_D_REGEX.test(tag) && (INTERACTIVE_NATIVE.has(tag) || tag === 'progress')) {
|
|
527
|
+
if (tag === 'input') {
|
|
528
|
+
const type = inputType(el);
|
|
529
|
+
if (type.state === 'unknown' || (type.state === 'static' && type.value.toLowerCase() === 'hidden'))
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
return { element: `<${tag}>`, labelable: NATIVE_LABELABLE.has(tag) };
|
|
533
|
+
}
|
|
534
|
+
if (A_Z_A_Z_D_REGEX.test(tag) && tag === 'a' && attrOf(el, 'href'))
|
|
535
|
+
return { element: '<a>', labelable: false };
|
|
536
|
+
if (A_Z_A_Z_D_REGEX.test(tag) && tag === 'area' && attrOf(el, 'href'))
|
|
537
|
+
return { element: '<area>', labelable: false };
|
|
538
|
+
const role = staticAttr(attrOf(el, 'role'));
|
|
539
|
+
if (role.state === 'static' && INTERACTIVE_ROLES.has(role.value.toLowerCase()))
|
|
540
|
+
return { element: `<${tag}>[role="${role.value}"]`, labelable: false };
|
|
541
|
+
return undefined;
|
|
542
|
+
})(node);
|
|
543
|
+
if (!currentHidden && kind) {
|
|
544
|
+
const ariaLabel = ariaNameState(node);
|
|
545
|
+
const ariaName = ariaLabel === 'empty'
|
|
546
|
+
? (function labelledByState(el, ids) {
|
|
547
|
+
const value = staticAttr(attrOf(el, 'aria-labelledby'));
|
|
548
|
+
if (value.state !== 'static')
|
|
549
|
+
return value.state;
|
|
550
|
+
const refs = value.value.trim().split(/\s+/).filter(Boolean);
|
|
551
|
+
if (!refs.length)
|
|
552
|
+
return 'empty';
|
|
553
|
+
return combine(refs.map(i => ids.get(i) ?? 'empty'));
|
|
554
|
+
})(node, ids)
|
|
555
|
+
: ariaLabel;
|
|
556
|
+
const name = ariaName === 'empty' ? elNameState(node, kind, labels, nestedLabel) : { state: ariaName, iconOnly: false };
|
|
557
|
+
if (name.state === 'empty') {
|
|
558
|
+
const titleCanFix = name.title?.state === 'static' && name.iconOnly;
|
|
559
|
+
const position = parsed.getLineAndCharacterOfPosition(node.getStart(parsed));
|
|
560
|
+
findings.push({
|
|
561
|
+
file: displayPath(cfg, file),
|
|
562
|
+
line: position.line + 1,
|
|
563
|
+
column: position.character + 1,
|
|
564
|
+
element: kind.element,
|
|
565
|
+
message: titleCanFix
|
|
566
|
+
? `${kind.element} has no accessible name; copy its non-empty title into aria-label.`
|
|
567
|
+
: `${kind.element} has no accessible name; add static text, an ARIA name, or an associated label.`,
|
|
568
|
+
fixable: titleCanFix,
|
|
569
|
+
});
|
|
570
|
+
if (name.title?.state === 'static') {
|
|
571
|
+
candidates.push({ parsed, opening: ts.isJsxElement(node) ? node.openingElement : node, title: name.title, emptyAriaLabel: name.emptyAriaLabel });
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else if (name.state === 'named') {
|
|
575
|
+
for (const icon of decorativeIcons(node)) {
|
|
576
|
+
const position = parsed.getLineAndCharacterOfPosition(icon.getStart(parsed));
|
|
577
|
+
findings.push({
|
|
578
|
+
file: displayPath(cfg, file),
|
|
579
|
+
line: position.line + 1,
|
|
580
|
+
column: position.character + 1,
|
|
581
|
+
element: '<svg>',
|
|
582
|
+
message: 'Decorative SVG inside an already named control is exposed to assistive technology; add aria-hidden="true".',
|
|
583
|
+
fixable: true,
|
|
584
|
+
});
|
|
585
|
+
decorativeCandidates.push({ parsed, opening: ts.isJsxElement(icon) ? icon.openingElement : icon });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
ts.forEachChild(node, c => visit(c, currentHidden, childLabel));
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
ts.forEachChild(node, c => visit(c, hidden, nestedLabel));
|
|
593
|
+
};
|
|
594
|
+
visit(parsed, false, 'empty');
|
|
595
|
+
return { findings, candidates, decorativeCandidates };
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Returns configured files that contain JSX syntax supported by this check.
|
|
599
|
+
*
|
|
600
|
+
* @param cfg Quality configuration defining source roots and extensions.
|
|
601
|
+
* @param analysis Optional shared analysis context containing discovered source files.
|
|
602
|
+
*
|
|
603
|
+
* @return Configured source files whose extensions support JSX parsing.
|
|
604
|
+
*/
|
|
605
|
+
function jsxFiles(cfg, analysis) {
|
|
606
|
+
return (analysis?.files ?? srcFiles(cfg)).filter(f => JSX_EXTS.test(f));
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Loads the source and parsed AST from the shared analysis cache when available.
|
|
610
|
+
*
|
|
611
|
+
* @param file Absolute source path to load and parse.
|
|
612
|
+
* @param analysis Optional shared analysis cache for file text and parsed sources.
|
|
613
|
+
*
|
|
614
|
+
* @return Source text and its parsed JSX tree.
|
|
615
|
+
*/
|
|
616
|
+
function srcFor(file, analysis) {
|
|
617
|
+
const text = analysis?.texts.get(file) ?? readFileSync(file, 'utf8');
|
|
618
|
+
return { text, parsed: analysis?.sources.get(file) ?? ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, scriptKind(file)) };
|
|
619
|
+
}
|
|
620
|
+
/*//////////////////////////////////////////////////
|
|
621
|
+
PUBLIC API
|
|
622
|
+
//////////////////////////////////////////////////*/
|
|
623
|
+
/**
|
|
624
|
+
* Finds JSX native controls and elements with explicit interactive roles that have no known accessible name.
|
|
625
|
+
* Dynamic child output, dynamic ARIA values, hidden controls, and components without explicit roles are skipped.
|
|
626
|
+
*
|
|
627
|
+
* @param cfg Quality configuration selecting source roots and extensions.
|
|
628
|
+
* @param analysis Optional shared parse context for the current quality run.
|
|
629
|
+
*
|
|
630
|
+
* @return Accessible-name findings with a flag for title-based fixes that can be applied safely.
|
|
631
|
+
*/
|
|
632
|
+
export function accessibilityFindings(cfg, analysis) {
|
|
633
|
+
return jsxFiles(cfg, analysis).flatMap(f => {
|
|
634
|
+
const { parsed } = srcFor(f, analysis);
|
|
635
|
+
return inspectFile(cfg, f, parsed).findings;
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Adds aria-label only when a non-empty literal title is the sole source-evident name for an icon-only control.
|
|
640
|
+
* Existing visible text, labels, ARIA names, and uncertain component output are left unchanged.
|
|
641
|
+
*
|
|
642
|
+
* @param cfg Quality configuration selecting source roots and extensions.
|
|
643
|
+
*
|
|
644
|
+
* @return Result containing the number of aria-label attributes added or repaired.
|
|
645
|
+
*/
|
|
646
|
+
export function fixAccessibleNames(cfg) {
|
|
647
|
+
let fixed = 0;
|
|
648
|
+
for (const file of jsxFiles(cfg)) {
|
|
649
|
+
const { text, parsed } = srcFor(file);
|
|
650
|
+
const { candidates, decorativeCandidates } = inspectFile(cfg, file, parsed);
|
|
651
|
+
if (!candidates.length && !decorativeCandidates.length)
|
|
652
|
+
continue;
|
|
653
|
+
const edits = candidates.map(c => {
|
|
654
|
+
const text = `aria-label=${c.title.source}`;
|
|
655
|
+
if (c.emptyAriaLabel)
|
|
656
|
+
return { start: c.emptyAriaLabel.getStart(c.parsed), end: c.emptyAriaLabel.end, text };
|
|
657
|
+
const attrs = c.opening.attributes;
|
|
658
|
+
const insertion = attrs.properties.length ? attrs.properties.at(-1).end : c.opening.tagName.end;
|
|
659
|
+
return { start: insertion, end: insertion, text: ` ${text}` };
|
|
660
|
+
});
|
|
661
|
+
for (const candidate of decorativeCandidates) {
|
|
662
|
+
const attrs = candidate.opening.attributes;
|
|
663
|
+
const insertion = attrs.properties.length ? attrs.properties.at(-1).end : candidate.opening.tagName.end;
|
|
664
|
+
edits.push({ start: insertion, end: insertion, text: ' aria-hidden="true"' });
|
|
665
|
+
}
|
|
666
|
+
let updated = text;
|
|
667
|
+
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
668
|
+
updated = `${updated.slice(0, edit.start)}${edit.text}${updated.slice(edit.end)}`;
|
|
669
|
+
if (ts.transpileModule(updated, { fileName: file, reportDiagnostics: true, compilerOptions: { allowJs: true, jsx: ts.JsxEmit.Preserve, target: ts.ScriptTarget.ESNext } }).diagnostics?.length)
|
|
670
|
+
continue;
|
|
671
|
+
writeFileSync(file, updated);
|
|
672
|
+
fixed += edits.length;
|
|
673
|
+
}
|
|
674
|
+
return { fixed };
|
|
675
|
+
}
|
|
676
|
+
//# sourceMappingURL=accessibility.js.map
|