loadwise 0.6.2 → 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.
Files changed (278) hide show
  1. package/README.md +175 -115
  2. package/dist/bin/loadwise.js +132 -67
  3. package/dist/lib/accessibility/analyze.js +5 -3
  4. package/dist/lib/accessibility/angular-inline.js +9 -11
  5. package/dist/lib/accessibility/angular-literal.js +39 -0
  6. package/dist/lib/accessibility/form-context.js +36 -0
  7. package/dist/lib/accessibility/frame-head.js +92 -0
  8. package/dist/lib/accessibility/frame-viewport.js +149 -0
  9. package/dist/lib/accessibility/frontend-detect.js +6 -5
  10. package/dist/lib/accessibility/jsx-elements.js +13 -3
  11. package/dist/lib/accessibility/markup-files.js +7 -2
  12. package/dist/lib/accessibility/rule-ids.js +3 -0
  13. package/dist/lib/accessibility/rules.js +128 -41
  14. package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
  15. package/dist/lib/accessibility/template-attributes.js +5 -3
  16. package/dist/lib/accessibility/template-elements.js +25 -6
  17. package/dist/lib/accessibility/template-file.js +40 -25
  18. package/dist/lib/accessibility/usage.js +10 -2
  19. package/dist/lib/editor/accessibility-examples.js +6 -1
  20. package/dist/lib/editor/actions.js +46 -7
  21. package/dist/lib/editor/apply-fix.js +69 -4
  22. package/dist/lib/editor/configured-setup.js +63 -0
  23. package/dist/lib/editor/diagnostics.js +206 -17
  24. package/dist/lib/editor/dismissals.js +85 -26
  25. package/dist/lib/editor/editor-document.js +5 -2
  26. package/dist/lib/editor/editor-launcher.js +170 -0
  27. package/dist/lib/editor/fix-edits.js +19 -0
  28. package/dist/lib/editor/jetbrains-setup.js +53 -0
  29. package/dist/lib/editor/language-server.js +80 -24
  30. package/dist/lib/editor/managed-config.js +37 -0
  31. package/dist/lib/editor/native-setup.js +86 -0
  32. package/dist/lib/editor/perf-watch.js +8 -6
  33. package/dist/lib/editor/release-vsix.js +61 -0
  34. package/dist/lib/editor/reliability-examples.js +15 -0
  35. package/dist/lib/editor/scan-session.js +29 -8
  36. package/dist/lib/editor/server-commands.js +38 -9
  37. package/dist/lib/editor/setup-server.js +87 -0
  38. package/dist/lib/editor/setup-vim.js +63 -0
  39. package/dist/lib/editor/setup.js +131 -0
  40. package/dist/lib/editor/stdio-setup.js +6 -0
  41. package/dist/lib/editor/workspace-files.js +61 -7
  42. package/dist/lib/editor/workspace-paths.js +41 -1
  43. package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
  44. package/dist/lib/maintainability/architecture/architecture.js +4 -4
  45. package/dist/lib/maintainability/cli/changed-lines.js +20 -2
  46. package/dist/lib/maintainability/cli/inputs.js +12 -3
  47. package/dist/lib/maintainability/cli.js +18 -5
  48. package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
  49. package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
  50. package/dist/lib/maintainability/examples.js +4 -0
  51. package/dist/lib/maintainability/quality/functions.js +9 -6
  52. package/dist/lib/maintainability/quality/limits.js +19 -0
  53. package/dist/lib/maintainability/quality/size-limits.js +8 -2
  54. package/dist/lib/maintainability/quality/stray-console.js +62 -1
  55. package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
  56. package/dist/lib/maintainability/rule-ids.js +3 -0
  57. package/dist/lib/maintainability/scan-changed.js +4 -1
  58. package/dist/lib/maintainability/scan-worker.js +6 -2
  59. package/dist/lib/maintainability/scan.js +21 -8
  60. package/dist/lib/maintainability/site-fixes/unused-bindings.js +138 -3
  61. package/dist/lib/maintainability/unused/module-usage.js +43 -21
  62. package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
  63. package/dist/lib/maintainability/unused/unused-modules.js +5 -10
  64. package/dist/lib/performance/analysis/source-inputs.js +7 -2
  65. package/dist/lib/performance/analysis/source-options.js +7 -6
  66. package/dist/lib/performance/analyze.js +16 -3
  67. package/dist/lib/performance/cli/changed-lines.js +8 -1
  68. package/dist/lib/performance/cli/cli-arguments.js +19 -8
  69. package/dist/lib/performance/cli/cli-output.js +4 -0
  70. package/dist/lib/performance/cli/cli-scan.js +21 -2
  71. package/dist/lib/performance/cli.js +16 -7
  72. package/dist/lib/performance/collections/memory-growth.js +55 -12
  73. package/dist/lib/performance/contracts/openapi.js +13 -4
  74. package/dist/lib/performance/datastores/pg-integrity.js +68 -22
  75. package/dist/lib/performance/datastores/pg-session-release.js +114 -0
  76. package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
  77. package/dist/lib/performance/datastores/pooling.js +62 -3
  78. package/dist/lib/performance/datastores/redis.js +94 -18
  79. package/dist/lib/performance/datastores/session-store.js +2 -1
  80. package/dist/lib/performance/db/checks.js +19 -8
  81. package/dist/lib/performance/db/gateway.js +3 -1
  82. package/dist/lib/performance/db/plan-estimates.js +4 -4
  83. package/dist/lib/performance/engine/native-syntax.js +3 -0
  84. package/dist/lib/performance/engine/native.js +11 -7
  85. package/dist/lib/performance/evidence/plans.js +7 -5
  86. package/dist/lib/performance/evidence/traces.js +21 -1
  87. package/dist/lib/performance/frontend/angular-teardown.js +96 -0
  88. package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
  89. package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
  90. package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
  91. package/dist/lib/performance/frontend/frontend-perf.js +149 -74
  92. package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
  93. package/dist/lib/performance/migrations/extract-code.js +13 -5
  94. package/dist/lib/performance/migrations/extract-sql.js +82 -38
  95. package/dist/lib/performance/migrations/operations.js +56 -13
  96. package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
  97. package/dist/lib/performance/migrations/postgres-registry.js +127 -26
  98. package/dist/lib/performance/migrations/postgres-settings.js +78 -0
  99. package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
  100. package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
  101. package/dist/lib/performance/migrations/rules-postgres.js +88 -39
  102. package/dist/lib/performance/orm/offset-pagination.js +6 -4
  103. package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
  104. package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
  105. package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
  106. package/dist/lib/performance/polyglot.js +111 -14
  107. package/dist/lib/performance/projects.js +3 -3
  108. package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
  109. package/dist/lib/performance/request/backend-mastery.js +151 -42
  110. package/dist/lib/performance/request/bulk-listener-registration.js +111 -0
  111. package/dist/lib/performance/request/fastify-receivers.js +93 -0
  112. package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
  113. package/dist/lib/performance/request/mongoose-lean.js +298 -46
  114. package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
  115. package/dist/lib/performance/request/phase5-ast.js +6 -7
  116. package/dist/lib/performance/request/phase5-rules.js +204 -23
  117. package/dist/lib/performance/request/request-handlers.js +120 -23
  118. package/dist/lib/performance/request/sql-select-star.js +150 -0
  119. package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
  120. package/dist/lib/performance/request/upload-limits.js +5 -1
  121. package/dist/lib/performance/site-fix.js +4 -4
  122. package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
  123. package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
  124. package/dist/lib/performance/site-fixes/collections.js +1 -2
  125. package/dist/lib/performance/site-fixes/frontend-fixes.js +358 -14
  126. package/dist/lib/performance/site-fixes/helpers.js +3 -4
  127. package/dist/lib/performance/site-fixes/integrity.js +2 -4
  128. package/dist/lib/performance/site-fixes/migration-context.js +8 -1
  129. package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
  130. package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
  131. package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
  132. package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
  133. package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
  134. package/dist/lib/performance/sql/mysql-tokens.js +38 -12
  135. package/dist/lib/reliability/boundary-access.js +114 -57
  136. package/dist/lib/reliability/react-bugs.js +29 -7
  137. package/dist/lib/reliability/resource-leak-intervals.js +258 -0
  138. package/dist/lib/reliability/resource-leaks.js +209 -195
  139. package/dist/lib/reliability/rule-ids.js +10 -1
  140. package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
  141. package/dist/lib/reliability/swallowed-errors.js +107 -21
  142. package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
  143. package/dist/lib/reliability/usage.js +16 -5
  144. package/dist/lib/reliability/walk.js +3 -2
  145. package/dist/lib/security/auth-crypto/hashing.js +24 -8
  146. package/dist/lib/security/auth-crypto/jwt.js +21 -6
  147. package/dist/lib/security/auth-crypto/secrets.js +44 -1
  148. package/dist/lib/security/auth-crypto/shared.js +3 -1
  149. package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
  150. package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
  151. package/dist/lib/security/cli.js +21 -6
  152. package/dist/lib/security/cookie-credentials.js +115 -0
  153. package/dist/lib/security/cookie-csrf.js +241 -0
  154. package/dist/lib/security/deps/advisory.js +50 -109
  155. package/dist/lib/security/deps/cli.js +1 -1
  156. package/dist/lib/security/deps/cvss-score.js +14 -0
  157. package/dist/lib/security/deps/fixed-version.js +97 -0
  158. package/dist/lib/security/deps/lockfiles.js +135 -74
  159. package/dist/lib/security/deps/osv.js +11 -3
  160. package/dist/lib/security/deps/scan.js +47 -20
  161. package/dist/lib/security/deps/yarn-lock.js +158 -0
  162. package/dist/lib/security/examples/injection.cjs +4 -0
  163. package/dist/lib/security/exposure/cookies.js +17 -2
  164. package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
  165. package/dist/lib/security/exposure/frontend-security.js +21 -14
  166. package/dist/lib/security/exposure/jsx-url.js +18 -33
  167. package/dist/lib/security/exposure/logging.js +49 -10
  168. package/dist/lib/security/exposure/prototype-pollution.js +126 -56
  169. package/dist/lib/security/exposure/react-html.js +26 -0
  170. package/dist/lib/security/exposure/reflected-xss.js +34 -5
  171. package/dist/lib/security/files/compose.js +126 -1
  172. package/dist/lib/security/files/dockerfile.js +62 -4
  173. package/dist/lib/security/files/index.js +1 -1
  174. package/dist/lib/security/injection/command.js +46 -18
  175. package/dist/lib/security/injection/index.js +2 -0
  176. package/dist/lib/security/injection/ldap.js +86 -0
  177. package/dist/lib/security/injection/nosql.js +28 -4
  178. package/dist/lib/security/injection/redos.js +1 -1
  179. package/dist/lib/security/injection/rule-ids.js +1 -0
  180. package/dist/lib/security/injection/shared.js +5 -1
  181. package/dist/lib/security/injection/sql.js +28 -13
  182. package/dist/lib/security/lexical-declaration.js +113 -0
  183. package/dist/lib/security/pg-dynamic-query.js +28 -1
  184. package/dist/lib/security/pg-identifier-guards.js +107 -3
  185. package/dist/lib/security/phase5-rules.js +26 -135
  186. package/dist/lib/security/polyglot.js +2 -2
  187. package/dist/lib/security/redirect-settings.js +98 -0
  188. package/dist/lib/security/request-forgery/open-redirect.js +18 -5
  189. package/dist/lib/security/request-forgery/path-traversal.js +84 -6
  190. package/dist/lib/security/request-forgery/shared.js +1 -7
  191. package/dist/lib/security/request-forgery/ssrf.js +176 -14
  192. package/dist/lib/security/rule-descriptions.js +5 -1
  193. package/dist/lib/security/rule-ids.js +7 -0
  194. package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
  195. package/dist/lib/security/site-fixes/exposure.js +21 -3
  196. package/dist/lib/security/site-fixes/files.js +11 -13
  197. package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
  198. package/dist/lib/security/site-fixes/injection.js +17 -4
  199. package/dist/lib/security/site-fixes/jwt.js +1 -20
  200. package/dist/lib/security/site-fixes/request-forgery.js +37 -29
  201. package/dist/lib/security/taint/binding-inputs.js +236 -0
  202. package/dist/lib/security/taint/filename-guard.js +45 -45
  203. package/dist/lib/security/taint/guards.js +14 -8
  204. package/dist/lib/security/taint/index.js +126 -154
  205. package/dist/lib/security/taint/propagate.js +43 -9
  206. package/dist/lib/security/taint/record-writes.js +161 -0
  207. package/dist/lib/security/taint/resolution-cache.js +13 -7
  208. package/dist/lib/security/taint/sanitizers.js +89 -5
  209. package/dist/lib/security/taint/trace-nodes.js +61 -0
  210. package/dist/lib/security/taint/validators.js +89 -9
  211. package/dist/lib/shared/agent/agent-init.js +28 -5
  212. package/dist/lib/shared/agent/agent-prompt.js +74 -0
  213. package/dist/lib/shared/agent/agent-session.js +6 -1
  214. package/dist/lib/shared/agent/agent-verify.js +58 -11
  215. package/dist/lib/shared/agent/git-hook.js +17 -6
  216. package/dist/lib/shared/agent/review-delivery.js +1 -1
  217. package/dist/lib/shared/agent/review-mcp.js +8 -2
  218. package/dist/lib/shared/analysis/ast-semantics.js +2 -2
  219. package/dist/lib/shared/analysis/scan-cache.js +99 -14
  220. package/dist/lib/shared/check.js +172 -20
  221. package/dist/lib/shared/cli-dispatch.js +17 -0
  222. package/dist/lib/shared/config.js +27 -10
  223. package/dist/lib/shared/explain.js +1 -1
  224. package/dist/lib/shared/fix/fix-convergence.js +19 -31
  225. package/dist/lib/shared/fix/fix-handoff.js +16 -11
  226. package/dist/lib/shared/fix/fix-imports.js +4 -162
  227. package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
  228. package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
  229. package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
  230. package/dist/lib/shared/fix/fix-presentation.js +9 -6
  231. package/dist/lib/shared/fix/fix-safety.js +32 -1
  232. package/dist/lib/shared/fix/fix-scope.js +82 -0
  233. package/dist/lib/shared/fix/fix-terminal.js +28 -1
  234. package/dist/lib/shared/fix/fix-typecheck.js +8 -4
  235. package/dist/lib/shared/fix/import-text-edits.js +148 -0
  236. package/dist/lib/shared/fix/project-file-access.js +17 -26
  237. package/dist/lib/shared/fix/read-fix-text.js +20 -0
  238. package/dist/lib/shared/fix.js +241 -104
  239. package/dist/lib/shared/formats/finding-location.js +4 -1
  240. package/dist/lib/shared/formats/github.js +3 -3
  241. package/dist/lib/shared/formats/sarif.js +9 -3
  242. package/dist/lib/shared/report-fp.js +97 -0
  243. package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
  244. package/dist/lib/shared/reporting/baseline.js +7 -5
  245. package/dist/lib/shared/reporting/check-text.js +50 -0
  246. package/dist/lib/shared/reporting/pillars.js +54 -19
  247. package/dist/lib/shared/reporting/source-report.js +3 -0
  248. package/dist/lib/shared/system/atomic-write.js +5 -2
  249. package/dist/lib/shared/system/glob.js +34 -8
  250. package/dist/lib/shared/system/sentry.js +222 -0
  251. package/dist/lib/shared/system/shell-argument.js +5 -1
  252. package/dist/lib/shared/system/terminal-safe.js +3 -2
  253. package/dist/lib/shared/system/terminal-style.js +131 -0
  254. package/dist/lib/shared/workspaces.js +15 -3
  255. package/docs/assets/cli-workflow.gif +0 -0
  256. package/integrations/sublime/plugin.py +22 -0
  257. package/integrations/zed/Cargo.lock +845 -0
  258. package/integrations/zed/Cargo.toml +11 -0
  259. package/integrations/zed/extension.toml +11 -0
  260. package/integrations/zed/src/lib.rs +25 -0
  261. package/package.json +15 -3
  262. package/plugin/.claude-plugin/plugin.json +1 -1
  263. package/plugin/commands/loadwise.md +11 -6
  264. package/plugin/hooks/check-edited-file.mjs +27 -5
  265. package/polyglot/performance/rules/csharp.yml +34 -5
  266. package/polyglot/performance/rules/java.yml +24 -1
  267. package/polyglot/performance/rules/python.yml +74 -2
  268. package/polyglot/performance/sgconfig.yml +1 -0
  269. package/polyglot/reliability/rules/csharp.yml +12 -6
  270. package/polyglot/reliability/rules/go.yml +86 -6
  271. package/polyglot/reliability/rules/java.yml +22 -1
  272. package/polyglot/reliability/sgconfig.yml +1 -0
  273. package/polyglot/security/rules/go.yml +100 -22
  274. package/polyglot/security/rules/python.yml +74 -6
  275. package/polyglot/security/rules/rust.yml +65 -0
  276. package/polyglot/security/sgconfig.yml +1 -0
  277. package/schema/loadwise.config.schema.json +556 -76
  278. /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
