prunelle 0.1.1 → 0.5.2
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/llms.txt +23 -19
- package/package.json +8 -2
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +80 -36
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +8 -4
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +11 -9
- package/src/build/ecoindex.ts +229 -0
- package/src/build/index.ts +174 -108
- package/src/build/islands.ts +2 -2
- package/src/build/manifest.ts +66 -5
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +91 -33
- package/src/build/precompress.ts +15 -2
- package/src/build/prerender.ts +128 -46
- package/src/build/report.ts +23 -2
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static.ts +137 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +52 -5
- package/src/cli/commands.ts +86 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +31 -2
- package/src/cli/mcp-tools.ts +480 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +261 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +20 -6
- package/src/compiler/cacheability.ts +592 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +120 -221
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +12 -11
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +56 -17
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +216 -84
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +84 -34
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +1 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +42 -25
- package/src/dev/watchers.ts +47 -11
- package/src/dom/action.ts +4 -1
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +2 -2
- package/src/dom/island.ts +11 -10
- package/src/plugins/config.ts +4 -4
- package/src/plugins/index.ts +2 -2
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +62 -0
- package/src/plugins/types.ts +32 -0
- package/src/server/action-protect.ts +198 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +82 -27
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +91 -9
- package/src/server/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +128 -31
- package/src/server/index.ts +230 -260
- package/src/server/loader.ts +5 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +123 -88
- package/src/server/public.ts +3 -3
- package/src/server/rate-limit.ts +58 -35
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +339 -8
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +196 -63
- package/src/server/security.ts +208 -32
- package/src/server/serve-handlers.ts +21 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +61 -8
- package/src/server/stream.ts +41 -22
- package/src/ssr/context.ts +85 -3
- package/src/ssr/index.ts +120 -1
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +6 -0
- package/src/test/index.ts +17 -3
- package/src/ts-plugin/diagnostics.ts +378 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +5 -0
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/index.tsx +4 -0
- package/ts-plugin.cjs +4277 -0
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
// French web law compliance checks (RGAA, RGPD, LCEN): static TSX/CSS warnings and route-level checks with explicit silencing.
|
|
2
2
|
|
|
3
|
-
import type { JSXAttribute,
|
|
3
|
+
import type { JSXAttribute, JSXElement, Node, Program } from 'oxc-parser'
|
|
4
4
|
import type { ModuleAnalysis } from './analyze'
|
|
5
|
+
import type { RgaaJsxRule, RgaaScope } from './compliance-rgaa'
|
|
5
6
|
import type { CompilerWarning } from './mistakes'
|
|
6
7
|
import { existsSync, readFileSync } from 'node:fs'
|
|
7
8
|
import { basename } from 'node:path'
|
|
8
9
|
import { visitorKeys } from 'oxc-parser'
|
|
9
10
|
import { relPosix, walkFiles } from '../build/files'
|
|
10
11
|
import { fileToRoutePath } from '../build/routes'
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
attrTargetKey,
|
|
14
|
+
checkRgaaElement,
|
|
15
|
+
cloneRgaaScope,
|
|
16
|
+
createRgaaScope,
|
|
17
|
+
findAttr,
|
|
18
|
+
hasNonEmptyAttr,
|
|
19
|
+
INTERACTIVE_ANCESTORS,
|
|
20
|
+
mergeRgaaScope,
|
|
21
|
+
RGAA_JSX_RULES,
|
|
22
|
+
staticStringValueOf,
|
|
23
|
+
} from './compliance-rgaa'
|
|
24
|
+
import { formatDiagnostic, formatLoc, isComponentTag, jsxTagName } from './shared'
|
|
12
25
|
|
|
13
26
|
export type ComplianceRule =
|
|
14
|
-
|
|
|
15
|
-
| 'rgaa/form-label'
|
|
16
|
-
| 'rgaa/accessible-name'
|
|
27
|
+
| RgaaJsxRule
|
|
17
28
|
| 'rgpd/third-party-url'
|
|
18
29
|
| 'lcen/legal-notice'
|
|
19
30
|
| 'rgaa/accessibility-statement'
|
|
@@ -28,15 +39,12 @@ export interface ComplianceConfig {
|
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
const COMPLIANCE_RULES = new Set<ComplianceRule>([
|
|
31
|
-
|
|
32
|
-
'rgaa/form-label',
|
|
33
|
-
'rgaa/accessible-name',
|
|
42
|
+
...RGAA_JSX_RULES,
|
|
34
43
|
'rgpd/third-party-url',
|
|
35
44
|
'lcen/legal-notice',
|
|
36
45
|
'rgaa/accessibility-statement',
|
|
37
46
|
])
|
|
38
47
|
|
|
39
|
-
const NON_LABELLED_INPUT_TYPES = new Set(['hidden', 'submit', 'reset', 'button', 'image'])
|
|
40
48
|
const THIRD_PARTY_LINK_RELS = new Set(['stylesheet', 'preload', 'preconnect', 'dns-prefetch'])
|
|
41
49
|
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '0.0.0.0'])
|
|
42
50
|
const DEFAULT_LEGAL_PATHS = new Set(['/mentions-legales', '/legal', '/legal-notice', '/imprint', '/impressum', '/cgu', '/cgv'])
|
|
@@ -175,147 +183,18 @@ export function shouldEmitWarning(warning: CompilerWarning, compliance?: Complia
|
|
|
175
183
|
return true
|
|
176
184
|
}
|
|
177
185
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
return undefined
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function hasSpread(attributes: readonly JSXAttributeItem[]): boolean {
|
|
187
|
-
return attributes.some(a => a.type === 'JSXSpreadAttribute')
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function staticStringValueOf(value: JSXAttribute['value']): string | undefined {
|
|
191
|
-
if (value === null)
|
|
192
|
-
return undefined
|
|
193
|
-
if (value.type === 'Literal' && typeof value.value === 'string')
|
|
194
|
-
return value.value
|
|
195
|
-
if (value.type === 'JSXExpressionContainer' && value.expression.type !== 'JSXEmptyExpression') {
|
|
196
|
-
const expr = unwrapTsExpr(value.expression)
|
|
197
|
-
if (expr.type === 'Literal' && typeof expr.value === 'string')
|
|
198
|
-
return expr.value
|
|
199
|
-
if (expr.type === 'TemplateLiteral' && expr.expressions.length === 0)
|
|
200
|
-
return expr.quasis[0]?.value.cooked ?? undefined
|
|
201
|
-
}
|
|
202
|
-
return undefined
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function attrTargetKey(attr: JSXAttribute | undefined): string | undefined {
|
|
206
|
-
if (attr === undefined || attr.value === null)
|
|
207
|
-
return undefined
|
|
208
|
-
const str = staticStringValueOf(attr.value)
|
|
209
|
-
if (str !== undefined && str.trim() !== '')
|
|
210
|
-
return `s:${str}`
|
|
211
|
-
if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
212
|
-
const expr = unwrapTsExpr(attr.value.expression)
|
|
213
|
-
if (expr.type === 'Identifier')
|
|
214
|
-
return `i:${expr.name}`
|
|
215
|
-
}
|
|
216
|
-
return undefined
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function hasNonEmptyAttr(attributes: readonly JSXAttributeItem[], name: string): boolean {
|
|
220
|
-
const attr = findAttr(attributes, name)
|
|
221
|
-
if (attr === undefined || attr.value === null)
|
|
222
|
-
return false
|
|
223
|
-
const str = staticStringValueOf(attr.value)
|
|
224
|
-
if (str !== undefined)
|
|
225
|
-
return str.trim() !== ''
|
|
226
|
-
if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
227
|
-
const expr = unwrapParens(attr.value.expression)
|
|
228
|
-
if (expr.type === 'Literal' && (expr.value === null || expr.value === false || expr.value === ''))
|
|
229
|
-
return false
|
|
230
|
-
if (expr.type === 'Identifier' && expr.name === 'undefined')
|
|
231
|
-
return false
|
|
232
|
-
return true
|
|
233
|
-
}
|
|
234
|
-
return false
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function hasLabelAttr(attributes: readonly JSXAttributeItem[]): boolean {
|
|
238
|
-
return hasNonEmptyAttr(attributes, 'aria-label')
|
|
239
|
-
|| hasNonEmptyAttr(attributes, 'aria-labelledby')
|
|
240
|
-
|| hasNonEmptyAttr(attributes, 'title')
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function isAriaHidden(attributes: readonly JSXAttributeItem[]): boolean {
|
|
244
|
-
const attr = findAttr(attributes, 'aria-hidden')
|
|
245
|
-
if (attr === undefined)
|
|
246
|
-
return false
|
|
247
|
-
if (attr.value === null)
|
|
248
|
-
return true
|
|
249
|
-
if (attr.value.type === 'Literal')
|
|
250
|
-
return attr.value.value === 'true'
|
|
251
|
-
if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
252
|
-
const expr = unwrapParens(attr.value.expression)
|
|
253
|
-
return expr.type === 'Literal' && (expr.value === true || expr.value === 'true')
|
|
254
|
-
}
|
|
255
|
-
return false
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function hasMeaningfulExpression(expr: Node): boolean {
|
|
259
|
-
const inner = unwrapParens(expr)
|
|
260
|
-
if (inner.type === 'Literal')
|
|
261
|
-
return typeof inner.value === 'string' ? inner.value.trim() !== '' : typeof inner.value === 'number'
|
|
262
|
-
if (inner.type === 'Identifier' && inner.name === 'undefined')
|
|
263
|
-
return false
|
|
264
|
-
return true
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function hasAccessibleName(children: readonly JSXChild[]): boolean {
|
|
268
|
-
for (const child of children) {
|
|
269
|
-
if (child.type === 'JSXText') {
|
|
270
|
-
if (cleanJsxText(child.value).trim() !== '')
|
|
271
|
-
return true
|
|
272
|
-
}
|
|
273
|
-
else if (child.type === 'JSXExpressionContainer') {
|
|
274
|
-
if (child.expression.type !== 'JSXEmptyExpression' && hasMeaningfulExpression(child.expression))
|
|
275
|
-
return true
|
|
276
|
-
}
|
|
277
|
-
else if (child.type === 'JSXFragment') {
|
|
278
|
-
if (hasAccessibleName(child.children))
|
|
279
|
-
return true
|
|
280
|
-
}
|
|
281
|
-
else if (child.type === 'JSXElement') {
|
|
282
|
-
const attrs = child.openingElement.attributes
|
|
283
|
-
if (isAriaHidden(attrs))
|
|
284
|
-
continue
|
|
285
|
-
const tag = jsxTagName(child.openingElement.name)
|
|
286
|
-
if (hasSpread(attrs) || hasLabelAttr(attrs))
|
|
287
|
-
return true
|
|
288
|
-
if (tag === 'img') {
|
|
289
|
-
if (hasNonEmptyAttr(attrs, 'alt'))
|
|
290
|
-
return true
|
|
291
|
-
continue
|
|
292
|
-
}
|
|
293
|
-
if (tag === 'svg') {
|
|
294
|
-
const hasTitle = child.children.some(c =>
|
|
295
|
-
c.type === 'JSXElement' && jsxTagName(c.openingElement.name) === 'title' && hasAccessibleName(c.children),
|
|
296
|
-
)
|
|
297
|
-
if (hasTitle)
|
|
298
|
-
return true
|
|
299
|
-
continue
|
|
300
|
-
}
|
|
301
|
-
if (isComponentTag(tag)) {
|
|
302
|
-
if (hasNonEmptyAttr(attrs, 'label') || hasAccessibleName(child.children))
|
|
303
|
-
return true
|
|
304
|
-
continue
|
|
305
|
-
}
|
|
306
|
-
if (hasAccessibleName(child.children))
|
|
307
|
-
return true
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return false
|
|
186
|
+
interface AncestorState {
|
|
187
|
+
labelDepth: number
|
|
188
|
+
consentGateDepth: number
|
|
189
|
+
interactiveAncestor: string | undefined
|
|
311
190
|
}
|
|
312
191
|
|
|
313
|
-
function walkAst(value: unknown, enter: (node: Node) => void
|
|
192
|
+
function walkAst(value: unknown, enter: (node: Node) => void): void {
|
|
314
193
|
if (value === null || typeof value !== 'object')
|
|
315
194
|
return
|
|
316
195
|
if (Array.isArray(value)) {
|
|
317
196
|
for (let i = 0; i < value.length; i++)
|
|
318
|
-
walkAst(value[i], enter
|
|
197
|
+
walkAst(value[i], enter)
|
|
319
198
|
return
|
|
320
199
|
}
|
|
321
200
|
const node = value as Node
|
|
@@ -325,9 +204,8 @@ function walkAst(value: unknown, enter: (node: Node) => void, exit?: (node: Node
|
|
|
325
204
|
const keys = visitorKeys[node.type]
|
|
326
205
|
if (keys !== undefined) {
|
|
327
206
|
for (let i = 0; i < keys.length; i++)
|
|
328
|
-
walkAst((node as unknown as Record<string, unknown>)[keys[i]!], enter
|
|
207
|
+
walkAst((node as unknown as Record<string, unknown>)[keys[i]!], enter)
|
|
329
208
|
}
|
|
330
|
-
exit?.(node)
|
|
331
209
|
}
|
|
332
210
|
|
|
333
211
|
function collectLabelTargets(program: Program): Set<string> {
|
|
@@ -386,52 +264,14 @@ function checkThirdPartyElement(
|
|
|
386
264
|
})
|
|
387
265
|
}
|
|
388
266
|
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
): void {
|
|
398
|
-
const tag = jsxTagName(element.openingElement.name)
|
|
399
|
-
if (tag === '' || isComponentTag(tag))
|
|
400
|
-
return
|
|
401
|
-
const attrs = element.openingElement.attributes
|
|
402
|
-
const spread = hasSpread(attrs)
|
|
403
|
-
|
|
404
|
-
if (tag === 'img' && !spread && findAttr(attrs, 'alt') === undefined && !isIgnoredAt(ignores, 'rgaa/img-alt', element.start)) {
|
|
405
|
-
warnings.push({
|
|
406
|
-
rule: 'rgaa/img-alt',
|
|
407
|
-
start: element.start,
|
|
408
|
-
message: `[rgaa/img-alt] <img> in ${filename} is missing an alt attribute: add alt="description" or alt="" for decorative images.`,
|
|
409
|
-
})
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if ((tag === 'input' || tag === 'select' || tag === 'textarea') && !spread && !inLabel && !hasLabelAttr(attrs)) {
|
|
413
|
-
const inputType = tag === 'input' ? staticStringValueOf(findAttr(attrs, 'type')?.value ?? null)?.toLowerCase() : undefined
|
|
414
|
-
const idKey = attrTargetKey(findAttr(attrs, 'id'))
|
|
415
|
-
const linked = idKey !== undefined && labelTargets.has(idKey)
|
|
416
|
-
if ((inputType === undefined || !NON_LABELLED_INPUT_TYPES.has(inputType)) && !linked && !isIgnoredAt(ignores, 'rgaa/form-label', element.start)) {
|
|
417
|
-
warnings.push({
|
|
418
|
-
rule: 'rgaa/form-label',
|
|
419
|
-
start: element.start,
|
|
420
|
-
message: `[rgaa/form-label] <${tag}> in ${filename} has no associated label: wrap it in <label>, link <label for="id">, or add aria-label="..." / aria-labelledby="...".`,
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if ((tag === 'button' || tag === 'a') && !spread && !hasLabelAttr(attrs) && !hasAccessibleName(element.children) && !isIgnoredAt(ignores, 'rgaa/accessible-name', element.start)) {
|
|
426
|
-
warnings.push({
|
|
427
|
-
rule: 'rgaa/accessible-name',
|
|
428
|
-
start: element.start,
|
|
429
|
-
message: `[rgaa/accessible-name] <${tag}> in ${filename} has no accessible name: add visible text or aria-label="...".`,
|
|
430
|
-
})
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (!inConsentGate)
|
|
434
|
-
checkThirdPartyElement(element, tag, filename, ignores, warnings)
|
|
267
|
+
function definitelyExits(stmt: Node): boolean {
|
|
268
|
+
if (stmt.type === 'ReturnStatement' || stmt.type === 'ThrowStatement')
|
|
269
|
+
return true
|
|
270
|
+
if (stmt.type === 'BlockStatement')
|
|
271
|
+
return stmt.body.length > 0 && definitelyExits(stmt.body[stmt.body.length - 1]!)
|
|
272
|
+
if (stmt.type === 'IfStatement')
|
|
273
|
+
return stmt.alternate !== null && definitelyExits(stmt.consequent) && definitelyExits(stmt.alternate)
|
|
274
|
+
return false
|
|
435
275
|
}
|
|
436
276
|
|
|
437
277
|
/** Runs RGAA & RGPD static JSX compliance checks on `program`, appending warnings (never throwing). */
|
|
@@ -444,36 +284,95 @@ export function checkCompliance(
|
|
|
444
284
|
): void {
|
|
445
285
|
const ignores = parsePrunelleIgnores(code)
|
|
446
286
|
const labelTargets = collectLabelTargets(program)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
287
|
+
const isIgnored = (rule: RgaaJsxRule, elementStart: number, attrStart?: number): boolean =>
|
|
288
|
+
isIgnoredAt(ignores, rule, elementStart) || (attrStart !== undefined && isIgnoredAt(ignores, rule, attrStart))
|
|
289
|
+
|
|
290
|
+
const visitChildren = (node: Node, ancestors: AncestorState, scope: RgaaScope): void => {
|
|
291
|
+
const keys = visitorKeys[node.type]
|
|
292
|
+
if (keys === undefined)
|
|
293
|
+
return
|
|
294
|
+
const rec = node as unknown as Record<string, unknown>
|
|
295
|
+
for (let i = 0; i < keys.length; i++)
|
|
296
|
+
visit(rec[keys[i]!], ancestors, scope)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const visit = (value: unknown, ancestors: AncestorState, scope: RgaaScope): void => {
|
|
300
|
+
if (value === null || typeof value !== 'object')
|
|
301
|
+
return
|
|
302
|
+
if (Array.isArray(value)) {
|
|
303
|
+
for (let i = 0; i < value.length; i++)
|
|
304
|
+
visit(value[i], ancestors, scope)
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
const node = value as Node
|
|
308
|
+
if (typeof node.type !== 'string')
|
|
309
|
+
return
|
|
310
|
+
|
|
311
|
+
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
|
|
312
|
+
visitChildren(node, ancestors, createRgaaScope())
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (node.type === 'ConditionalExpression') {
|
|
317
|
+
visit(node.test, ancestors, scope)
|
|
318
|
+
const branchA = cloneRgaaScope(scope)
|
|
319
|
+
const branchB = cloneRgaaScope(scope)
|
|
320
|
+
visit(node.consequent, ancestors, branchA)
|
|
321
|
+
visit(node.alternate, ancestors, branchB)
|
|
322
|
+
mergeRgaaScope(scope, branchA)
|
|
323
|
+
mergeRgaaScope(scope, branchB)
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (node.type === 'IfStatement') {
|
|
328
|
+
visit(node.test, ancestors, scope)
|
|
329
|
+
const branchA = cloneRgaaScope(scope)
|
|
330
|
+
visit(node.consequent, ancestors, branchA)
|
|
331
|
+
const branchB = cloneRgaaScope(scope)
|
|
332
|
+
if (node.alternate !== null)
|
|
333
|
+
visit(node.alternate, ancestors, branchB)
|
|
334
|
+
if (!definitelyExits(node.consequent))
|
|
335
|
+
mergeRgaaScope(scope, branchA)
|
|
336
|
+
if (node.alternate !== null && !definitelyExits(node.alternate))
|
|
337
|
+
mergeRgaaScope(scope, branchB)
|
|
338
|
+
return
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (node.type === 'JSXElement') {
|
|
457
342
|
const tag = jsxTagName(node.openingElement.name)
|
|
458
|
-
|
|
459
|
-
|
|
343
|
+
const attrs = node.openingElement.attributes
|
|
344
|
+
if (tag !== '' && !isComponentTag(tag)) {
|
|
345
|
+
checkRgaaElement(node, tag, {
|
|
346
|
+
filename,
|
|
347
|
+
inLabel: ancestors.labelDepth > 0,
|
|
348
|
+
interactiveAncestor: ancestors.interactiveAncestor,
|
|
349
|
+
labelTargets,
|
|
350
|
+
scope,
|
|
351
|
+
isIgnored,
|
|
352
|
+
warnings,
|
|
353
|
+
})
|
|
354
|
+
if (ancestors.consentGateDepth === 0)
|
|
355
|
+
checkThirdPartyElement(node, tag, filename, ignores, warnings)
|
|
356
|
+
}
|
|
357
|
+
visit(attrs, ancestors, scope)
|
|
358
|
+
const opensLabel = tag === 'label' || (isComponentTag(tag) && hasNonEmptyAttr(attrs, 'label'))
|
|
460
359
|
const opensConsentGate = resolveTag(tag) === 'ConsentGate'
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
)
|
|
360
|
+
const nextInteractive = INTERACTIVE_ANCESTORS.has(tag) ? tag : ancestors.interactiveAncestor
|
|
361
|
+
const childAncestors = opensLabel || opensConsentGate || nextInteractive !== ancestors.interactiveAncestor
|
|
362
|
+
? {
|
|
363
|
+
labelDepth: ancestors.labelDepth + (opensLabel ? 1 : 0),
|
|
364
|
+
consentGateDepth: ancestors.consentGateDepth + (opensConsentGate ? 1 : 0),
|
|
365
|
+
interactiveAncestor: nextInteractive,
|
|
366
|
+
}
|
|
367
|
+
: ancestors
|
|
368
|
+
visit(node.children, childAncestors, scope)
|
|
369
|
+
return
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
visitChildren(node, ancestors, scope)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
visit(program, { labelDepth: 0, consentGateDepth: 0, interactiveAncestor: undefined }, createRgaaScope())
|
|
477
376
|
}
|
|
478
377
|
|
|
479
378
|
/** Scans a CSS file for third-party `@import` or `url(...)` origins (RGPD), respecting `/* prunelle-ignore *\/` and config. */
|
|
@@ -552,7 +451,7 @@ export function checkRouteCompliance(pageRoutePaths: readonly string[], complian
|
|
|
552
451
|
if (compliance?.publicBody === true && !isRuleIgnored('rgaa/accessibility-statement', compliance)) {
|
|
553
452
|
const hasA11y = [...normalized].some(p => ACCESSIBILITY_PATHS.has(p))
|
|
554
453
|
if (!hasA11y) {
|
|
555
|
-
out.push(formatDiagnostic('prunelle.config.ts:1:1', '[rgaa/accessibility-statement] Public-body site (compliance.publicBody: true) has no accessibility statement route: add /accessibilite (or /accessibility)
|
|
454
|
+
out.push(formatDiagnostic('prunelle.config.ts:1:1', '[rgaa/accessibility-statement] Public-body site (compliance.publicBody: true) has no accessibility statement route: add /accessibilite (or /accessibility), or draft one with `prunelle a11y --draft`.', 'warning'))
|
|
556
455
|
}
|
|
557
456
|
}
|
|
558
457
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Dev-only `data-pru-src="file:line:col"` source-location tagging for SSR and DOM compilers.
|
|
2
|
+
|
|
3
|
+
import type { JSXElement } from 'oxc-parser'
|
|
4
|
+
import { isAbsolute, relative } from 'node:path'
|
|
5
|
+
import { escapeStaticAttr, jsxTagName } from './shared'
|
|
6
|
+
|
|
7
|
+
const DEV_SOURCE_SKIP_TAGS = new Set([
|
|
8
|
+
'html',
|
|
9
|
+
'head',
|
|
10
|
+
'title',
|
|
11
|
+
'meta',
|
|
12
|
+
'link',
|
|
13
|
+
'base',
|
|
14
|
+
'style',
|
|
15
|
+
'script',
|
|
16
|
+
'noscript',
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
const NOOP_DEV_SOURCE = (): string => ''
|
|
20
|
+
|
|
21
|
+
function toDevRelPath(filename: string, devSourceRoot: string): string {
|
|
22
|
+
if (!isAbsolute(filename) && isAbsolute(devSourceRoot))
|
|
23
|
+
return filename.replaceAll('\\', '/')
|
|
24
|
+
const rel = relative(devSourceRoot, filename).replaceAll('\\', '/')
|
|
25
|
+
if (rel === '' || rel === '..' || rel.startsWith('../') || isAbsolute(rel))
|
|
26
|
+
return filename.replaceAll('\\', '/')
|
|
27
|
+
return rel
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function hasDevSourceAttr(node: JSXElement): boolean {
|
|
31
|
+
for (const attr of node.openingElement.attributes) {
|
|
32
|
+
if (attr.type === 'JSXAttribute' && jsxTagName(attr.name) === 'data-pru-src')
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Precomputes the character offset of every 1-based line start in `code`. */
|
|
39
|
+
export function buildLineStarts(code: string): number[] {
|
|
40
|
+
const starts = [0]
|
|
41
|
+
for (let i = 0; i < code.length; i++) {
|
|
42
|
+
if (code.charCodeAt(i) === 10)
|
|
43
|
+
starts.push(i + 1)
|
|
44
|
+
}
|
|
45
|
+
return starts
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** O(log N) lookup of 1-based `{ line, col }` for a character offset using precomputed `lineStarts`. */
|
|
49
|
+
export function offsetToLineColFast(lineStarts: readonly number[], offset: number): { line: number, col: number } {
|
|
50
|
+
const clamped = offset < 0 ? 0 : offset
|
|
51
|
+
let lo = 0
|
|
52
|
+
let hi = lineStarts.length - 1
|
|
53
|
+
while (lo < hi) {
|
|
54
|
+
const mid = (lo + hi + 1) >> 1
|
|
55
|
+
if (lineStarts[mid]! <= clamped)
|
|
56
|
+
lo = mid
|
|
57
|
+
else
|
|
58
|
+
hi = mid - 1
|
|
59
|
+
}
|
|
60
|
+
return { line: lo + 1, col: clamped - lineStarts[lo]! + 1 }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Formats ` data-pru-src="relPath:line:col"` for an intrinsic JSX element, or `''` when skipped. */
|
|
64
|
+
export function formatDevSourceAttr(
|
|
65
|
+
node: JSXElement,
|
|
66
|
+
tag: string,
|
|
67
|
+
relPath: string,
|
|
68
|
+
lineStarts: readonly number[],
|
|
69
|
+
): string {
|
|
70
|
+
if (DEV_SOURCE_SKIP_TAGS.has(tag) || hasDevSourceAttr(node))
|
|
71
|
+
return ''
|
|
72
|
+
const { line, col } = offsetToLineColFast(lineStarts, node.openingElement.start)
|
|
73
|
+
return ` data-pru-src="${escapeStaticAttr(`${relPath}:${line}:${col}`)}"`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Returns a per-element `data-pru-src` formatter when `devSourceRoot` is set, or a zero-cost no-op otherwise. */
|
|
77
|
+
export function createDevSourceAttr(
|
|
78
|
+
filename: string,
|
|
79
|
+
code: string,
|
|
80
|
+
devSourceRoot: string | undefined,
|
|
81
|
+
): (node: JSXElement, tag: string) => string {
|
|
82
|
+
if (devSourceRoot === undefined)
|
|
83
|
+
return NOOP_DEV_SOURCE
|
|
84
|
+
const relPath = toDevRelPath(filename, devSourceRoot)
|
|
85
|
+
const lineStarts = buildLineStarts(code)
|
|
86
|
+
return (node, tag) => formatDevSourceAttr(node, tag, relPath, lineStarts)
|
|
87
|
+
}
|