loadwise 0.9.0 → 0.10.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/README.md +88 -19
- package/agent/hooks/check-edited-file.mjs +146 -28
- package/dist/bin/github-action.js +3 -74
- package/dist/bin/loadwise.js +12 -12
- package/dist/lib/accessibility/aria-tables.js +10 -6
- package/dist/lib/accessibility/document-reference-rules.js +13 -3
- package/dist/lib/accessibility/jsx-elements.js +34 -16
- package/dist/lib/accessibility/native-interactive.js +51 -13
- package/dist/lib/accessibility/rules.js +4 -2
- package/dist/lib/accessibility/site-fixes/aria-typo.js +65 -0
- package/dist/lib/accessibility/site-fixes/html-language.js +45 -9
- package/dist/lib/accessibility/template-elements.js +5 -3
- package/dist/lib/editor/actions.js +15 -9
- package/dist/lib/editor/diagnostics.js +110 -107
- package/dist/lib/editor/finding-comparison.js +4 -25
- package/dist/lib/editor/hover-markdown.js +104 -0
- package/dist/lib/editor/inline-fix.js +50 -0
- package/dist/lib/editor/inline-recommendation.js +27 -0
- package/dist/lib/editor/language-server.js +94 -18
- package/dist/lib/editor/scan-session.js +2 -1
- package/dist/lib/editor/standalone-performance-examples.js +48 -0
- package/dist/lib/maintainability/analysis/analyze-source.js +2 -0
- package/dist/lib/maintainability/architecture/architecture.js +50 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -5
- package/dist/lib/maintainability/cli/site-fix.js +3 -0
- package/dist/lib/maintainability/cli.js +6 -3
- package/dist/lib/maintainability/examples.js +48 -0
- package/dist/lib/maintainability/quality/modern-node-callbacks.js +188 -0
- package/dist/lib/maintainability/quality/modern-syntax.js +301 -0
- package/dist/lib/maintainability/quality/tsconfig-strict.js +307 -15
- package/dist/lib/maintainability/rule-ids.js +18 -0
- package/dist/lib/maintainability/scan-changed.js +33 -2
- package/dist/lib/maintainability/scan.js +10 -1
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +15 -6
- package/dist/lib/maintainability/unused/module-usage-signatures.js +116 -0
- package/dist/lib/maintainability/unused/module-usage.js +67 -106
- package/dist/lib/maintainability/unused/unused-bindings.js +143 -8
- package/dist/lib/maintainability/unused/unused-dependencies.js +218 -0
- package/dist/lib/maintainability/unused/unused-modules.js +4 -0
- package/dist/lib/performance/analysis/missing-packages.js +3 -0
- package/dist/lib/performance/analysis/source-text.js +2 -2
- package/dist/lib/performance/analyze.js +4 -1
- package/dist/lib/performance/async/floating-promises.js +25 -4
- package/dist/lib/performance/cli/cli-output.js +9 -3
- package/dist/lib/performance/cli/cli-policy.js +25 -2
- package/dist/lib/performance/cli/cli-scan.js +25 -24
- package/dist/lib/performance/cli/scan-outcome.js +19 -1
- package/dist/lib/performance/cli/shared-security-inputs.js +27 -0
- package/dist/lib/performance/cli/watch.js +27 -8
- package/dist/lib/performance/collections/collection-lookups.js +27 -10
- package/dist/lib/performance/collections/collection-reduce.js +32 -2
- package/dist/lib/performance/collections/collections.js +28 -0
- package/dist/lib/performance/collections/repeated.js +25 -1
- package/dist/lib/performance/contracts/cli.js +22 -11
- package/dist/lib/performance/contracts/git-files.js +46 -1
- package/dist/lib/performance/datastores/pooling.js +1 -17
- package/dist/lib/performance/datastores/postgres.js +41 -33
- package/dist/lib/performance/engine/native.js +5 -1
- package/dist/lib/performance/frontend/angular-template-calls.js +187 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +68 -8
- package/dist/lib/performance/frontend/frontend-perf.js +115 -171
- package/dist/lib/performance/frontend/frontend-render-perf.js +7 -3
- package/dist/lib/performance/frontend/jsx-element-perf.js +171 -0
- package/dist/lib/performance/frontend/next-fetch-waterfall.js +346 -29
- package/dist/lib/performance/frontend/rxjs-subscriptions.js +155 -0
- package/dist/lib/performance/frontend/seo/client-fetched-content.js +196 -0
- package/dist/lib/performance/frontend/seo/navigation-without-link.js +116 -0
- package/dist/lib/performance/frontend/seo/next-routes.js +114 -0
- package/dist/lib/performance/frontend/seo/route-metadata.js +158 -0
- package/dist/lib/performance/frontend/seo/seo-rules.js +9 -0
- package/dist/lib/performance/frontend/seo/sitewide-noindex.js +103 -0
- package/dist/lib/performance/frontend/template-tracking.js +86 -2
- package/dist/lib/performance/frontend/vue-options-hooks.js +108 -0
- package/dist/lib/performance/orm/prisma.js +1 -25
- package/dist/lib/performance/projects.js +3 -2
- package/dist/lib/performance/query-loops/service-loops.js +38 -8
- package/dist/lib/performance/request/json-stringify-output.js +82 -4
- package/dist/lib/performance/request/promise-schedulers.js +180 -0
- package/dist/lib/performance/request/request-handlers.js +43 -4
- package/dist/lib/performance/request/unbounded-promise-all.js +13 -52
- package/dist/lib/performance/rule-ids.js +26 -2
- package/dist/lib/performance/site-fix.js +1 -0
- package/dist/lib/reliability/react-bugs.js +9 -0
- package/dist/lib/reliability/react-state-aliases.js +94 -4
- package/dist/lib/reliability/react-state.js +24 -5
- package/dist/lib/security/auth-crypto/secrets.js +121 -16
- package/dist/lib/security/cli.js +1 -1
- package/dist/lib/security/credential-entropy.js +12 -0
- package/dist/lib/security/deps/lockfiles.js +3 -1
- package/dist/lib/security/examples/files.js +110 -0
- package/dist/lib/security/examples/request-forgery.js +1 -1
- package/dist/lib/security/exposure/frontend-security.js +11 -2
- package/dist/lib/security/exposure/prototype-pollution.js +73 -4
- package/dist/lib/security/files/azure-pipelines.js +69 -0
- package/dist/lib/security/files/bitbucket-pipelines.js +32 -0
- package/dist/lib/security/files/ci-platforms.js +16 -0
- package/dist/lib/security/files/ci-shared.js +260 -0
- package/dist/lib/security/files/circleci.js +81 -0
- package/dist/lib/security/files/dockerfile.js +188 -3
- package/dist/lib/security/files/github-actions.js +490 -0
- package/dist/lib/security/files/gitlab-ci.js +90 -0
- package/dist/lib/security/files/hcl.js +264 -0
- package/dist/lib/security/files/hosting-config.js +159 -0
- package/dist/lib/security/files/http-headers.js +65 -0
- package/dist/lib/security/files/index.js +62 -7
- package/dist/lib/security/files/jenkinsfile.js +482 -0
- package/dist/lib/security/files/json-nodes.js +67 -0
- package/dist/lib/security/files/nginx.js +501 -0
- package/dist/lib/security/files/package-scripts.js +175 -0
- package/dist/lib/security/files/rule-ids.js +29 -0
- package/dist/lib/security/files/secret-values.js +31 -5
- package/dist/lib/security/files/secrets.js +44 -13
- package/dist/lib/security/files/terraform.js +345 -0
- package/dist/lib/security/injection/nosql.js +2 -1
- package/dist/lib/security/injection/sql.js +2 -2
- package/dist/lib/security/lexical-declaration.js +28 -0
- package/dist/lib/security/pg-identifier-guards.js +90 -1
- package/dist/lib/security/request-forgery/member-chain.js +41 -0
- package/dist/lib/security/request-forgery/open-redirect.js +45 -8
- package/dist/lib/security/request-forgery/shared.js +18 -3
- package/dist/lib/security/rule-descriptions.js +29 -0
- package/dist/lib/security/rule-ids.js +29 -0
- package/dist/lib/security/taint/original-string-validation.js +229 -0
- package/dist/lib/security/taint/validators.js +1 -1
- package/dist/lib/shared/agent/review-delivery.js +3 -1
- package/dist/lib/shared/analysis/ast-semantics.js +17 -1
- package/dist/lib/shared/analysis/hot-path-graph.js +55 -19
- package/dist/lib/shared/analysis/next-env-config.js +232 -0
- package/dist/lib/shared/analysis/scan-cache-git.js +114 -0
- package/dist/lib/shared/analysis/scan-cache-loadwise-packages.js +54 -0
- package/dist/lib/shared/analysis/scan-cache-project-inputs.js +221 -0
- package/dist/lib/shared/analysis/scan-cache-sources.js +235 -0
- package/dist/lib/shared/analysis/scan-cache-storage.js +24 -0
- package/dist/lib/shared/analysis/scan-cache.js +158 -174
- package/dist/lib/shared/check-watch.js +3 -3
- package/dist/lib/shared/check.js +25 -4
- package/dist/lib/shared/config.js +1 -1
- package/dist/lib/shared/conventional-projects.js +40 -0
- package/dist/lib/shared/fix/fix-command.js +2 -0
- package/dist/lib/shared/fix/fix-usage.js +47 -0
- package/dist/lib/shared/fix/project-file-access.js +43 -20
- package/dist/lib/shared/fix.js +4 -35
- package/dist/lib/shared/formats/security-cwe.js +29 -0
- package/dist/lib/shared/project-root.js +1 -1
- package/dist/lib/shared/reporting/action-comparison.js +78 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +7 -2
- package/dist/lib/shared/reporting/check-text.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +28 -8
- package/dist/lib/shared/reporting/source-report.js +4 -4
- package/dist/lib/shared/system/git.js +31 -16
- package/dist/lib/shared/system/glob.js +146 -19
- package/dist/lib/shared/system/terminal-style.js +2 -2
- package/dist/lib/shared/workspaces.js +6 -1
- package/package.json +4 -1
- package/schema/loadwise.config.schema.json +86 -0
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { runCheck } from '../lib/shared/check.js';
|
|
4
|
-
import {
|
|
4
|
+
import { comparisonArgs } from '../lib/shared/reporting/action-comparison.js';
|
|
5
5
|
import { renderReports } from '../lib/shared/formats/index.js';
|
|
6
6
|
import { actionSummary, actionText } from '../lib/shared/reporting/action-summary.js';
|
|
7
|
-
import { selectPillars } from '../lib/shared/reporting/pillars.js';
|
|
8
|
-
import { mergeBaseSince } from '../lib/performance/migrations/enforce.js';
|
|
9
|
-
import { isRecord } from '../lib/shared/system/is-record.js';
|
|
10
7
|
import { optionArguments } from '../lib/shared/system/shell-argument.js';
|
|
11
|
-
const { GITHUB_OUTPUT,
|
|
12
|
-
const pullRequestEvent = GITHUB_EVENT_NAME === 'pull_request' || GITHUB_EVENT_NAME === 'pull_request_target';
|
|
8
|
+
const { GITHUB_OUTPUT, GITHUB_STEP_SUMMARY, RUNNER_TEMP, LOADWISE_CHECKERS, LOADWISE_PATH, LOADWISE_FAIL_ON, LOADWISE_UPLOAD_SARIF, LOADWISE_ANNOTATIONS, LOADWISE_CONFIG, LOADWISE_BASELINE, LOADWISE_WORKSPACES, LOADWISE_SKIP, LOADWISE_MIN_IMPACT, LOADWISE_IGNORE, LOADWISE_INCLUDE_CONTEXTUAL, LOADWISE_ONLINE, } = process.env;
|
|
13
9
|
function requiredEnvironment(value, name) {
|
|
14
10
|
if (!value)
|
|
15
11
|
throw new TypeError(`${name} is not set`);
|
|
@@ -24,57 +20,6 @@ function reportError(error) {
|
|
|
24
20
|
.replaceAll('[', '\\u005b');
|
|
25
21
|
console.error(`Loadwise: ${escapedMessage}`);
|
|
26
22
|
}
|
|
27
|
-
function eventBase() {
|
|
28
|
-
if (!GITHUB_EVENT_PATH)
|
|
29
|
-
return;
|
|
30
|
-
let payload;
|
|
31
|
-
try {
|
|
32
|
-
payload = JSON.parse(fs.readFileSync(GITHUB_EVENT_PATH, 'utf8'));
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (!isRecord(payload))
|
|
38
|
-
return;
|
|
39
|
-
if (GITHUB_EVENT_NAME === 'push')
|
|
40
|
-
return payload.before;
|
|
41
|
-
if (GITHUB_EVENT_NAME === 'merge_group' && isRecord(payload.merge_group))
|
|
42
|
-
return payload.merge_group.base_sha;
|
|
43
|
-
if (pullRequestEvent && isRecord(payload.pull_request) && isRecord(payload.pull_request.base))
|
|
44
|
-
return payload.pull_request.base.sha;
|
|
45
|
-
}
|
|
46
|
-
const unavailableBaseWarning = 'Warning: changed-only has no usable base commit; running a full scan. Fetch the base and full history with actions/checkout fetch-depth: 0.';
|
|
47
|
-
const nonFastForwardWarning = "Warning: the push's earlier commit is outside HEAD's history; running a full scan.";
|
|
48
|
-
function changedOnlyComparison(directory) {
|
|
49
|
-
// The comparison is required by the selected event or input even if its commit cannot be read.
|
|
50
|
-
const requiredBase = LOADWISE_BASE_SHA
|
|
51
|
-
? 'base-sha override'
|
|
52
|
-
: pullRequestEvent
|
|
53
|
-
? 'pull request base commit'
|
|
54
|
-
: undefined;
|
|
55
|
-
const unavailable = { warning: unavailableBaseWarning, requiredBase };
|
|
56
|
-
const base = LOADWISE_BASE_SHA || eventBase();
|
|
57
|
-
if (typeof base !== 'string' || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(base) || /^0+$/.test(base))
|
|
58
|
-
return unavailable;
|
|
59
|
-
try {
|
|
60
|
-
const commonAncestor = mergeBaseSince(base, directory).base;
|
|
61
|
-
// Changed-since compares against the common ancestor, which can omit reintroduced files on a force push.
|
|
62
|
-
if (commonAncestor && GITHUB_EVENT_NAME === 'push' && !LOADWISE_BASE_SHA && commonAncestor !== base.toLowerCase())
|
|
63
|
-
return { warning: nonFastForwardWarning };
|
|
64
|
-
if (commonAncestor)
|
|
65
|
-
return { base };
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
// Checkouts with incomplete history still run the check in full.
|
|
69
|
-
}
|
|
70
|
-
return unavailable;
|
|
71
|
-
}
|
|
72
|
-
function includesReliability(directory) {
|
|
73
|
-
const selection = LOADWISE_CHECKERS || LOADWISE_SKIP
|
|
74
|
-
? { only: LOADWISE_CHECKERS || undefined, skip: LOADWISE_SKIP || undefined }
|
|
75
|
-
: { only: loadSettings({ directory, explicit: configFile(directory) }).checkers?.join(',') };
|
|
76
|
-
return selectPillars(selection).some(({ name }) => name === 'rel');
|
|
77
|
-
}
|
|
78
23
|
const upload = LOADWISE_UPLOAD_SARIF === 'true';
|
|
79
24
|
const annotate = LOADWISE_ANNOTATIONS === 'true';
|
|
80
25
|
const incompleteScanCode = 2;
|
|
@@ -113,28 +58,12 @@ async function writeSummary(filename, entries) {
|
|
|
113
58
|
console.warn('Could not write the Loadwise job summary.');
|
|
114
59
|
}
|
|
115
60
|
}
|
|
116
|
-
function comparisonArgs(directory) {
|
|
117
|
-
if (LOADWISE_CHANGED_ONLY !== 'true')
|
|
118
|
-
return { flags: [], incomplete: false };
|
|
119
|
-
const comparison = changedOnlyComparison(directory);
|
|
120
|
-
if ('base' in comparison)
|
|
121
|
-
return { flags: ['--changed-since', comparison.base], incomplete: false };
|
|
122
|
-
console.warn(comparison.warning);
|
|
123
|
-
const contractGate = LOADWISE_FAIL_ON === 'contract';
|
|
124
|
-
const incomplete = (contractGate || comparison.requiredBase !== undefined) && includesReliability(directory);
|
|
125
|
-
if (incomplete) {
|
|
126
|
-
console.error(contractGate
|
|
127
|
-
? 'Cannot compare API contracts without a usable base commit. The contract-gated scan is incomplete.'
|
|
128
|
-
: `Cannot compare API contracts without a usable ${comparison.requiredBase}. The changed-only scan is incomplete.`);
|
|
129
|
-
}
|
|
130
|
-
return { flags: [], incomplete };
|
|
131
|
-
}
|
|
132
61
|
async function run() {
|
|
133
62
|
const args = [];
|
|
134
63
|
const directory = path.resolve(LOADWISE_PATH || '.');
|
|
135
64
|
if (LOADWISE_CHECKERS)
|
|
136
65
|
args.push('--only', LOADWISE_CHECKERS);
|
|
137
|
-
const comparison = comparisonArgs(directory);
|
|
66
|
+
const comparison = comparisonArgs(directory, process.env);
|
|
138
67
|
args.push(...comparison.flags);
|
|
139
68
|
if (LOADWISE_FAIL_ON)
|
|
140
69
|
args.push('--fail-on', LOADWISE_FAIL_ON);
|
package/dist/bin/loadwise.js
CHANGED
|
@@ -12,7 +12,7 @@ Start here
|
|
|
12
12
|
loadwise fix Preview automatic fixes
|
|
13
13
|
loadwise fix --apply Apply automatic fixes
|
|
14
14
|
loadwise explain <rule-id> Read about a finding's rule
|
|
15
|
-
loadwise explain --list
|
|
15
|
+
loadwise explain --list Discover rules by checker or keyword
|
|
16
16
|
|
|
17
17
|
Command help
|
|
18
18
|
loadwise check --help Scan scope, filters, and output
|
|
@@ -21,7 +21,7 @@ Command help
|
|
|
21
21
|
loadwise editor setup Set up editor diagnostics (see editor --help)
|
|
22
22
|
loadwise lsp [--stdio] Start the editor language server
|
|
23
23
|
loadwise report-fp --help Report a false positive
|
|
24
|
-
loadwise completion <shell>
|
|
24
|
+
loadwise completion <shell> Print Bash or PowerShell completion
|
|
25
25
|
|
|
26
26
|
Checker help
|
|
27
27
|
loadwise perf --help Performance, databases, traces, and plans
|
|
@@ -49,25 +49,25 @@ Scope and configuration
|
|
|
49
49
|
--only <checkers> Run the listed checkers
|
|
50
50
|
--skip <checkers> Run every other checker
|
|
51
51
|
--workspace <name|path> Scope the scan to a workspace (repeatable)
|
|
52
|
-
--uncommitted
|
|
53
|
-
--staged
|
|
52
|
+
--uncommitted Check staged, unstaged and untracked changes since HEAD
|
|
53
|
+
--staged Check lines changed in the Git index
|
|
54
54
|
--changed-since <git-ref> Check lines changed since a Git ref
|
|
55
55
|
--config <file> Use a different Loadwise configuration
|
|
56
56
|
--watch Refresh the selected checkers after saves and removals
|
|
57
|
-
--online
|
|
57
|
+
--online Query OSV with lockfile package names and versions
|
|
58
58
|
|
|
59
59
|
Reports and thresholds
|
|
60
|
-
--json
|
|
61
|
-
|
|
62
|
-
--format <format>
|
|
63
|
-
--include-contextual
|
|
60
|
+
--json Output JSON grouped by checker, with _coverage for incomplete or inapplicable checks
|
|
61
|
+
With --watch, print one JSON snapshot per line
|
|
62
|
+
--format <format> text, json, sarif, github, gitlab, junit, checkstyle, markdown, or html
|
|
63
|
+
--include-contextual Show contextual findings and their reasons
|
|
64
64
|
--ignore <rule-id> Hide findings for a rule (repeatable)
|
|
65
65
|
--min-impact <level> Select low, medium, high, or critical and above
|
|
66
|
-
--fail-on <contract|all>
|
|
66
|
+
--fail-on <contract|all> Override each checker's exit threshold
|
|
67
67
|
--baseline [file] Report findings new since the baseline
|
|
68
68
|
--write-baseline [file] Record the current findings
|
|
69
|
-
--review
|
|
70
|
-
--report-crashes
|
|
69
|
+
--review Save a structured report for agent review (defaults to JSON output)
|
|
70
|
+
--report-crashes Opt in to reporting unexpected CLI errors
|
|
71
71
|
|
|
72
72
|
Use either --only or --skip with comma-separated checker names.
|
|
73
73
|
Checkers: perf, rel, maint, sec, a11y. Full names work too.
|
|
@@ -203,13 +203,15 @@ function editDistance(first, second) {
|
|
|
203
203
|
return previousRow[second.length];
|
|
204
204
|
}
|
|
205
205
|
// The one valid name closest to the misspelling; a tie at the best distance has no clear answer.
|
|
206
|
-
function closestName(candidates, misspelled) {
|
|
206
|
+
function closestName(candidates, misspelled, maximumDistance) {
|
|
207
207
|
let best;
|
|
208
|
-
let bestDistance =
|
|
208
|
+
let bestDistance = maximumDistance + 1;
|
|
209
209
|
let isTied = false;
|
|
210
210
|
for (const candidate of candidates) {
|
|
211
|
+
if (Math.abs(candidate.length - misspelled.length) > maximumDistance)
|
|
212
|
+
continue;
|
|
211
213
|
const distance = editDistance(misspelled, candidate);
|
|
212
|
-
if (distance >
|
|
214
|
+
if (distance > maximumDistance)
|
|
213
215
|
continue;
|
|
214
216
|
if (distance < bestDistance) {
|
|
215
217
|
best = candidate;
|
|
@@ -223,9 +225,11 @@ function closestName(candidates, misspelled) {
|
|
|
223
225
|
return isTied ? undefined : best;
|
|
224
226
|
}
|
|
225
227
|
function closestAttributeName(misspelled) {
|
|
226
|
-
|
|
228
|
+
if (validAttributeNames.has(misspelled))
|
|
229
|
+
return misspelled;
|
|
230
|
+
return closestName(ariaAttributeNames, misspelled, maxSuggestionDistance);
|
|
227
231
|
}
|
|
228
|
-
function closestRoleName(misspelled) {
|
|
229
|
-
return closestName(ariaRoleNames, misspelled);
|
|
232
|
+
function closestRoleName(misspelled, maximumDistance = maxSuggestionDistance) {
|
|
233
|
+
return closestName(ariaRoleNames, misspelled, maximumDistance);
|
|
230
234
|
}
|
|
231
235
|
export { validAttributeNames, validRoleNames, closestAttributeName, closestRoleName };
|
|
@@ -37,11 +37,11 @@ function elementVisibility(element, cache) {
|
|
|
37
37
|
cache.set(element, visibility);
|
|
38
38
|
return visibility;
|
|
39
39
|
}
|
|
40
|
-
function svgAncestorMayHide(ancestors, cache) {
|
|
40
|
+
function svgAncestorMayHide(ancestors, cache, mayHide = (element) => elementVisibility(element, cache).mayHide) {
|
|
41
41
|
let inSvg = false;
|
|
42
42
|
for (const ancestor of ancestors) {
|
|
43
43
|
const visibility = elementVisibility(ancestor, cache);
|
|
44
|
-
if (
|
|
44
|
+
if (mayHide(ancestor))
|
|
45
45
|
return true;
|
|
46
46
|
inSvg ||= ancestor.tagName === 'svg';
|
|
47
47
|
if (inSvg && visibility.hasDisplayNone)
|
|
@@ -77,6 +77,16 @@ function idRefTokens(value) {
|
|
|
77
77
|
// HTML space-separated tokens recognize only ASCII whitespace.
|
|
78
78
|
return [...new Set(value.split(/[\t\n\f\r ]+/).filter(Boolean))];
|
|
79
79
|
}
|
|
80
|
+
// A blank aria-labelledby names nothing, and neither does one whose IDs a complete document proves absent; elsewhere the
|
|
81
|
+
// target may be rendered by another file.
|
|
82
|
+
function labelledByMaySupplyName(element, documentIds) {
|
|
83
|
+
const reference = attributeNamed(element, 'aria-labelledby');
|
|
84
|
+
if (!reference)
|
|
85
|
+
return false;
|
|
86
|
+
if (reference.value.kind === 'dynamic')
|
|
87
|
+
return true;
|
|
88
|
+
return idRefTokens(reference.value.text).some((token) => !documentIds || possibleCharacterReference.test(token) || documentIds.has(token));
|
|
89
|
+
}
|
|
80
90
|
function invalidIdReference(element, { document, documentIds }) {
|
|
81
91
|
if (!documentIds)
|
|
82
92
|
return [];
|
|
@@ -130,4 +140,4 @@ function indexCompleteDocumentIds(document, includesOtherTemplates) {
|
|
|
130
140
|
}
|
|
131
141
|
return ids;
|
|
132
142
|
}
|
|
133
|
-
export { elementVisibility, indexCompleteDocumentIds, invalidIdReference, svgAncestorMayHide, svgImageMissingName };
|
|
143
|
+
export { elementVisibility, indexCompleteDocumentIds, invalidIdReference, labelledByMaySupplyName, styleMayHide, svgAncestorMayHide, svgImageMissingName, };
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { ts } from '../performance/engine/compiler.js';
|
|
3
3
|
import { intrinsicTagPattern } from './markup.js';
|
|
4
4
|
const htmlNameByJsxProp = { htmlFor: 'for', className: 'class' };
|
|
5
|
+
// Buttons, and the icon elements whose emptiness decides a button's name.
|
|
6
|
+
const textTrackedTags = new Set(['button', 'i', 'span']);
|
|
5
7
|
function isElementNode(node) {
|
|
6
8
|
return ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node);
|
|
7
9
|
}
|
|
@@ -222,17 +224,18 @@ function passesChildrenThrough(opening, checker) {
|
|
|
222
224
|
const expression = directChildExpression(container);
|
|
223
225
|
return !!expression && isChildrenReference(expression, parameter, checker);
|
|
224
226
|
}
|
|
225
|
-
function translateElement(sourceFile, node, isConditional, checker) {
|
|
227
|
+
function translateElement(sourceFile, node, isConditional, isTemplate, checker) {
|
|
226
228
|
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
227
229
|
const children = ts.isJsxElement(node) ? node.children : [];
|
|
228
230
|
const tagName = opening.tagName.getText(sourceFile);
|
|
229
231
|
const { attributes, hasSpreadAttributes } = translateAttributes(sourceFile, opening.attributes.properties, checker);
|
|
230
232
|
const nested = [];
|
|
233
|
+
const nestedSink = { sourceFile, into: nested, checker };
|
|
231
234
|
// A JSX element passed as a prop is rendered only if its recipient uses the prop.
|
|
232
235
|
for (const attribute of opening.attributes.properties)
|
|
233
|
-
collectElements(
|
|
236
|
+
collectElements(nestedSink, attribute, true, true);
|
|
234
237
|
for (const child of children)
|
|
235
|
-
collectElements(
|
|
238
|
+
collectElements(nestedSink, child, false, false);
|
|
236
239
|
const staticText = tagName === 'a' || tagName === 'title' ? staticChildText(children) : undefined;
|
|
237
240
|
return {
|
|
238
241
|
tagName,
|
|
@@ -241,8 +244,9 @@ function translateElement(sourceFile, node, isConditional, checker) {
|
|
|
241
244
|
attributes,
|
|
242
245
|
hasSpreadAttributes,
|
|
243
246
|
...(staticText === undefined ? {} : { staticText }),
|
|
244
|
-
...(tagName
|
|
247
|
+
...(textTrackedTags.has(tagName) && !children.some(childMaySupplyText) && { hasOnlyElementChildren: true }),
|
|
245
248
|
...(isConditional ? { isConditional } : {}),
|
|
249
|
+
...(isConditional && !isTemplate && { rendersAsWritten: true }),
|
|
246
250
|
children: nested,
|
|
247
251
|
...position(sourceFile, opening),
|
|
248
252
|
};
|
|
@@ -254,16 +258,16 @@ const logicalOperators = new Set([
|
|
|
254
258
|
]);
|
|
255
259
|
// The branches of `a ? <X /> : <Y />` and the right side of `a && <X />` may not render, and the two branches never
|
|
256
260
|
// render together.
|
|
257
|
-
function collectConditionalElements(
|
|
261
|
+
function collectConditionalElements(sink, node, isConditional, isTemplate) {
|
|
258
262
|
if (ts.isConditionalExpression(node)) {
|
|
259
|
-
collectElements(
|
|
260
|
-
collectElements(
|
|
261
|
-
collectElements(
|
|
263
|
+
collectElements(sink, node.condition, isConditional, isTemplate);
|
|
264
|
+
collectElements(sink, node.whenTrue, true, isTemplate);
|
|
265
|
+
collectElements(sink, node.whenFalse, true, isTemplate);
|
|
262
266
|
return true;
|
|
263
267
|
}
|
|
264
268
|
if (ts.isBinaryExpression(node) && logicalOperators.has(node.operatorToken.kind)) {
|
|
265
|
-
collectElements(
|
|
266
|
-
collectElements(
|
|
269
|
+
collectElements(sink, node.left, isConditional, isTemplate);
|
|
270
|
+
collectElements(sink, node.right, true, isTemplate);
|
|
267
271
|
return true;
|
|
268
272
|
}
|
|
269
273
|
return false;
|
|
@@ -309,23 +313,37 @@ function isRenderSlotValue(sourceFile, node) {
|
|
|
309
313
|
}
|
|
310
314
|
return isRenderSlotFactory(sourceFile, node);
|
|
311
315
|
}
|
|
316
|
+
const listMappingMethods = new Set(['map', 'flatMap']);
|
|
317
|
+
// A list-mapping callback, as in `items.map((item) => <li />)`, returns its elements as written; any other function in a
|
|
318
|
+
// JSX expression, such as a function child or a callback handed to an unknown helper, may be a render prop whose
|
|
319
|
+
// recipient fills in what it returns.
|
|
320
|
+
function isListMappingCallback(node) {
|
|
321
|
+
const call = node.parent;
|
|
322
|
+
return (ts.isCallExpression(call) &&
|
|
323
|
+
call.arguments[0] === node &&
|
|
324
|
+
ts.isPropertyAccessExpression(call.expression) &&
|
|
325
|
+
listMappingMethods.has(call.expression.name.text));
|
|
326
|
+
}
|
|
312
327
|
// Fragments and expression wrappers are transparent: the elements inside them belong to the nearest enclosing element.
|
|
313
|
-
function collectElements(
|
|
328
|
+
function collectElements(sink, node, isConditional, isTemplate) {
|
|
329
|
+
const { sourceFile, into, checker } = sink;
|
|
314
330
|
if (isElementNode(node)) {
|
|
315
|
-
into.push(translateElement(sourceFile, node, isConditional, checker));
|
|
331
|
+
into.push(translateElement(sourceFile, node, isConditional, isTemplate, checker));
|
|
316
332
|
return;
|
|
317
333
|
}
|
|
318
|
-
if (collectConditionalElements(
|
|
334
|
+
if (collectConditionalElements(sink, node, isConditional, isTemplate))
|
|
319
335
|
return;
|
|
320
336
|
// A function produced inside a JSX expression may be called zero times, even when its enclosing element renders.
|
|
321
337
|
const isJsxCallback = (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) &&
|
|
322
338
|
ts.findAncestor(node, ts.isJsxExpression) !== undefined;
|
|
323
|
-
const
|
|
324
|
-
|
|
339
|
+
const isRenderSlot = isRenderSlotValue(sourceFile, node);
|
|
340
|
+
const childIsConditional = isConditional || isJsxCallback || isRenderSlot;
|
|
341
|
+
const childIsTemplate = isTemplate || isRenderSlot || (isJsxCallback && !isListMappingCallback(node));
|
|
342
|
+
ts.forEachChild(node, (child) => collectElements(sink, child, childIsConditional, childIsTemplate));
|
|
325
343
|
}
|
|
326
344
|
function jsxDocument(sourceFile, file, checker) {
|
|
327
345
|
const roots = [];
|
|
328
|
-
collectElements(
|
|
346
|
+
collectElements({ sourceFile, into: roots, checker }, sourceFile, false, false);
|
|
329
347
|
return { file, roots, text: sourceFile.text };
|
|
330
348
|
}
|
|
331
349
|
export { jsxDocument };
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import { elementVisibility, svgAncestorMayHide } from './document-reference-rules.js';
|
|
1
|
+
import { elementVisibility, labelledByMaySupplyName, styleMayHide, svgAncestorMayHide, } from './document-reference-rules.js';
|
|
2
2
|
import { labelMayTargetId } from './form-context.js';
|
|
3
3
|
import { attributeNamed, staticAttributeText } from './markup.js';
|
|
4
4
|
import { contentSettingAttributes, finding, hasAttribute, isCertainlyHidden, isPossiblyHidden, isPresentationalRole, maySupplyName, } from './rule-utilities.js';
|
|
5
|
-
function isUncertainInteractiveMarkup(element) {
|
|
5
|
+
function isUncertainInteractiveMarkup(element, allowsRenderedAsWritten = false) {
|
|
6
6
|
return (!element.isIntrinsic ||
|
|
7
7
|
element.hasSpreadAttributes ||
|
|
8
|
-
element.isConditional === true ||
|
|
8
|
+
(element.isConditional === true && !(allowsRenderedAsWritten && element.rendersAsWritten)) ||
|
|
9
9
|
['iframe', 'slot', 'template'].includes(element.tagName));
|
|
10
10
|
}
|
|
11
|
+
// Whether a button has a name does not depend on whether it renders, so a JSX branch or list item that renders as
|
|
12
|
+
// written is as certain as unconditional markup; only a template a component may fill in stays open.
|
|
13
|
+
function isUncertainNamingMarkup(element) {
|
|
14
|
+
return isUncertainInteractiveMarkup(element, true);
|
|
15
|
+
}
|
|
16
|
+
function mayHideNamedMarkup(element, svgVisibility) {
|
|
17
|
+
if (!element.rendersAsWritten)
|
|
18
|
+
return elementVisibility(element, svgVisibility).mayHide;
|
|
19
|
+
// isUncertainNamingMarkup already covers components, spreads and templates.
|
|
20
|
+
return isPossiblyHidden(element) || styleMayHide(element);
|
|
21
|
+
}
|
|
11
22
|
function isOutsideButtonNamingTree(element) {
|
|
12
23
|
return (staticAttributeText(element, 'inert') !== undefined ||
|
|
13
24
|
staticAttributeText(element, 'popover') !== undefined ||
|
|
@@ -52,31 +63,58 @@ function mayRenderNameFromAttribute(element) {
|
|
|
52
63
|
return (translate !== undefined &&
|
|
53
64
|
(translate.kind === 'dynamic' || !nativeTranslateValues.has(translate.text.trim().toLowerCase())));
|
|
54
65
|
}
|
|
66
|
+
function maySupplyOwnName(element, documentIds) {
|
|
67
|
+
return (['aria-label', 'title'].some((name) => maySupplyName(element, name)) ||
|
|
68
|
+
labelledByMaySupplyName(element, documentIds) ||
|
|
69
|
+
['children', 'dangerouslysetinnerhtml', ...contentSettingAttributes].some((name) => hasAttribute(element, name)) ||
|
|
70
|
+
mayRenderNameFromAttribute(element));
|
|
71
|
+
}
|
|
72
|
+
// Icon-font classes: Font Awesome (`fa`, its `fas`/`far`/`fab`/`fal`/`fad`/`fat` styles and `fa-*`), Bootstrap
|
|
73
|
+
// Icons, Material Design Icons, Glyphicons and any class with `icon` as a whole segment, not `lexicon` or `fare`.
|
|
74
|
+
const iconClassToken = /^(?:fa[bdlrst]?|fa-.+|bi|bi-.+|mdi|mdi-.+|glyphicon.*|(?:.*[-_])?icons?(?:[-_].*)?)$/i;
|
|
75
|
+
// An icon font draws its glyph with CSS, which gives a button no text: `<i class="fa fa-trash">` or an empty
|
|
76
|
+
// `<span class="icon">`. Any other empty span stays open, since CSS generated content can supply a name.
|
|
77
|
+
function isEmptyIconElement(element, documentIds) {
|
|
78
|
+
if (isUncertainInteractiveMarkup(element) || !element.hasOnlyElementChildren || element.children.length)
|
|
79
|
+
return false;
|
|
80
|
+
if (maySupplyOwnName(element, documentIds))
|
|
81
|
+
return false;
|
|
82
|
+
if (element.tagName === 'i')
|
|
83
|
+
return true;
|
|
84
|
+
const classes = staticAttributeText(element, 'class');
|
|
85
|
+
return element.tagName === 'span' && !!classes?.split(/\s+/).some((token) => iconClassToken.test(token));
|
|
86
|
+
}
|
|
87
|
+
// `alt=""` marks an image as decorative, so it adds nothing to the button's name.
|
|
88
|
+
function isDecorativeImage(element, documentIds) {
|
|
89
|
+
return (element.tagName === 'img' &&
|
|
90
|
+
!isUncertainInteractiveMarkup(element) &&
|
|
91
|
+
staticAttributeText(element, 'alt')?.trim() === '' &&
|
|
92
|
+
!maySupplyOwnName(element, documentIds));
|
|
93
|
+
}
|
|
55
94
|
const buttonMissingName = (element, context) => {
|
|
56
95
|
const { document, ancestors, includesOtherTemplates, svgVisibility } = context;
|
|
57
96
|
if (element.tagName !== 'button' || !element.hasOnlyElementChildren || includesOtherTemplates)
|
|
58
97
|
return [];
|
|
59
|
-
if (
|
|
60
|
-
|
|
98
|
+
if (isUncertainNamingMarkup(element) ||
|
|
99
|
+
mayHideNamedMarkup(element, svgVisibility) ||
|
|
61
100
|
isOutsideButtonNamingTree(element) ||
|
|
62
101
|
isPresentationalRole(element))
|
|
63
102
|
return [];
|
|
64
|
-
if (svgAncestorMayHide(ancestors, svgVisibility) ||
|
|
65
|
-
ancestors.some((ancestor, index) =>
|
|
103
|
+
if (svgAncestorMayHide(ancestors, svgVisibility, (ancestor) => mayHideNamedMarkup(ancestor, svgVisibility)) ||
|
|
104
|
+
ancestors.some((ancestor, index) => isUncertainNamingMarkup(ancestor) ||
|
|
66
105
|
isOutsideButtonNamingTree(ancestor) ||
|
|
67
106
|
hidesDetailsBranch(ancestor, ancestors[index + 1] ?? element) ||
|
|
68
107
|
ancestor.tagName === 'label'))
|
|
69
108
|
return [];
|
|
70
|
-
if (
|
|
71
|
-
return [];
|
|
72
|
-
if (['children', 'dangerouslysetinnerhtml', ...contentSettingAttributes].some((name) => hasAttribute(element, name)))
|
|
73
|
-
return [];
|
|
74
|
-
if (mayRenderNameFromAttribute(element))
|
|
109
|
+
if (maySupplyOwnName(element, context.documentIds))
|
|
75
110
|
return [];
|
|
76
111
|
const id = attributeNamed(element, 'id');
|
|
77
112
|
if (id && labelMayTargetId(id, context))
|
|
78
113
|
return [];
|
|
79
|
-
|
|
114
|
+
const isSilentChild = (child) => (!isUncertainInteractiveMarkup(child) && isCertainlyHidden(child)) ||
|
|
115
|
+
isEmptyIconElement(child, context.documentIds) ||
|
|
116
|
+
isDecorativeImage(child, context.documentIds);
|
|
117
|
+
if (!element.children.every(isSilentChild))
|
|
80
118
|
return [];
|
|
81
119
|
return [
|
|
82
120
|
finding(document, element, 'a11y-button-missing-name', 'This button has no accessible name. Add text or a label that describes its action.'),
|
|
@@ -11,7 +11,7 @@ import { formAndLabelTargets, formMayDisableAutocomplete, labelMayTargetId } fro
|
|
|
11
11
|
import { buttonMissingName, nestedInteractive } from './native-interactive.js';
|
|
12
12
|
import { hasPageScriptingOrStyles, mediaAutoplay, videoCaptionsReview } from './media-rules.js';
|
|
13
13
|
import { placeholderLinkAction, roleMissingChecked } from './interaction-semantics.js';
|
|
14
|
-
import { indexCompleteDocumentIds, invalidIdReference, svgImageMissingName } from './document-reference-rules.js';
|
|
14
|
+
import { indexCompleteDocumentIds, invalidIdReference, labelledByMaySupplyName, svgImageMissingName, } from './document-reference-rules.js';
|
|
15
15
|
import { dataTableMissingHeaders } from './table-headers.js';
|
|
16
16
|
import { contentSettingAttributes, finding, hasAttribute, hasHiddenInlineStyle, isHiddenFromAssistiveTechnology, isPossiblyHidden, isPresentationalRole, isStaticValue, mayPreventTabFocus, maySupplyName, } from './rule-utilities.js';
|
|
17
17
|
import { normalizeSlashes } from '../shared/system/posix-path.js';
|
|
@@ -270,7 +270,9 @@ const missingFormLabel = (element, context) => {
|
|
|
270
270
|
return [];
|
|
271
271
|
if (context.includesOtherTemplates)
|
|
272
272
|
return [];
|
|
273
|
-
|
|
273
|
+
// A blank aria-label or title, or an aria-labelledby that names nothing, leaves the control unlabelled.
|
|
274
|
+
if (['aria-label', 'title'].some((name) => maySupplyName(element, name)) ||
|
|
275
|
+
labelledByMaySupplyName(element, context.documentIds))
|
|
274
276
|
return [];
|
|
275
277
|
if (hasLabelFromContext(element, context))
|
|
276
278
|
return [];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ts } from '../../performance/engine/compiler.js';
|
|
2
|
+
import { closestAttributeName, closestRoleName, validAttributeNames, validRoleNames } from '../aria-tables.js';
|
|
3
|
+
import { intrinsicTagPattern } from '../markup.js';
|
|
4
|
+
const ordinaryAriaName = /^aria-[a-z]+$/;
|
|
5
|
+
const ordinaryRoleName = /^[a-z][a-z-]*$/i;
|
|
6
|
+
const maxRoleFixDistance = 1;
|
|
7
|
+
function roleTypo(initializer, sourceFile) {
|
|
8
|
+
const quotedRole = initializer.getText(sourceFile);
|
|
9
|
+
const role = quotedRole.slice(1, -1);
|
|
10
|
+
const normalizedRole = role.toLowerCase();
|
|
11
|
+
if (quotedRole[0] !== quotedRole.at(-1) ||
|
|
12
|
+
role !== initializer.text ||
|
|
13
|
+
!ordinaryRoleName.test(role) ||
|
|
14
|
+
validRoleNames.has(normalizedRole))
|
|
15
|
+
return;
|
|
16
|
+
const replacement = closestRoleName(normalizedRole, maxRoleFixDistance);
|
|
17
|
+
if (!replacement)
|
|
18
|
+
return;
|
|
19
|
+
return {
|
|
20
|
+
edits: [{ start: initializer.getStart(sourceFile) + 1, end: initializer.end - 1, text: replacement }],
|
|
21
|
+
note: `Verify that the ${replacement} role matches the element's behavior, keyboard support and accessible name.`,
|
|
22
|
+
requiresReview: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const ariaTypo = ({ finding, node, sourceFile }) => {
|
|
26
|
+
if (!sourceFile || !node || !ts.isIdentifier(node) || !ts.isJsxAttribute(node.parent) || node.parent.name !== node)
|
|
27
|
+
return;
|
|
28
|
+
const start = node.getStart(sourceFile);
|
|
29
|
+
const location = sourceFile.getLineAndCharacterOfPosition(start);
|
|
30
|
+
if (location.line + 1 !== finding.line || location.character + 1 !== finding.column)
|
|
31
|
+
return;
|
|
32
|
+
const attribute = node.parent;
|
|
33
|
+
if (!attribute.initializer || !ts.isStringLiteral(attribute.initializer))
|
|
34
|
+
return;
|
|
35
|
+
const opening = attribute.parent.parent;
|
|
36
|
+
if (!intrinsicTagPattern.test(opening.tagName.getText(sourceFile)))
|
|
37
|
+
return;
|
|
38
|
+
const names = new Set();
|
|
39
|
+
for (const sibling of opening.attributes.properties) {
|
|
40
|
+
if (!ts.isJsxAttribute(sibling))
|
|
41
|
+
return;
|
|
42
|
+
const name = sibling.name.getText(sourceFile).toLowerCase();
|
|
43
|
+
if (names.has(name))
|
|
44
|
+
return;
|
|
45
|
+
names.add(name);
|
|
46
|
+
}
|
|
47
|
+
const typo = node.getText(sourceFile);
|
|
48
|
+
if (typo === 'role')
|
|
49
|
+
return roleTypo(attribute.initializer, sourceFile);
|
|
50
|
+
if (!ordinaryAriaName.test(typo) || validAttributeNames.has(typo))
|
|
51
|
+
return;
|
|
52
|
+
const replacement = closestAttributeName(typo);
|
|
53
|
+
if (!replacement)
|
|
54
|
+
return;
|
|
55
|
+
for (const name of names) {
|
|
56
|
+
if (name !== typo && name.startsWith('aria-') && closestAttributeName(name) === replacement)
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
edits: [{ start, end: node.end, text: replacement }],
|
|
61
|
+
note: `Verify that ${replacement} is the intended ARIA attribute for the existing value.`,
|
|
62
|
+
requiresReview: true,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export default { 'a11y-invalid-aria': ariaTypo };
|
|
@@ -6,7 +6,10 @@ import { offsetOf } from './source-position.js';
|
|
|
6
6
|
const plainHtmlFile = /\.html?$/i;
|
|
7
7
|
const htmlTag = /^<html(?=[\s>])/i;
|
|
8
8
|
const literalXmlLang = /^xml:lang\s*=\s*(?:(['"])([\s\S]*?)\1|([a-z0-9-]+)(?=[\s>]))/i;
|
|
9
|
-
|
|
9
|
+
// The markup model omits some directives. Require ordinary literal attributes in the original opening tag.
|
|
10
|
+
const literalHtmlOpening = /^<html(?:[\t\n\f\r ]+(?!(?:v-|x-|ng-|data-ng-|data-x-|data-bind\b))[a-z][a-z0-9_-]*(?:[\t\n\f\r ]*=[\t\n\f\r ]*(?:"[^"<>{}$]*"|'[^'<>{}$]*'|[^\t\n\f\r "'=<>`{}$]+))?)*[\t\n\f\r ]*>/i;
|
|
11
|
+
const literalLocale = /^lang[\t\n\f\r ]*=[\t\n\f\r ]*(['"]?)([a-z]{2,3}_(?:[a-z]{2}|\d{3}))\1(?=[\t\n\f\r >])/i;
|
|
12
|
+
function htmlLanguageTarget({ finding, text, load }) {
|
|
10
13
|
const { file, line, column } = finding;
|
|
11
14
|
if (!file || line === undefined || column === undefined || !plainHtmlFile.test(file) || isAngularTemplate(file))
|
|
12
15
|
return;
|
|
@@ -17,11 +20,19 @@ function languageFix({ finding, text, load }) {
|
|
|
17
20
|
if (roots.length !== 1)
|
|
18
21
|
return;
|
|
19
22
|
const [html] = roots;
|
|
20
|
-
if (html.tagName !== 'html' ||
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (html.tagName !== 'html' || html.line !== line || html.column !== column || html.hasSpreadAttributes)
|
|
24
|
+
return;
|
|
25
|
+
const openingOffset = offsetOf(source, line, column);
|
|
26
|
+
if (openingOffset === undefined)
|
|
27
|
+
return;
|
|
28
|
+
return { html, source, openingOffset };
|
|
29
|
+
}
|
|
30
|
+
function languageFix(input) {
|
|
31
|
+
const target = htmlLanguageTarget(input);
|
|
32
|
+
if (!target)
|
|
33
|
+
return;
|
|
34
|
+
const { html, source, openingOffset } = target;
|
|
35
|
+
if (attributeNamed(html, 'lang'))
|
|
25
36
|
return;
|
|
26
37
|
const xmlLang = html.attributes.filter(({ name }) => name === 'xml:lang');
|
|
27
38
|
if (xmlLang.length !== 1 || xmlLang[0].value.kind !== 'static')
|
|
@@ -34,8 +45,7 @@ function languageFix({ finding, text, load }) {
|
|
|
34
45
|
if (value === undefined || value !== xmlLang[0].value.text || !wellFormedLanguageTag(value))
|
|
35
46
|
return;
|
|
36
47
|
const quote = match?.[1] ?? '';
|
|
37
|
-
|
|
38
|
-
if (openingOffset === undefined || !htmlTag.test(source.slice(openingOffset)))
|
|
48
|
+
if (!htmlTag.test(source.slice(openingOffset)))
|
|
39
49
|
return;
|
|
40
50
|
const at = openingOffset + '<html'.length;
|
|
41
51
|
return {
|
|
@@ -44,5 +54,31 @@ function languageFix({ finding, text, load }) {
|
|
|
44
54
|
requiresReview: true,
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
|
-
|
|
57
|
+
function languageSeparatorFix(input) {
|
|
58
|
+
const target = htmlLanguageTarget(input);
|
|
59
|
+
if (!target)
|
|
60
|
+
return;
|
|
61
|
+
const { html, source, openingOffset } = target;
|
|
62
|
+
const lang = html.attributes.filter(({ name }) => name === 'lang');
|
|
63
|
+
if (lang.length !== 1 || lang[0].value.kind !== 'static' || attributeNamed(html, 'xml:lang'))
|
|
64
|
+
return;
|
|
65
|
+
if (!literalHtmlOpening.test(source.slice(openingOffset)))
|
|
66
|
+
return;
|
|
67
|
+
const offset = offsetOf(source, lang[0].line, lang[0].column);
|
|
68
|
+
if (offset === undefined)
|
|
69
|
+
return;
|
|
70
|
+
const match = literalLocale.exec(source.slice(offset));
|
|
71
|
+
if (!match || match[2] !== lang[0].value.text || !wellFormedLanguageTag(match[2].replace('_', '-')))
|
|
72
|
+
return;
|
|
73
|
+
const start = offset + match[0].indexOf('_');
|
|
74
|
+
return {
|
|
75
|
+
edits: [{ start, end: start + 1, text: '-' }],
|
|
76
|
+
note: 'Verify the language and region describe the current page content.',
|
|
77
|
+
requiresReview: true,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const builders = {
|
|
81
|
+
'a11y-html-missing-lang': languageFix,
|
|
82
|
+
'a11y-html-invalid-lang': languageSeparatorFix,
|
|
83
|
+
};
|
|
48
84
|
export default builders;
|
|
@@ -14,6 +14,8 @@ const captionTextClosingTag = /([^<{}]*)<\/caption(?=[\s>])/iy;
|
|
|
14
14
|
// Rules and the tree walks recurse once per nesting level; deeper tags of a pathological file become siblings so the
|
|
15
15
|
// recursion stays shallow.
|
|
16
16
|
const maxOpenElements = 500;
|
|
17
|
+
// Buttons, and the icon elements whose emptiness decides a button's name.
|
|
18
|
+
const textTrackedTags = new Set(['button', 'i', 'span']);
|
|
17
19
|
const maxBracePasses = 4;
|
|
18
20
|
class TemplateBraceBudgetError extends Error {
|
|
19
21
|
constructor() {
|
|
@@ -103,7 +105,7 @@ class TemplateParser {
|
|
|
103
105
|
while (this.position < this.end) {
|
|
104
106
|
const element = this.top();
|
|
105
107
|
const next = this.readConstruct(this.position, singleRoot && this.stack.length === 1);
|
|
106
|
-
if (element.tagName
|
|
108
|
+
if (textTrackedTags.has(element.tagName) && isPossibleButtonText(this.text, this.position, next))
|
|
107
109
|
element.hasPossibleDirectText = true;
|
|
108
110
|
this.position = next === -1 ? this.position + 1 : next;
|
|
109
111
|
if (singleRoot && this.stack.length === 1)
|
|
@@ -354,7 +356,7 @@ class TemplateParser {
|
|
|
354
356
|
attributes: frame.attributes,
|
|
355
357
|
hasSpreadAttributes: frame.hasSpreadAttributes,
|
|
356
358
|
...(frame.staticText === undefined ? {} : { staticText: frame.staticText }),
|
|
357
|
-
...(frame.tagName
|
|
359
|
+
...(textTrackedTags.has(frame.tagName) && !frame.hasPossibleDirectText && { hasOnlyElementChildren: true }),
|
|
358
360
|
...(frame.isConditional ? { isConditional: true } : {}),
|
|
359
361
|
...(frame.vuePre ? { vuePre: true } : {}),
|
|
360
362
|
children: frame.children,
|
|
@@ -417,7 +419,7 @@ class TemplateParser {
|
|
|
417
419
|
return this.readRawText(frame, parsed.next);
|
|
418
420
|
if (frame.isTransparent) {
|
|
419
421
|
frame.children = parent.children;
|
|
420
|
-
if (parent.tagName
|
|
422
|
+
if (textTrackedTags.has(parent.tagName))
|
|
421
423
|
parent.hasPossibleDirectText = true;
|
|
422
424
|
}
|
|
423
425
|
this.stack.push(frame);
|