@@ -22,16 +22,17 @@ const frontendPackages = new Set([
22
22
  'lit',
23
23
  ]);
24
24
  const dependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
25
- function dependsOnFrontendPackage(manifestFile) {
25
+ function mayDependOnFrontendPackage(manifestFile) {
26
26
  let manifest;
27
27
  try {
28
28
  manifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
29
29
  }
30
30
  catch {
31
- return false;
31
+ // Unreadable dependencies cannot establish that accessibility is inapplicable.
32
+ return true;
32
33
  }
33
34
  if (!isRecord(manifest))
34
- return false;
35
+ return true;
35
36
  return dependencyFields.some((field) => {
36
37
  const dependencies = manifest[field];
37
38
  return isRecord(dependencies) && Object.keys(dependencies).some((name) => frontendPackages.has(name));
@@ -78,7 +79,7 @@ function hasFrontendSources(directory) {
78
79
  if (known !== undefined)
79
80
  return known;
80
81
  const found = listFrontendCandidateFiles(resolved).some((file) => frontendFilePattern.test(file) ||
81
- (path.posix.basename(file) === 'package.json' && dependsOnFrontendPackage(path.join(resolved, file))));
82
+ (path.posix.basename(file) === 'package.json' && mayDependOnFrontendPackage(path.join(resolved, file))));
82
83
  frontendByDirectory.set(resolved, found);
83
84
  return found;
84
85
  }
@@ -93,7 +94,7 @@ function hasFrontendSourcesInWorkspaces(directory, selectors) {
93
94
  }
94
95
  catch {
95
96
  // An unmatched selector is reported by the checker itself.
96
- return hasFrontendSources(directory);
97
+ return true;
97
98
  }
98
99
  }
99
100
  export { hasFrontendSources, hasFrontendSourcesInWorkspaces, listFrontendCandidateFiles };
@@ -21,7 +21,8 @@ function staticExpressionText(expression) {
21
21
  ts.isNumericLiteral(inner.operand);
22
22
  return isNegatedNumber ? `-${inner.operand.text}` : undefined;
23
23
  }
24
- function attributeValue(attribute) {
24
+ const nativeBooleans = new Set(['autoplay', 'controls', 'disabled', 'hidden', 'inert', 'muted', 'open', 'readonly']);
25
+ function attributeValue(attribute, name) {
25
26
  const initializer = attribute.initializer;
26
27
  if (!initializer)
27
28
  return { kind: 'static', text: '' };
@@ -29,10 +30,12 @@ function attributeValue(attribute) {
29
30
  return { kind: 'static', text: initializer.text };
30
31
  if (!ts.isJsxExpression(initializer) || !initializer.expression)
31
32
  return { kind: 'dynamic' };
32
- // `hidden={true}` is on exactly like a bare `hidden`; `{false}` stays dynamic so every rule treats it as unknown.
33
+ // Native boolean false is omitted below; ARIA booleans are serialized as explicit tokens.
33
34
  if (unwrapExpression(initializer.expression).kind === ts.SyntaxKind.TrueKeyword) {
34
35
  return { kind: 'static', text: 'true' };
35
36
  }
37
+ if (name.startsWith('aria-') && unwrapExpression(initializer.expression).kind === ts.SyntaxKind.FalseKeyword)
38
+ return { kind: 'static', text: 'false' };
36
39
  const text = staticExpressionText(initializer.expression);
37
40
  return text === undefined ? { kind: 'dynamic' } : { kind: 'static', text };
38
41
  }
@@ -103,13 +106,20 @@ function translateAttributes(sourceFile, attributeNodes, checker) {
103
106
  continue;
104
107
  }
105
108
  const name = htmlAttributeName(attribute.name.getText(sourceFile));
109
+ const initializer = attribute.initializer;
110
+ if (nativeBooleans.has(name) &&
111
+ initializer &&
112
+ ts.isJsxExpression(initializer) &&
113
+ initializer.expression &&
114
+ unwrapExpression(initializer.expression).kind === ts.SyntaxKind.FalseKeyword)
115
+ continue;
106
116
  if (name === 'onclick' && isPropagationOnlyHandler(attribute))
107
117
  continue;
108
118
  if (name === 'autoplay' && isFalsyAutoplay(attribute))
109
119
  continue;
110
120
  if ((name === 'alt' || name === 'title') && isOmittedTextAttribute(attribute, checker))
111
121
  continue;
112
- attributes.push({ name, value: attributeValue(attribute), ...position(sourceFile, attribute.name) });
122
+ attributes.push({ name, value: attributeValue(attribute, name), ...position(sourceFile, attribute.name) });
113
123
  }
114
124
  return { attributes, hasSpreadAttributes };
115
125
  }
@@ -6,7 +6,7 @@ import path from 'node:path';
6
6
  import { isVendoredMinified } from '../shared/analysis/execution-context.js';
7
7
  import { recordSkippedFile } from '../shared/reporting/coverage-notes.js';
8
8
  import { listFrontendCandidateFiles } from './frontend-detect.js';
9
- import { checkTemplateFile } from './template-file.js';
9
+ import { analyzeTemplateFile } from './template-file.js';
10
10
  const markupFilePattern = /\.(?:html?|vue|svelte)$/i;
11
11
  function isMarkupFile(filename) {
12
12
  return markupFilePattern.test(filename);
@@ -23,7 +23,12 @@ function findingsOfFile(absolute, skippedFiles) {
23
23
  try {
24
24
  // The absolute path lets Angular .html templates find their component's sibling .ts file; findings report the path
25
25
  // relative to the working directory, as program findings do.
26
- return checkTemplateFile(absolute, fs.readFileSync(absolute, 'utf8')).map((finding) => ({ ...finding, file }));
26
+ const result = analyzeTemplateFile(absolute, fs.readFileSync(absolute, 'utf8'));
27
+ if (result.skipReason) {
28
+ recordSkippedFile(skippedFiles, { file, reason: result.skipReason }, `The accessibility analysis of ${file} was skipped (${result.skipReason}).`);
29
+ return [];
30
+ }
31
+ return result.findings.map((finding) => ({ ...finding, file }));
27
32
  }
28
33
  catch (error) {
29
34
  const message = error instanceof Error ? error.message : String(error);
@@ -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, walkElements } from './markup.js';
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
- return isStaticValue(element, 'type', 'image') && !hasAttribute(element, 'alt');
112
- return (element.tagName === 'img' || element.tagName === 'area') && !hasAttribute(element, 'alt');
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
- const imgMissingAlt = (element, { document }) => {
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 (hasAccessibleNameAttribute(element) ||
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
- const kind = element.tagName === 'input' ? '<input type="image">' : `<${element.tagName}>`;
123
- return [
124
- finding(document, element, 'a11y-img-missing-alt', `${kind} 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.`),
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') || hasAttribute(element, 'role'))
215
+ if (!hasAttribute(element, 'onclick') || isPossiblyHidden(element))
149
216
  return [];
150
- if (keyHandlerNames.some((name) => hasAttribute(element, name)) || isHiddenFromAssistiveTechnology(element))
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
- return [
234
- 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".'),
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}, so people with low vision cannot pinch-zoom the page. Remove it, or allow a maximum-scale of at least 2.`),
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, { document }) => {
464
+ const inputMissingAutocomplete = (element, context) => {
364
465
  if (element.tagName !== 'input' || !element.isIntrinsic || element.hasSpreadAttributes)
365
466
  return [];
366
- if (hasAttribute(element, 'autocomplete') || hasAttribute(element, 'hidden'))
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
- ...labelTargets(document),
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 || !source.startsWith(buttonTagOpening, start))
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*\}\}?\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
- export { templateDocument };
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
- /** The content of the top-level `<template>` block of a .vue file; undefined when absent or not HTML (`lang="pug"`). */
108
- function vueTemplateRegion(text) {
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 = /\blang\s*=\s*["']?([\w-]+)/i.exec(text.slice(tagStart, tagEnd))?.[1];
132
+ const language = langAttribute(text.slice(tagStart, tagEnd));
129
133
  if (language && language.toLowerCase() !== 'html')
130
- return undefined;
131
- return { start: tagEnd, end: templateBlockEnd(text, tagEnd) };
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 region = vueTemplateRegion(text);
153
- return region && templateDocument(file, text, 'vue', region.start, region.end);
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 checkTemplateFile(file, text) {
178
- if (isSkippedMarkup(file, text))
179
- return [];
180
- const document = markupDocument(file, text);
181
- return document ? withReviewedReasons(text, checkMarkup(document)) : [];
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 { checkTemplateFile };
198
+ export { analyzeTemplateFile };
@@ -1,6 +1,14 @@
1
1
  const accessibilityUsage = `Usage:
2
- loadwise a11y [-p tsconfig.json | -p monorepo-root [--workspace name|path ...] | file.tsx file.html file.vue ...] [--engine auto|native|js] [--loadwise-config loadwise.config.json] [--json | --format text|json|sarif|github] [--include-contextual] [--ignore rule-id] [--min-impact low|medium|high|critical] [--fail-on all|contract] [--baseline [file] | --write-baseline [file]] [--fix [--yes | --only id,...] [--no-comments] [--no-format]]
3
- loadwise a11y [-p tsconfig.json] (--staged | --changed-since git-ref) [--json] [--include-contextual] [--ignore rule-id]
2
+ loadwise a11y [-p <project> | <files...>] [options]
3
+
4
+ Scan options
5
+ -p <project> --workspace <name|path> --engine <auto|native|js>
6
+ --loadwise-config <file> --ignore <rule-id>
7
+ --staged | --changed-since <git-ref>
8
+ --json | --format <text|json|sarif|github> --include-contextual
9
+ --min-impact <low|medium|high|critical> --fail-on <all|contract>
10
+ --baseline [file] | --write-baseline [file]
11
+ --fix [--yes | --only <ids>] [--no-comments] [--no-format]
4
12
 
5
13
  The accessibility checker finds markup that people using screen readers, keyboards or zoom cannot use: images without alt text, unlabelled form controls, click handlers on non-interactive elements, invalid ARIA, missing page language and similar.
6
14
  It reads JSX and inline Angular templates from the TypeScript program, and .html, .htm, .vue and .svelte files from the project folders (ignored folders, build output and the config's "ignore" paths are left out). Name markup files on the command line to check just those.