loadwise 0.7.0 → 0.8.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 +23 -15
- package/dist/bin/loadwise.js +12 -24
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +5 -3
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +7 -2
- package/dist/lib/editor/language-server.js +64 -25
- package/dist/lib/editor/native-setup.js +3 -2
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +36 -9
- package/dist/lib/editor/setup-server.js +1 -1
- package/dist/lib/editor/setup-vim.js +6 -4
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +9 -1
- package/dist/lib/maintainability/cli.js +4 -0
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/cli-output.js +1 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +8 -3
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +61 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +56 -2
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +72 -57
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/mongoose-lean.js +175 -10
- package/dist/lib/performance/request/phase5-rules.js +74 -13
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +18 -4
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +6 -2
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +2 -1
- package/dist/lib/shared/agent/agent-verify.js +4 -1
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +96 -12
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +5 -3
- package/dist/lib/shared/fix/fix-imports.js +4 -171
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation.js +5 -3
- package/dist/lib/shared/fix/fix-safety.js +7 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix.js +31 -7
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +6 -2
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +9 -3
- package/dist/lib/shared/reporting/source-report.js +1 -0
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +26 -7
- package/dist/lib/shared/workspaces.js +15 -3
- package/package.json +5 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +554 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// TypeScript pass; HTML files and Vue, Svelte and Angular templates are read as markup files beside it.
|
|
3
3
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
4
4
|
const knownRules = new Set([
|
|
5
|
+
'a11y-aria-hidden-focus',
|
|
5
6
|
'a11y-button-missing-type',
|
|
6
7
|
'a11y-clickable-non-interactive',
|
|
7
8
|
'a11y-heading-level-skipped',
|
|
@@ -18,6 +19,7 @@ const knownRules = new Set([
|
|
|
18
19
|
]);
|
|
19
20
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
20
21
|
const impactByRule = {
|
|
22
|
+
'a11y-aria-hidden-focus': 'high',
|
|
21
23
|
'a11y-button-missing-type': 'medium',
|
|
22
24
|
'a11y-clickable-non-interactive': 'high',
|
|
23
25
|
'a11y-heading-level-skipped': 'low',
|
|
@@ -34,6 +36,7 @@ const impactByRule = {
|
|
|
34
36
|
};
|
|
35
37
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
36
38
|
const descriptionByRule = {
|
|
39
|
+
'a11y-aria-hidden-focus': 'A control in the Tab order is hidden from assistive technology by aria-hidden.',
|
|
37
40
|
'a11y-button-missing-type': 'A button associated with a form has a click handler but no explicit type, so clicking it can also submit the form.',
|
|
38
41
|
'a11y-clickable-non-interactive': 'A click handler sits on a non-interactive element without a role and keyboard support, so keyboard users cannot activate it.',
|
|
39
42
|
'a11y-heading-level-skipped': 'A heading jumps more than one level down, which leaves a gap in the page outline.',
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// The accessibility rules over the shared element model; see markup.ts. Every rule favours silence: a spread, a dynamic
|
|
2
|
+
// value or a component may supply what the source does not show.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { testPathKind, workspaceScopedPath } from '../shared/analysis/execution-context.js';
|
|
1
5
|
import { closestAttributeName, closestRoleName, validAttributeNames, validRoleNames } from './aria-tables.js';
|
|
2
|
-
import { attributeNamed, serverTemplateMarker, staticAttributeText
|
|
6
|
+
import { attributeNamed, serverTemplateMarker, staticAttributeText } from './markup.js';
|
|
7
|
+
import { formAndLabelTargets, formMayDisableAutocomplete } from './form-context.js';
|
|
3
8
|
// Elements with no built-in keyboard behaviour; a click handler on one needs a role and a key handler.
|
|
4
9
|
const nonInteractiveTags = new Set([
|
|
5
10
|
'div',
|
|
@@ -92,6 +97,50 @@ function isHiddenFromAssistiveTechnology(element) {
|
|
|
92
97
|
function isCertainlyHidden(element) {
|
|
93
98
|
return staticAttributeText(element, 'hidden') !== undefined || isStaticValue(element, 'aria-hidden', 'true');
|
|
94
99
|
}
|
|
100
|
+
const tabbableControls = new Set(['button', 'select', 'textarea', 'input']);
|
|
101
|
+
function isKnownTabStop(element) {
|
|
102
|
+
const tabindex = attributeNamed(element, 'tabindex');
|
|
103
|
+
if (tabindex && (tabindex.value.kind !== 'static' || !/^\+?\d+$/.test(tabindex.value.text.trim())))
|
|
104
|
+
return false;
|
|
105
|
+
if (nonInteractiveTags.has(element.tagName))
|
|
106
|
+
return tabindex !== undefined;
|
|
107
|
+
if (element.tagName === 'a')
|
|
108
|
+
return tabindex !== undefined || staticAttributeText(element, 'href') !== undefined;
|
|
109
|
+
if (!tabbableControls.has(element.tagName) || hasAttribute(element, 'disabled'))
|
|
110
|
+
return false;
|
|
111
|
+
if (element.tagName !== 'input')
|
|
112
|
+
return true;
|
|
113
|
+
const type = attributeNamed(element, 'type');
|
|
114
|
+
return !type || (type.value.kind === 'static' && !['hidden', 'radio'].includes(type.value.text.trim().toLowerCase()));
|
|
115
|
+
}
|
|
116
|
+
function mayPreventTabFocus(element) {
|
|
117
|
+
return (!element.isIntrinsic ||
|
|
118
|
+
element.hasSpreadAttributes ||
|
|
119
|
+
hasAttribute(element, 'hidden') ||
|
|
120
|
+
hasAttribute(element, 'inert') ||
|
|
121
|
+
hasAttribute(element, 'style') ||
|
|
122
|
+
hasAttribute(element, 'popover') ||
|
|
123
|
+
hasAttribute(element, 'v-show') ||
|
|
124
|
+
element.tagName === 'template' ||
|
|
125
|
+
element.tagName === 'datalist' ||
|
|
126
|
+
element.tagName === 'iframe' ||
|
|
127
|
+
(element.tagName === 'fieldset' && hasAttribute(element, 'disabled')) ||
|
|
128
|
+
(['dialog', 'details'].includes(element.tagName) && staticAttributeText(element, 'open') === undefined));
|
|
129
|
+
}
|
|
130
|
+
function hasStaticAriaHidden(element) {
|
|
131
|
+
return isStaticValue(element, 'aria-hidden', 'true');
|
|
132
|
+
}
|
|
133
|
+
function ariaHiddenFocus(element, { document, ancestors }) {
|
|
134
|
+
if (!isKnownTabStop(element) || mayPreventTabFocus(element))
|
|
135
|
+
return [];
|
|
136
|
+
if (!hasStaticAriaHidden(element) && !ancestors.some(hasStaticAriaHidden))
|
|
137
|
+
return [];
|
|
138
|
+
if (ancestors.some(mayPreventTabFocus))
|
|
139
|
+
return [];
|
|
140
|
+
return [
|
|
141
|
+
finding(document, element, 'a11y-aria-hidden-focus', 'Keyboard users can tab to this control while aria-hidden removes it from the accessibility tree. Keep an interactive control exposed, or make hidden content inert.'),
|
|
142
|
+
];
|
|
143
|
+
}
|
|
95
144
|
function isPossiblyHidden(element) {
|
|
96
145
|
return hasAttribute(element, 'hidden') || isHiddenFromAssistiveTechnology(element);
|
|
97
146
|
}
|
|
@@ -107,22 +156,40 @@ function isPresentationalRole(element) {
|
|
|
107
156
|
return ['presentation', 'none'].includes(role.value.text.trim().toLowerCase());
|
|
108
157
|
}
|
|
109
158
|
function isImageWithoutAlt(element) {
|
|
110
|
-
if (element.tagName === 'input')
|
|
111
|
-
|
|
112
|
-
|
|
159
|
+
if (element.tagName === 'input' && isStaticValue(element, 'type', 'image')) {
|
|
160
|
+
const alt = attributeNamed(element, 'alt');
|
|
161
|
+
return !alt || (alt.value.kind === 'static' && !alt.value.text.trim());
|
|
162
|
+
}
|
|
163
|
+
const isLinkedArea = element.tagName === 'area' && hasAttribute(element, 'href');
|
|
164
|
+
return (element.tagName === 'img' || isLinkedArea) && !hasAttribute(element, 'alt');
|
|
113
165
|
}
|
|
114
|
-
|
|
166
|
+
function maySupplyName(element, name) {
|
|
167
|
+
const attribute = attributeNamed(element, name);
|
|
168
|
+
return !!attribute && (attribute.value.kind === 'dynamic' || !!attribute.value.text.trim());
|
|
169
|
+
}
|
|
170
|
+
const imgMissingAlt = (element, { document, ancestors, labelledIds, hasDynamicLabelFor }) => {
|
|
115
171
|
if (!element.isIntrinsic || element.hasSpreadAttributes || !isImageWithoutAlt(element))
|
|
116
172
|
return [];
|
|
117
|
-
if (
|
|
118
|
-
isPresentationalRole(element) ||
|
|
119
|
-
isHiddenFromAssistiveTechnology(element)) {
|
|
173
|
+
if (isHiddenFromAssistiveTechnology(element))
|
|
120
174
|
return [];
|
|
175
|
+
if (element.tagName === 'input') {
|
|
176
|
+
if (hasAttribute(element, 'hidden') || ancestors.some(isPossiblyHidden))
|
|
177
|
+
return [];
|
|
178
|
+
const id = attributeNamed(element, 'id');
|
|
179
|
+
if (['aria-label', 'aria-labelledby', 'title'].some((name) => maySupplyName(element, name)) ||
|
|
180
|
+
ancestors.some((ancestor) => !ancestor.isIntrinsic || ancestor.tagName === 'label') ||
|
|
181
|
+
(id && (hasDynamicLabelFor || id.value.kind === 'dynamic' || labelledIds.has(id.value.text))))
|
|
182
|
+
return [];
|
|
183
|
+
return [
|
|
184
|
+
finding(document, element, 'a11y-img-missing-alt', '<input type="image"> has no action name. Add alt text that describes what submitting the button does, such as alt="Search".'),
|
|
185
|
+
];
|
|
121
186
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
187
|
+
if (hasAccessibleNameAttribute(element) || isPresentationalRole(element))
|
|
188
|
+
return [];
|
|
189
|
+
const message = element.tagName === 'area'
|
|
190
|
+
? 'This image-map link has no alternative text. Add alt text that describes its destination.'
|
|
191
|
+
: '<img> has no alt attribute, so screen readers announce its file name or nothing. Add alt text that says what it shows, or alt="" when it is purely decorative.';
|
|
192
|
+
return [finding(document, element, 'a11y-img-missing-alt', message)];
|
|
126
193
|
};
|
|
127
194
|
// Only a button with its own click handler that the source shows inside a form (or tied to one by its form attribute)
|
|
128
195
|
// is reported: outside a form the default submit type does nothing, and a typeless button without a handler is usually
|
|
@@ -142,12 +209,35 @@ const buttonMissingType = (element, { document, ancestors }) => {
|
|
|
142
209
|
finding(document, element, 'a11y-button-missing-type', 'This <button> has a click handler but no type, so a click also submits its form. Add type="button" when the handler is all it should do, or type="submit" when it should submit.'),
|
|
143
210
|
];
|
|
144
211
|
};
|
|
145
|
-
const clickableNonInteractive = (element, { document }) => {
|
|
212
|
+
const clickableNonInteractive = (element, { document, ancestors }) => {
|
|
146
213
|
if (!element.isIntrinsic || !nonInteractiveTags.has(element.tagName) || element.hasSpreadAttributes)
|
|
147
214
|
return [];
|
|
148
|
-
if (!hasAttribute(element, 'onclick') ||
|
|
215
|
+
if (!hasAttribute(element, 'onclick') || isPossiblyHidden(element))
|
|
149
216
|
return [];
|
|
150
|
-
|
|
217
|
+
const role = attributeNamed(element, 'role');
|
|
218
|
+
const hasKeyHandler = keyHandlerNames.some((name) => hasAttribute(element, name));
|
|
219
|
+
if (role) {
|
|
220
|
+
if (!isStaticValue(element, 'role', 'button'))
|
|
221
|
+
return [];
|
|
222
|
+
if (ancestors.some((ancestor) => !ancestor.isIntrinsic || ancestor.hasSpreadAttributes || isPossiblyHidden(ancestor)))
|
|
223
|
+
return [];
|
|
224
|
+
const focus = attributeNamed(element, 'tabindex');
|
|
225
|
+
if (focus?.value.kind === 'dynamic' || hasAttribute(element, 'contenteditable'))
|
|
226
|
+
return [];
|
|
227
|
+
const hasTabStop = focus?.value.kind === 'static' && /^\+?\d+$/.test(focus.value.text.trim());
|
|
228
|
+
// A negative tabindex may be intentional for a roving focus pattern.
|
|
229
|
+
if (focus?.value.kind === 'static' && /^-\d+$/.test(focus.value.text.trim()))
|
|
230
|
+
return [];
|
|
231
|
+
if (hasTabStop && hasKeyHandler)
|
|
232
|
+
return [];
|
|
233
|
+
const missing = [!hasTabStop && 'a Tab stop', !hasKeyHandler && 'a keyboard activation handler']
|
|
234
|
+
.filter(Boolean)
|
|
235
|
+
.join(' and ');
|
|
236
|
+
return [
|
|
237
|
+
finding(document, element, 'a11y-clickable-non-interactive', `This custom button has a click handler, but its markup does not show ${missing}. Check for delegated handling. Prefer a native button, or support focus and activation with Enter and Space.`),
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
if (hasKeyHandler)
|
|
151
241
|
return [];
|
|
152
242
|
return [
|
|
153
243
|
finding(document, element, 'a11y-clickable-non-interactive', `A click handler on <${element.tagName}> cannot be reached or activated with a keyboard or announced by a screen reader. Use a <button>, or add a role, tabIndex and a key handler.`),
|
|
@@ -230,9 +320,20 @@ const htmlMissingLang = (element, { document }) => {
|
|
|
230
320
|
if (element.tagName !== 'html' || !element.isIntrinsic || element.hasSpreadAttributes)
|
|
231
321
|
return [];
|
|
232
322
|
if (staticAttributeText(element, 'lang')?.trim() === '' || !hasAttribute(element, 'lang')) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
323
|
+
const result = finding(document, element, 'a11y-html-missing-lang', 'The <html> element has no lang, so screen readers guess the language and may read the page with the wrong pronunciation. Add lang with the page language, such as lang="en".');
|
|
324
|
+
if (plainHtmlFile.test(document.file)) {
|
|
325
|
+
const scopedPath = path.isAbsolute(document.file)
|
|
326
|
+
? workspaceScopedPath(document.file)
|
|
327
|
+
: document.file.replaceAll('\\', '/');
|
|
328
|
+
const kind = testPathKind(scopedPath);
|
|
329
|
+
if (kind === 'fixture' && /(?:^|\/)(?:tests?|__tests__|specs?)\//i.test(scopedPath))
|
|
330
|
+
result.contextualReason = 'HTML fixture for tests; verify whether this document is served to users.';
|
|
331
|
+
else if (kind === 'test-directory' &&
|
|
332
|
+
/<td\s[^>]*\bdata-t=/i.test(document.text) &&
|
|
333
|
+
/<title>SheetJS Table Export<\/title>/i.test(document.text))
|
|
334
|
+
result.contextualReason = 'Spreadsheet data exported as an HTML table for a test.';
|
|
335
|
+
}
|
|
336
|
+
return [result];
|
|
236
337
|
}
|
|
237
338
|
return [];
|
|
238
339
|
};
|
|
@@ -272,7 +373,7 @@ function viewportDirectives(content) {
|
|
|
272
373
|
}
|
|
273
374
|
function zoomRestriction(directives) {
|
|
274
375
|
const userScalable = directives.get('user-scalable');
|
|
275
|
-
if (userScalable === 'no' || userScalable === '0')
|
|
376
|
+
if (userScalable === 'no' || userScalable === '0' || userScalable === 'false')
|
|
276
377
|
return `user-scalable=${userScalable}`;
|
|
277
378
|
const maximumScaleText = directives.get('maximum-scale');
|
|
278
379
|
const maximumScale = maximumScaleText === undefined ? Number.NaN : Number.parseFloat(maximumScaleText);
|
|
@@ -288,7 +389,7 @@ const viewportZoomDisabled = (element, { document }) => {
|
|
|
288
389
|
if (!restriction)
|
|
289
390
|
return [];
|
|
290
391
|
return [
|
|
291
|
-
finding(document, element, 'a11y-viewport-zoom-disabled', `The viewport meta tag sets ${restriction},
|
|
392
|
+
finding(document, element, 'a11y-viewport-zoom-disabled', `The viewport meta tag sets ${restriction}, which can limit pinch zoom in the document where it is rendered. Remove it, or allow a maximum-scale of at least 2.`),
|
|
292
393
|
];
|
|
293
394
|
};
|
|
294
395
|
function normalizedLinkText(text) {
|
|
@@ -360,20 +461,21 @@ function isPersonalDataInput(element) {
|
|
|
360
461
|
return false;
|
|
361
462
|
return hasPersonalDataName(element);
|
|
362
463
|
}
|
|
363
|
-
const inputMissingAutocomplete = (element,
|
|
464
|
+
const inputMissingAutocomplete = (element, context) => {
|
|
364
465
|
if (element.tagName !== 'input' || !element.isIntrinsic || element.hasSpreadAttributes)
|
|
365
466
|
return [];
|
|
366
|
-
|
|
467
|
+
const autocomplete = attributeNamed(element, 'autocomplete');
|
|
468
|
+
if (autocomplete?.value.kind === 'dynamic' || autocomplete?.value.text.trim() || hasAttribute(element, 'hidden'))
|
|
367
469
|
return [];
|
|
368
470
|
if (hasAttribute(element, 'disabled') || hasAttribute(element, 'readonly'))
|
|
369
471
|
return [];
|
|
370
472
|
// A field that already holds a value edits existing data, such as a settings or admin form, not the visitor's own details.
|
|
371
473
|
if (hasExistingValue(element))
|
|
372
474
|
return [];
|
|
373
|
-
if (!isPersonalDataInput(element))
|
|
475
|
+
if (!isPersonalDataInput(element) || formMayDisableAutocomplete(element, context))
|
|
374
476
|
return [];
|
|
375
477
|
return [
|
|
376
|
-
finding(document, element, 'a11y-input-missing-autocomplete', 'This input asks for personal data but has no autocomplete, so browsers and assistive technology cannot fill it in for people who find typing hard. Add autocomplete with the matching token, such as autocomplete="email".'),
|
|
478
|
+
finding(context.document, element, 'a11y-input-missing-autocomplete', 'This input asks for personal data but has no autocomplete, so browsers and assistive technology cannot fill it in for people who find typing hard. Add autocomplete with the matching token, such as autocomplete="email".'),
|
|
377
479
|
];
|
|
378
480
|
};
|
|
379
481
|
const elementRules = [
|
|
@@ -384,28 +486,13 @@ const elementRules = [
|
|
|
384
486
|
missingFormLabel,
|
|
385
487
|
htmlMissingLang,
|
|
386
488
|
iframeMissingTitle,
|
|
489
|
+
ariaHiddenFocus,
|
|
387
490
|
positiveTabindex,
|
|
388
491
|
viewportZoomDisabled,
|
|
389
492
|
linkTextNotDescriptive,
|
|
390
493
|
mediaAutoplay,
|
|
391
494
|
inputMissingAutocomplete,
|
|
392
495
|
];
|
|
393
|
-
function isLabelLike(element) {
|
|
394
|
-
return element.tagName === 'label' || !element.isIntrinsic;
|
|
395
|
-
}
|
|
396
|
-
// Labels of components count too: a `<Label htmlFor="x">` names the control with that id just as a `<label>` does.
|
|
397
|
-
function labelTargets(document) {
|
|
398
|
-
const labelledIds = new Set();
|
|
399
|
-
let hasDynamicLabelFor = false;
|
|
400
|
-
for (const element of walkElements(document.roots)) {
|
|
401
|
-
const target = isLabelLike(element) ? attributeNamed(element, 'for') : undefined;
|
|
402
|
-
if (target?.value.kind === 'static')
|
|
403
|
-
labelledIds.add(target.value.text);
|
|
404
|
-
else if (target)
|
|
405
|
-
hasDynamicLabelFor = true;
|
|
406
|
-
}
|
|
407
|
-
return { labelledIds, hasDynamicLabelFor };
|
|
408
|
-
}
|
|
409
496
|
// `context.ancestors` is this same stack, so one array serves every element instead of a copy per element.
|
|
410
497
|
function checkElement(element, context, stack, findings) {
|
|
411
498
|
for (const rule of elementRules)
|
|
@@ -477,7 +564,7 @@ function checkMarkup(document) {
|
|
|
477
564
|
const context = {
|
|
478
565
|
document,
|
|
479
566
|
ancestors: stack,
|
|
480
|
-
...
|
|
567
|
+
...formAndLabelTargets(document),
|
|
481
568
|
includesOtherTemplates: includesOtherTemplates(document),
|
|
482
569
|
};
|
|
483
570
|
const findings = [];
|
|
@@ -20,7 +20,11 @@ function buttonTypeFix({ finding, text, load }) {
|
|
|
20
20
|
if (source === undefined)
|
|
21
21
|
return;
|
|
22
22
|
const start = offsetOf(source, line, column);
|
|
23
|
-
if (start === undefined
|
|
23
|
+
if (start === undefined)
|
|
24
|
+
return;
|
|
25
|
+
const opening = source.slice(start, start + buttonTagOpening.length);
|
|
26
|
+
const isHtml = typeof file === 'string' && /\.html?$/i.test(file);
|
|
27
|
+
if ((isHtml ? opening.toLowerCase() : opening) !== buttonTagOpening)
|
|
24
28
|
return;
|
|
25
29
|
const tagNameEnd = start + buttonTagOpening.length;
|
|
26
30
|
if (tagNameCharacter.test(source.charAt(tagNameEnd)))
|
|
@@ -24,7 +24,7 @@ function hasInterpolation(dialect, value) {
|
|
|
24
24
|
const propagationOnlyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?(?:\{\s*)?(?:[\w$]+\.(?:stopPropagation|preventDefault)\(\)\s*(?:;\s*)?)+(?:\}\s*)?$/;
|
|
25
25
|
// `@click="() => {}"` does nothing, so it is no more a way to activate the element than a propagation-only handler. A
|
|
26
26
|
// Svelte `on:click={…}` value keeps its closing brace, hence the optional second one.
|
|
27
|
-
const emptyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?\{\s*\}\
|
|
27
|
+
const emptyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?\{\s*\}\s*$/;
|
|
28
28
|
function eventAttribute(event, rawValue, isBareAllowed) {
|
|
29
29
|
const isBare = rawValue === undefined || rawValue.trim() === '';
|
|
30
30
|
if (isBare && isBareAllowed)
|
|
@@ -45,7 +45,9 @@ function plainAttribute(dialect, name, rawValue, isBraced) {
|
|
|
45
45
|
return { kind: 'attribute', name, value: { kind: 'static', text: rawValue ?? '' } };
|
|
46
46
|
}
|
|
47
47
|
// The few directives the rules read: what fills the element at runtime, and whether it renders at all.
|
|
48
|
-
function keptDirective(name) {
|
|
48
|
+
function keptDirective(name, rawValue) {
|
|
49
|
+
if (withoutModifiers(name) === 'v-show')
|
|
50
|
+
return rawValue?.trim() === 'true' ? ignored : { kind: 'conditional', visibilityDirective: 'v-show' };
|
|
49
51
|
if (vueContentDirectives.has(name))
|
|
50
52
|
return dynamicAttribute(name);
|
|
51
53
|
return conditionalDirectiveNames.has(name) ? conditional : undefined;
|
|
@@ -69,7 +71,7 @@ function vueAttribute(name, rawValue, plain) {
|
|
|
69
71
|
if (name.startsWith('v-model:'))
|
|
70
72
|
return dynamicAttribute(withoutModifiers(name.slice(8)));
|
|
71
73
|
if (name.startsWith('v-') || name.startsWith('#'))
|
|
72
|
-
return keptDirective(name) ?? ignored;
|
|
74
|
+
return keptDirective(name, rawValue) ?? ignored;
|
|
73
75
|
return plain();
|
|
74
76
|
}
|
|
75
77
|
// `[ariaLabel]` and `[htmlFor]` are DOM property names; rules compare attribute names. An `aria…` input that is no
|
|
@@ -86,16 +86,18 @@ class TemplateParser {
|
|
|
86
86
|
text;
|
|
87
87
|
dialect;
|
|
88
88
|
end;
|
|
89
|
+
sourcePosition;
|
|
89
90
|
position;
|
|
90
91
|
lineStarts;
|
|
91
92
|
stack;
|
|
92
93
|
lastIndexByNeedle = new Map();
|
|
93
|
-
constructor(text, dialect, start, end) {
|
|
94
|
+
constructor(text, dialect, start, end, sourcePosition) {
|
|
94
95
|
this.text = text;
|
|
95
96
|
this.dialect = dialect;
|
|
96
97
|
this.end = end;
|
|
98
|
+
this.sourcePosition = sourcePosition;
|
|
97
99
|
this.position = start;
|
|
98
|
-
this.lineStarts = lineStartOffsets(text);
|
|
100
|
+
this.lineStarts = sourcePosition ? [] : lineStartOffsets(text);
|
|
99
101
|
this.stack = [
|
|
100
102
|
this.openElement({
|
|
101
103
|
tagName: '',
|
|
@@ -108,10 +110,12 @@ class TemplateParser {
|
|
|
108
110
|
}),
|
|
109
111
|
];
|
|
110
112
|
}
|
|
111
|
-
parse() {
|
|
113
|
+
parse(singleRoot = false) {
|
|
112
114
|
while (this.position < this.end) {
|
|
113
115
|
const next = this.readConstruct(this.position);
|
|
114
116
|
this.position = next === -1 ? this.position + 1 : next;
|
|
117
|
+
if (singleRoot && this.stack.length === 1)
|
|
118
|
+
break;
|
|
115
119
|
}
|
|
116
120
|
this.closeDownTo(1);
|
|
117
121
|
return this.stack[0].children;
|
|
@@ -120,6 +124,8 @@ class TemplateParser {
|
|
|
120
124
|
return this.stack[this.stack.length - 1];
|
|
121
125
|
}
|
|
122
126
|
lineAndColumn(offset) {
|
|
127
|
+
if (this.sourcePosition)
|
|
128
|
+
return this.sourcePosition(offset);
|
|
123
129
|
let low = 0;
|
|
124
130
|
let high = this.lineStarts.length - 1;
|
|
125
131
|
while (low < high) {
|
|
@@ -415,7 +421,7 @@ class TemplateParser {
|
|
|
415
421
|
if (opener === '{' && this.dialect === 'svelte') {
|
|
416
422
|
const close = this.closingBrace(index);
|
|
417
423
|
const valueEnd = close === -1 ? this.end : close;
|
|
418
|
-
return { value: this.text.slice(index + 1, valueEnd), isBraced: true, next: valueEnd };
|
|
424
|
+
return { value: this.text.slice(index + 1, close === -1 ? valueEnd : close - 1), isBraced: true, next: valueEnd };
|
|
419
425
|
}
|
|
420
426
|
let valueEnd = index;
|
|
421
427
|
while (valueEnd < this.end && !isWhitespace(this.text[valueEnd]) && this.text[valueEnd] !== '>')
|
|
@@ -431,8 +437,13 @@ class TemplateParser {
|
|
|
431
437
|
record(parsed, nameOffset, normalized) {
|
|
432
438
|
if (normalized.kind === 'spread')
|
|
433
439
|
parsed.hasSpreadAttributes = true;
|
|
434
|
-
else if (normalized.kind === 'conditional')
|
|
440
|
+
else if (normalized.kind === 'conditional') {
|
|
435
441
|
parsed.isConditional = true;
|
|
442
|
+
if (normalized.visibilityDirective) {
|
|
443
|
+
const position = this.lineAndColumn(nameOffset);
|
|
444
|
+
parsed.attributes.push({ name: normalized.visibilityDirective, value: { kind: 'dynamic' }, ...position });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
436
447
|
else if (normalized.kind === 'attribute') {
|
|
437
448
|
const { line, column } = this.lineAndColumn(nameOffset);
|
|
438
449
|
parsed.attributes.push({ name: normalized.name, value: normalized.value, line, column });
|
|
@@ -448,4 +459,12 @@ function templateDocument(file, text, dialect, start = 0, end = text.length) {
|
|
|
448
459
|
const roots = new TemplateParser(text, dialect, start, Math.min(end, text.length)).parse();
|
|
449
460
|
return { file, roots, text };
|
|
450
461
|
}
|
|
451
|
-
|
|
462
|
+
/** Parse the selected SFC block until its matching end tag, using the markup parser's normal token boundaries. */
|
|
463
|
+
function vueBlockDocument(file, text, start) {
|
|
464
|
+
return { file, text, roots: new TemplateParser(text, 'vue', start, text.length).parse(true) };
|
|
465
|
+
}
|
|
466
|
+
function mappedAngularDocument(file, text, sourcePosition) {
|
|
467
|
+
const roots = new TemplateParser(text, 'angular', 0, text.length, sourcePosition).parse();
|
|
468
|
+
return { file, text, roots };
|
|
469
|
+
}
|
|
470
|
+
export { templateDocument, mappedAngularDocument, vueBlockDocument };
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { reviewMarkers } from '../performance/analysis/review-context.js';
|
|
5
5
|
import { isVendoredMinified } from '../shared/analysis/execution-context.js';
|
|
6
6
|
import { checkMarkup } from './rules.js';
|
|
7
|
-
import { templateDocument } from './template-elements.js';
|
|
7
|
+
import { templateDocument, vueBlockDocument } from './template-elements.js';
|
|
8
8
|
// A line this long is a bundler's output, not hand-written markup.
|
|
9
9
|
const minifiedLineLength = 5000;
|
|
10
10
|
const generatedHeaderLength = 2048;
|
|
@@ -18,7 +18,6 @@ const angularComponentTemplatePattern = /\.component\.html?$/i;
|
|
|
18
18
|
const templateUrlPattern = /templateUrl\s*:\s*['"`]([^'"`]+)['"`]/g;
|
|
19
19
|
const openingTagStartPattern = /^<([A-Za-z][\w-]*)/;
|
|
20
20
|
const reviewCommentPattern = /<!--\s*loadwise-reviewed\s+([a-z][a-z0-9-]*)\s+--\s+(\S.*?)\s*-->/;
|
|
21
|
-
const templateTagPattern = /<(\/?)template\b/gi;
|
|
22
21
|
function hasMinifiedLine(text) {
|
|
23
22
|
let lineStart = 0;
|
|
24
23
|
while (lineStart < text.length) {
|
|
@@ -88,24 +87,29 @@ function openingTagEnd(text, tagStart) {
|
|
|
88
87
|
}
|
|
89
88
|
return -1;
|
|
90
89
|
}
|
|
91
|
-
function templateBlockEnd(text, contentStart) {
|
|
92
|
-
templateTagPattern.lastIndex = contentStart;
|
|
93
|
-
let depth = 1;
|
|
94
|
-
for (let tag = templateTagPattern.exec(text); tag; tag = templateTagPattern.exec(text)) {
|
|
95
|
-
depth += tag[1] ? -1 : 1;
|
|
96
|
-
if (depth === 0)
|
|
97
|
-
return tag.index;
|
|
98
|
-
}
|
|
99
|
-
return text.length;
|
|
100
|
-
}
|
|
101
90
|
function skipBlock(text, name, from) {
|
|
102
91
|
const closing = new RegExp(`</${name}\\s*>`, 'ig');
|
|
103
92
|
closing.lastIndex = from;
|
|
104
93
|
const match = closing.exec(text);
|
|
105
94
|
return match ? match.index + match[0].length : -1;
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
class UnsupportedVuePreprocessorError extends Error {
|
|
97
|
+
constructor(language) {
|
|
98
|
+
super(`Vue template uses unsupported preprocessor lang=${JSON.stringify(language)}`);
|
|
99
|
+
this.name = 'UnsupportedVuePreprocessorError';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** The value of the exact `lang` attribute of an opening tag; ignores `data-lang` and text inside other quoted values. */
|
|
103
|
+
function langAttribute(openingTag) {
|
|
104
|
+
const attributePattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
105
|
+
for (const match of openingTag.slice(1).matchAll(attributePattern)) {
|
|
106
|
+
if (match[1].toLowerCase() === 'lang')
|
|
107
|
+
return match[2] ?? match[3] ?? match[4];
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
/** The content of the top-level `<template>` block of a .vue file; undefined when absent. Throws on unsupported `lang`. */
|
|
112
|
+
function vueTemplateStart(text) {
|
|
109
113
|
let index = 0;
|
|
110
114
|
while (index < text.length) {
|
|
111
115
|
const tagStart = text.indexOf('<', index);
|
|
@@ -125,10 +129,10 @@ function vueTemplateRegion(text) {
|
|
|
125
129
|
continue;
|
|
126
130
|
}
|
|
127
131
|
if (name.toLowerCase() === 'template') {
|
|
128
|
-
const language =
|
|
132
|
+
const language = langAttribute(text.slice(tagStart, tagEnd));
|
|
129
133
|
if (language && language.toLowerCase() !== 'html')
|
|
130
|
-
|
|
131
|
-
return
|
|
134
|
+
throw new UnsupportedVuePreprocessorError(language);
|
|
135
|
+
return tagStart;
|
|
132
136
|
}
|
|
133
137
|
if (text[tagEnd - 2] === '/') {
|
|
134
138
|
index = tagEnd;
|
|
@@ -149,8 +153,8 @@ function markupDocument(file, text) {
|
|
|
149
153
|
if (extension === '.svelte')
|
|
150
154
|
return templateDocument(file, text, 'svelte');
|
|
151
155
|
if (extension === '.vue') {
|
|
152
|
-
const
|
|
153
|
-
return
|
|
156
|
+
const start = vueTemplateStart(text);
|
|
157
|
+
return start === undefined ? undefined : vueBlockDocument(file, text, start);
|
|
154
158
|
}
|
|
155
159
|
if (extension === '.html' || extension === '.htm')
|
|
156
160
|
return templateDocument(file, text, htmlDialect(file));
|
|
@@ -174,10 +178,21 @@ function withReviewedReasons(text, findings) {
|
|
|
174
178
|
return reason ? { ...finding, contextualReason: reason } : finding;
|
|
175
179
|
});
|
|
176
180
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
function analyzeTemplateFile(file, text) {
|
|
182
|
+
try {
|
|
183
|
+
// Checked before the markup filter so an unsupported template is reported even in a file the filter would drop.
|
|
184
|
+
if (path.extname(file).toLowerCase() === '.vue')
|
|
185
|
+
vueTemplateStart(text);
|
|
186
|
+
if (isSkippedMarkup(file, text))
|
|
187
|
+
return { findings: [] };
|
|
188
|
+
const document = markupDocument(file, text);
|
|
189
|
+
return { findings: document ? withReviewedReasons(text, checkMarkup(document)) : [] };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (error instanceof UnsupportedVuePreprocessorError) {
|
|
193
|
+
return { findings: [], skipReason: error.message };
|
|
194
|
+
}
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
182
197
|
}
|
|
183
|
-
export {
|
|
198
|
+
export { analyzeTemplateFile };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
2
2
|
const examples = {
|
|
3
|
+
'a11y-aria-hidden-focus': {
|
|
4
|
+
jsx: { before: '<button aria-hidden="true">Close</button>', code: '<button>Close</button>' },
|
|
5
|
+
html: { before: '<button aria-hidden="true">Close</button>', code: '<button>Close</button>' },
|
|
6
|
+
note: 'Expose the control if it is interactive. If the entire region is inactive, consider making it inert.',
|
|
7
|
+
},
|
|
3
8
|
'a11y-button-missing-type': {
|
|
4
9
|
jsx: {
|
|
5
10
|
before: '<button onClick={save}>Save</button>',
|
|
@@ -43,7 +48,7 @@ const examples = {
|
|
|
43
48
|
'a11y-img-missing-alt': {
|
|
44
49
|
jsx: { before: '<img src={logo} />', code: '<img src={logo} alt="Company logo" />' },
|
|
45
50
|
html: { before: '<img src="logo.png">', code: '<img src="logo.png" alt="Company logo">' },
|
|
46
|
-
note: '
|
|
51
|
+
note: 'For an image submit button, describe its action, for example alt="Search". Reserve empty alt text for decorative images.',
|
|
47
52
|
},
|
|
48
53
|
'a11y-input-missing-autocomplete': {
|
|
49
54
|
jsx: { before: '<input type="email" />', code: '<input type="email" autoComplete="email" />' },
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Code actions and code lenses for the published findings of one file.
|
|
2
2
|
import { CodeActionKind } from 'vscode-languageserver';
|
|
3
|
+
import { locateChange } from './apply-fix.js';
|
|
4
|
+
import { samePosition } from './editor-document.js';
|
|
3
5
|
import { bulkFixesFor, fixAllEdit, fixEdit, missingFolders } from './fix-edits.js';
|
|
4
6
|
const commands = {
|
|
5
7
|
scan: 'loadwise.scan',
|
|
@@ -18,8 +20,7 @@ function kindRequested(only, kind) {
|
|
|
18
20
|
return only.some((requested) => kind === requested || kind.startsWith(requested + '.'));
|
|
19
21
|
}
|
|
20
22
|
// The lightbulb appears with the cursor anywhere on a flagged line, not only on the reported token.
|
|
21
|
-
function onLines(
|
|
22
|
-
const flagged = entry.diagnostic.range;
|
|
23
|
+
function onLines(flagged, range) {
|
|
23
24
|
return flagged.start.line <= range.end.line && flagged.end.line >= range.start.line;
|
|
24
25
|
}
|
|
25
26
|
function command(title, name, argument) {
|
|
@@ -33,6 +34,22 @@ function applyFixAction(entry, fix, workspace) {
|
|
|
33
34
|
diagnostics: [entry.diagnostic],
|
|
34
35
|
isPreferred: !fix.requiresReview,
|
|
35
36
|
};
|
|
37
|
+
const shiftedLine = entry.diagnostic.range.start.line;
|
|
38
|
+
if (shiftedLine !== entry.anchor.line - 1) {
|
|
39
|
+
const [change] = fix.changes;
|
|
40
|
+
const document = workspace.documentFor(entry.filename);
|
|
41
|
+
const relativeLine = change ? entry.anchor.line - change.line : -1;
|
|
42
|
+
const lines = document?.getText().split(/\r?\n/);
|
|
43
|
+
if (fix.changes.length !== 1 ||
|
|
44
|
+
change.create ||
|
|
45
|
+
workspace.keyOf(change.filename) !== workspace.keyOf(entry.filename) ||
|
|
46
|
+
relativeLine < 0 ||
|
|
47
|
+
relativeLine >= change.before.split(/\r?\n/).length ||
|
|
48
|
+
!lines ||
|
|
49
|
+
locateChange(lines, change) !== shiftedLine - relativeLine) {
|
|
50
|
+
return { ...action, disabled: { reason: 'Save and rescan to verify the edit target for this moved finding.' } };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
36
53
|
const result = fixEdit(fix, workspace);
|
|
37
54
|
if (result.edit === undefined)
|
|
38
55
|
action.disabled = { reason: result.error };
|
|
@@ -51,10 +68,10 @@ function dismissAction(entry, title, dismissal) {
|
|
|
51
68
|
command: command(title, commands.dismiss, dismissal),
|
|
52
69
|
};
|
|
53
70
|
}
|
|
54
|
-
function quickFixes(entries,
|
|
71
|
+
function quickFixes(entries, selected, uri, workspace) {
|
|
55
72
|
const actions = [];
|
|
56
73
|
const fileWide = new Set();
|
|
57
|
-
for (const entry of
|
|
74
|
+
for (const entry of selected) {
|
|
58
75
|
const { fix, dismissal, ruleId } = entry.anchor;
|
|
59
76
|
if (fix)
|
|
60
77
|
actions.push(applyFixAction(entry, fix, workspace));
|
|
@@ -64,7 +81,7 @@ function quickFixes(entries, range, uri, workspace) {
|
|
|
64
81
|
fileWide.add(ruleId);
|
|
65
82
|
actions.push(dismissAction(entry, 'Dismiss ' + ruleId + ' in this file', { file: dismissal.file, ruleId: dismissal.ruleId }));
|
|
66
83
|
}
|
|
67
|
-
if (actions.length && bulkFixesFor(entries).eligible.length > 1) {
|
|
84
|
+
if (actions.length && !actions.some((action) => action.disabled) && bulkFixesFor(entries).eligible.length > 1) {
|
|
68
85
|
actions.push({
|
|
69
86
|
title: applyAllTitle,
|
|
70
87
|
kind: CodeActionKind.QuickFix,
|
|
@@ -86,10 +103,32 @@ function fixAllActions(entries, uri, workspace) {
|
|
|
86
103
|
}
|
|
87
104
|
return [{ title: applyAllTitle, kind: fixAllKind, edit }];
|
|
88
105
|
}
|
|
89
|
-
function
|
|
106
|
+
function findingsForAction(entries, range, diagnostics) {
|
|
107
|
+
if (!diagnostics.length)
|
|
108
|
+
return entries.filter((entry) => onLines(entry.diagnostic.range, range));
|
|
109
|
+
const selected = new Map();
|
|
110
|
+
for (const diagnostic of diagnostics) {
|
|
111
|
+
if (!onLines(diagnostic.range, range))
|
|
112
|
+
continue;
|
|
113
|
+
const matches = entries.filter(({ diagnostic: saved }) => saved.source === diagnostic.source &&
|
|
114
|
+
saved.code === diagnostic.code &&
|
|
115
|
+
(diagnostic.data !== undefined ? diagnostic.data === saved.data : diagnostic.message === saved.message));
|
|
116
|
+
// Without an echoed identity, identical diagnostics cannot safely identify a moved occurrence.
|
|
117
|
+
if (matches.length !== 1)
|
|
118
|
+
continue;
|
|
119
|
+
const [entry] = matches;
|
|
120
|
+
const published = entry.diagnostic.range;
|
|
121
|
+
if (diagnostic.data === undefined &&
|
|
122
|
+
(!samePosition(published.start, diagnostic.range.start) || !samePosition(published.end, diagnostic.range.end)))
|
|
123
|
+
continue;
|
|
124
|
+
selected.set(entry, { ...entry, diagnostic: { ...entry.diagnostic, range: diagnostic.range } });
|
|
125
|
+
}
|
|
126
|
+
return [...selected.values()];
|
|
127
|
+
}
|
|
128
|
+
function codeActions(entries, { range, context: { only, diagnostics }, textDocument: { uri } }, workspace) {
|
|
90
129
|
const actions = [];
|
|
91
130
|
if (kindRequested(only, CodeActionKind.QuickFix))
|
|
92
|
-
actions.push(...quickFixes(entries, range, uri, workspace));
|
|
131
|
+
actions.push(...quickFixes(entries, findingsForAction(entries, range, diagnostics), uri, workspace));
|
|
93
132
|
// Building the fix-all edit reads files, so it runs only when the editor asks for that kind.
|
|
94
133
|
if (only && kindRequested(only, fixAllKind))
|
|
95
134
|
actions.push(...fixAllActions(entries, uri, workspace));
|