prunelle 0.1.1 → 0.5.3
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 +561 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check.ts +75 -20
- package/src/cli/commands.ts +85 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +103 -14
- package/src/cli/mcp-tools.ts +490 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +421 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +42 -9
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-rgaa.ts +508 -0
- package/src/compiler/compliance.ts +241 -289
- package/src/compiler/data-keys.ts +199 -192
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +517 -442
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/mistakes.ts +4 -1
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +400 -333
- package/src/compiler/server-only.ts +190 -151
- package/src/compiler/shared.ts +40 -12
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +218 -87
- 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 +43 -20
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +28 -12
- package/src/dom/index.ts +26 -8
- package/src/dom/island.ts +35 -28
- package/src/dom/loop.ts +10 -9
- package/src/plugins/config.ts +8 -7
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +26 -7
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +62 -0
- package/src/plugins/types.ts +32 -0
- package/src/reactivity/graph.ts +10 -0
- package/src/reactivity/index.ts +24 -16
- package/src/reactivity/selector.ts +31 -4
- package/src/reactivity/store.ts +45 -13
- 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/document.ts +25 -10
- 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 +130 -3
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +28 -13
- package/src/test/index.ts +97 -12
- package/src/ts-plugin/diagnostics.ts +505 -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, getLineStarts, isComponentTag, jsxTagName, lineIndexAtOffset, unwrapTsExpr } 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,19 +39,20 @@ 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
|
|
40
|
-
const
|
|
48
|
+
const THIRD_PARTY_LINK_RELS = new Set(['stylesheet', 'preload', 'preconnect', 'dns-prefetch', 'modulepreload', 'icon'])
|
|
49
|
+
const THIRD_PARTY_SRC_TAGS = new Set(['script', 'iframe', 'img', 'video', 'audio', 'source', 'embed'])
|
|
50
|
+
const THIRD_PARTY_SRCSET_TAGS = new Set(['img', 'source'])
|
|
51
|
+
const INLINE_MAP_METHODS = new Set(['map', 'flatMap'])
|
|
41
52
|
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '0.0.0.0'])
|
|
42
53
|
const DEFAULT_LEGAL_PATHS = new Set(['/mentions-legales', '/legal', '/legal-notice', '/imprint', '/impressum', '/cgu', '/cgv'])
|
|
43
54
|
const ACCESSIBILITY_PATHS = new Set(['/accessibilite', '/accessibility', '/declaration-accessibilite', '/accessibility-statement'])
|
|
55
|
+
const LOCALE_PREFIX_RE = /^\/(?:[a-z]{2}(?:-[a-z]{2})?|:[a-z_]\w*(?:=[^/]+)?\??|\[\[?[^\]]+\]\]?)(\/.+)$/i
|
|
44
56
|
|
|
45
57
|
const LINE_IGNORE_RE = /(?:^|[\s{;(,])\/\/\s*prunelle-ignore(-file)?[ \t]+([^\r\n]+)/g
|
|
46
58
|
const BLOCK_IGNORE_RE = /\/\*\s*prunelle-ignore(-file)?\s+([\s\S]*?)\*\//g
|
|
@@ -49,33 +61,11 @@ const CSS_IMPORT_RE = /@import\s+(?:url\(\s*)?(?:'([^']+)'|"([^"]+)"|([^'"\s);]+
|
|
|
49
61
|
const CSS_URL_RE = /url\(\s*(?:'([^']+)'|"([^"]+)"|([^'"\s)]+))\s*\)/gi
|
|
50
62
|
|
|
51
63
|
interface IgnoreMap {
|
|
52
|
-
lineStarts: number[]
|
|
64
|
+
lineStarts: readonly number[]
|
|
53
65
|
fileRules: Set<ComplianceRule>
|
|
54
66
|
lineRules: Map<number, Set<ComplianceRule>>
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
function buildLineStarts(code: string): number[] {
|
|
58
|
-
const starts = [0]
|
|
59
|
-
for (let i = 0; i < code.length; i++) {
|
|
60
|
-
if (code.charCodeAt(i) === 10)
|
|
61
|
-
starts.push(i + 1)
|
|
62
|
-
}
|
|
63
|
-
return starts
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function offsetToLine(lineStarts: readonly number[], offset: number): number {
|
|
67
|
-
let lo = 0
|
|
68
|
-
let hi = lineStarts.length - 1
|
|
69
|
-
while (lo < hi) {
|
|
70
|
-
const mid = (lo + hi + 1) >> 1
|
|
71
|
-
if (lineStarts[mid]! <= offset)
|
|
72
|
-
lo = mid
|
|
73
|
-
else
|
|
74
|
-
hi = mid - 1
|
|
75
|
-
}
|
|
76
|
-
return lo + 1
|
|
77
|
-
}
|
|
78
|
-
|
|
79
69
|
function extractRules(text: string): ComplianceRule[] {
|
|
80
70
|
const out: ComplianceRule[] = []
|
|
81
71
|
for (const token of text.trim().split(/[\s,]+/)) {
|
|
@@ -86,7 +76,7 @@ function extractRules(text: string): ComplianceRule[] {
|
|
|
86
76
|
}
|
|
87
77
|
|
|
88
78
|
export function parsePrunelleIgnores(code: string): IgnoreMap {
|
|
89
|
-
const lineStarts =
|
|
79
|
+
const lineStarts = getLineStarts(code)
|
|
90
80
|
const fileRules = new Set<ComplianceRule>()
|
|
91
81
|
const lineRules = new Map<number, Set<ComplianceRule>>()
|
|
92
82
|
|
|
@@ -99,8 +89,8 @@ export function parsePrunelleIgnores(code: string): IgnoreMap {
|
|
|
99
89
|
fileRules.add(r)
|
|
100
90
|
return
|
|
101
91
|
}
|
|
102
|
-
const startLine =
|
|
103
|
-
const endLine =
|
|
92
|
+
const startLine = lineIndexAtOffset(lineStarts, start) + 1
|
|
93
|
+
const endLine = lineIndexAtOffset(lineStarts, end) + 1
|
|
104
94
|
for (const line of [startLine, endLine, endLine + 1]) {
|
|
105
95
|
let set = lineRules.get(line)
|
|
106
96
|
if (set === undefined) {
|
|
@@ -123,7 +113,7 @@ export function parsePrunelleIgnores(code: string): IgnoreMap {
|
|
|
123
113
|
function isIgnoredAt(ignores: IgnoreMap, rule: ComplianceRule, offset: number): boolean {
|
|
124
114
|
if (ignores.fileRules.has(rule))
|
|
125
115
|
return true
|
|
126
|
-
const line =
|
|
116
|
+
const line = lineIndexAtOffset(ignores.lineStarts, offset) + 1
|
|
127
117
|
return ignores.lineRules.get(line)?.has(rule) === true
|
|
128
118
|
}
|
|
129
119
|
|
|
@@ -175,175 +165,103 @@ export function shouldEmitWarning(warning: CompilerWarning, compliance?: Complia
|
|
|
175
165
|
return true
|
|
176
166
|
}
|
|
177
167
|
|
|
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
|
|
168
|
+
interface AncestorState {
|
|
169
|
+
labelDepth: number
|
|
170
|
+
consentGateDepth: number
|
|
171
|
+
interactiveAncestor: string | undefined
|
|
172
|
+
inLoop: boolean
|
|
217
173
|
}
|
|
218
174
|
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
if (attr === undefined || attr.value === null)
|
|
175
|
+
function isInlineMapCall(node: Node): node is Extract<Node, { type: 'CallExpression' }> {
|
|
176
|
+
if (node.type !== 'CallExpression' || node.arguments.length === 0)
|
|
222
177
|
return false
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
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)
|
|
178
|
+
const callee = unwrapTsExpr(node.callee)
|
|
179
|
+
if (callee.type !== 'MemberExpression' || callee.computed || callee.property.type !== 'Identifier' || !INLINE_MAP_METHODS.has(callee.property.name))
|
|
246
180
|
return false
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const expr = unwrapParens(attr.value.expression)
|
|
253
|
-
return expr.type === 'Literal' && (expr.value === true || expr.value === 'true')
|
|
254
|
-
}
|
|
255
|
-
return false
|
|
181
|
+
const first = node.arguments[0]!
|
|
182
|
+
if (first.type === 'SpreadElement')
|
|
183
|
+
return false
|
|
184
|
+
const cb = unwrapTsExpr(first)
|
|
185
|
+
return cb.type === 'ArrowFunctionExpression' || cb.type === 'FunctionExpression'
|
|
256
186
|
}
|
|
257
187
|
|
|
258
|
-
function
|
|
259
|
-
|
|
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
|
|
188
|
+
function isFunctionNode(node: Node): boolean {
|
|
189
|
+
return node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression'
|
|
265
190
|
}
|
|
266
191
|
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
192
|
+
// Collects `<label for / htmlFor>` targets owned by the current component/function (including inline `.map()` callbacks, excluding nested functions).
|
|
193
|
+
function collectDirectLabelTargets(root: Node | null | undefined): Set<string> {
|
|
194
|
+
const targets = new Set<string>()
|
|
195
|
+
const walkScope = (value: unknown, isRoot: boolean): void => {
|
|
196
|
+
if (value === null || typeof value !== 'object')
|
|
197
|
+
return
|
|
198
|
+
if (Array.isArray(value)) {
|
|
199
|
+
for (let i = 0; i < value.length; i++)
|
|
200
|
+
walkScope(value[i], false)
|
|
201
|
+
return
|
|
272
202
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
203
|
+
const node = value as Node
|
|
204
|
+
if (typeof node.type !== 'string')
|
|
205
|
+
return
|
|
206
|
+
if (!isRoot && isFunctionNode(node))
|
|
207
|
+
return
|
|
208
|
+
if (isInlineMapCall(node)) {
|
|
209
|
+
walkScope(node.callee, false)
|
|
210
|
+
const cb = unwrapTsExpr(node.arguments[0]!)
|
|
211
|
+
if (cb.type === 'ArrowFunctionExpression' || cb.type === 'FunctionExpression')
|
|
212
|
+
walkScope(cb.body, false)
|
|
213
|
+
for (let i = 1; i < node.arguments.length; i++)
|
|
214
|
+
walkScope(node.arguments[i], false)
|
|
215
|
+
return
|
|
276
216
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
217
|
+
if (node.type === 'JSXElement' && jsxTagName(node.openingElement.name) === 'label') {
|
|
218
|
+
const attrs = node.openingElement.attributes
|
|
219
|
+
const key = attrTargetKey(findAttr(attrs, 'for') ?? findAttr(attrs, 'htmlFor'))
|
|
220
|
+
if (key !== undefined)
|
|
221
|
+
targets.add(key)
|
|
280
222
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
|
223
|
+
const keys = visitorKeys[node.type]
|
|
224
|
+
if (keys !== undefined) {
|
|
225
|
+
const rec = node as unknown as Record<string, unknown>
|
|
226
|
+
for (let i = 0; i < keys.length; i++)
|
|
227
|
+
walkScope(rec[keys[i]!], false)
|
|
308
228
|
}
|
|
309
229
|
}
|
|
310
|
-
|
|
230
|
+
walkScope(root, true)
|
|
231
|
+
return targets
|
|
311
232
|
}
|
|
312
233
|
|
|
313
|
-
function
|
|
314
|
-
|
|
234
|
+
function reportThirdPartyAttr(
|
|
235
|
+
tag: string,
|
|
236
|
+
attrName: string,
|
|
237
|
+
attr: JSXAttribute | undefined,
|
|
238
|
+
filename: string,
|
|
239
|
+
ignores: IgnoreMap,
|
|
240
|
+
warnings: CompilerWarning[],
|
|
241
|
+
isSrcset = false,
|
|
242
|
+
): void {
|
|
243
|
+
if (attr === undefined)
|
|
315
244
|
return
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
walkAst(value[i], enter, exit)
|
|
245
|
+
const raw = staticStringValueOf(attr.value)
|
|
246
|
+
if (raw === undefined)
|
|
319
247
|
return
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
248
|
+
const urls = isSrcset
|
|
249
|
+
? raw.split(',').map(part => part.trim().split(/\s+/, 1)[0] ?? '').filter(Boolean)
|
|
250
|
+
: [raw]
|
|
251
|
+
for (const url of urls) {
|
|
252
|
+
const origin = thirdPartyOrigin(url)
|
|
253
|
+
if (origin === undefined)
|
|
254
|
+
continue
|
|
255
|
+
if (!isIgnoredAt(ignores, 'rgpd/third-party-url', attr.start)) {
|
|
256
|
+
warnings.push({
|
|
257
|
+
rule: 'rgpd/third-party-url',
|
|
258
|
+
urlOrigin: origin,
|
|
259
|
+
start: attr.start,
|
|
260
|
+
message: `[rgpd/third-party-url] <${tag} ${attrName}="${url}"> in ${filename} loads a third-party resource without consent: self-host it (e.g. @prunellejs/seo fonts or public/) or wrap it in <ConsentGate category="...">.`,
|
|
261
|
+
})
|
|
262
|
+
}
|
|
323
263
|
return
|
|
324
|
-
enter(node)
|
|
325
|
-
const keys = visitorKeys[node.type]
|
|
326
|
-
if (keys !== undefined) {
|
|
327
|
-
for (let i = 0; i < keys.length; i++)
|
|
328
|
-
walkAst((node as unknown as Record<string, unknown>)[keys[i]!], enter, exit)
|
|
329
264
|
}
|
|
330
|
-
exit?.(node)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function collectLabelTargets(program: Program): Set<string> {
|
|
334
|
-
const targets = new Set<string>()
|
|
335
|
-
walkAst(program, (node) => {
|
|
336
|
-
if (node.type !== 'JSXElement')
|
|
337
|
-
return
|
|
338
|
-
const tag = jsxTagName(node.openingElement.name)
|
|
339
|
-
if (tag !== 'label')
|
|
340
|
-
return
|
|
341
|
-
const attrs = node.openingElement.attributes
|
|
342
|
-
const key = attrTargetKey(findAttr(attrs, 'for') ?? findAttr(attrs, 'htmlFor'))
|
|
343
|
-
if (key !== undefined)
|
|
344
|
-
targets.add(key)
|
|
345
|
-
})
|
|
346
|
-
return targets
|
|
347
265
|
}
|
|
348
266
|
|
|
349
267
|
function checkThirdPartyElement(
|
|
@@ -354,84 +272,30 @@ function checkThirdPartyElement(
|
|
|
354
272
|
warnings: CompilerWarning[],
|
|
355
273
|
): void {
|
|
356
274
|
const attrs = element.openingElement.attributes
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (tag
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
275
|
+
if (THIRD_PARTY_SRC_TAGS.has(tag))
|
|
276
|
+
reportThirdPartyAttr(tag, 'src', findAttr(attrs, 'src'), filename, ignores, warnings)
|
|
277
|
+
if (THIRD_PARTY_SRCSET_TAGS.has(tag))
|
|
278
|
+
reportThirdPartyAttr(tag, 'srcset', findAttr(attrs, 'srcset'), filename, ignores, warnings, true)
|
|
279
|
+
if (tag === 'object')
|
|
280
|
+
reportThirdPartyAttr(tag, 'data', findAttr(attrs, 'data'), filename, ignores, warnings)
|
|
281
|
+
if (tag === 'link') {
|
|
364
282
|
const relVal = staticStringValueOf(findAttr(attrs, 'rel')?.value ?? null)
|
|
365
283
|
if (relVal === undefined)
|
|
366
284
|
return
|
|
367
285
|
const rels = relVal.toLowerCase().split(/\s+/)
|
|
368
|
-
if (
|
|
369
|
-
|
|
370
|
-
attr = findAttr(attrs, 'href')
|
|
371
|
-
attrName = 'href'
|
|
286
|
+
if (rels.some(r => THIRD_PARTY_LINK_RELS.has(r)))
|
|
287
|
+
reportThirdPartyAttr(tag, 'href', findAttr(attrs, 'href'), filename, ignores, warnings)
|
|
372
288
|
}
|
|
373
|
-
if (attr === undefined)
|
|
374
|
-
return
|
|
375
|
-
const url = staticStringValueOf(attr.value)
|
|
376
|
-
if (url === undefined)
|
|
377
|
-
return
|
|
378
|
-
const origin = thirdPartyOrigin(url)
|
|
379
|
-
if (origin === undefined || isIgnoredAt(ignores, 'rgpd/third-party-url', attr.start))
|
|
380
|
-
return
|
|
381
|
-
warnings.push({
|
|
382
|
-
rule: 'rgpd/third-party-url',
|
|
383
|
-
urlOrigin: origin,
|
|
384
|
-
start: attr.start,
|
|
385
|
-
message: `[rgpd/third-party-url] <${tag} ${attrName}="${url}"> in ${filename} loads a third-party resource without consent: self-host it (e.g. @prunellejs/seo fonts or public/) or wrap it in <ConsentGate category="...">.`,
|
|
386
|
-
})
|
|
387
289
|
}
|
|
388
290
|
|
|
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)
|
|
291
|
+
function definitelyExits(stmt: Node): boolean {
|
|
292
|
+
if (stmt.type === 'ReturnStatement' || stmt.type === 'ThrowStatement')
|
|
293
|
+
return true
|
|
294
|
+
if (stmt.type === 'BlockStatement')
|
|
295
|
+
return stmt.body.length > 0 && definitelyExits(stmt.body[stmt.body.length - 1]!)
|
|
296
|
+
if (stmt.type === 'IfStatement')
|
|
297
|
+
return stmt.alternate !== null && definitelyExits(stmt.consequent) && definitelyExits(stmt.alternate)
|
|
298
|
+
return false
|
|
435
299
|
}
|
|
436
300
|
|
|
437
301
|
/** Runs RGAA & RGPD static JSX compliance checks on `program`, appending warnings (never throwing). */
|
|
@@ -443,36 +307,119 @@ export function checkCompliance(
|
|
|
443
307
|
resolveTag: (tag: string) => string | undefined,
|
|
444
308
|
): void {
|
|
445
309
|
const ignores = parsePrunelleIgnores(code)
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
let consentGateDepth = 0
|
|
449
|
-
const labelFlags: boolean[] = []
|
|
450
|
-
const consentFlags: boolean[] = []
|
|
310
|
+
const isIgnored = (rule: RgaaJsxRule, elementStart: number, attrStart?: number): boolean =>
|
|
311
|
+
isIgnoredAt(ignores, rule, elementStart) || (attrStart !== undefined && isIgnoredAt(ignores, rule, attrStart))
|
|
451
312
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
(
|
|
455
|
-
|
|
456
|
-
|
|
313
|
+
const visitChildren = (node: Node, ancestors: AncestorState, scope: RgaaScope, labelTargets: ReadonlySet<string>): void => {
|
|
314
|
+
const keys = visitorKeys[node.type]
|
|
315
|
+
if (keys === undefined)
|
|
316
|
+
return
|
|
317
|
+
const rec = node as unknown as Record<string, unknown>
|
|
318
|
+
for (let i = 0; i < keys.length; i++)
|
|
319
|
+
visit(rec[keys[i]!], ancestors, scope, labelTargets)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const visit = (value: unknown, ancestors: AncestorState, scope: RgaaScope, labelTargets: ReadonlySet<string>): void => {
|
|
323
|
+
if (value === null || typeof value !== 'object')
|
|
324
|
+
return
|
|
325
|
+
if (Array.isArray(value)) {
|
|
326
|
+
for (let i = 0; i < value.length; i++)
|
|
327
|
+
visit(value[i], ancestors, scope, labelTargets)
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
const node = value as Node
|
|
331
|
+
if (typeof node.type !== 'string')
|
|
332
|
+
return
|
|
333
|
+
|
|
334
|
+
if (isInlineMapCall(node)) {
|
|
335
|
+
visit(node.callee, ancestors, scope, labelTargets)
|
|
336
|
+
const cb = unwrapTsExpr(node.arguments[0]!)
|
|
337
|
+
if (cb.type === 'ArrowFunctionExpression' || cb.type === 'FunctionExpression') {
|
|
338
|
+
const loopAncestors: AncestorState = ancestors.inLoop ? ancestors : { ...ancestors, inLoop: true }
|
|
339
|
+
visitChildren(cb, loopAncestors, createRgaaScope(), labelTargets)
|
|
340
|
+
}
|
|
341
|
+
for (let i = 1; i < node.arguments.length; i++)
|
|
342
|
+
visit(node.arguments[i], ancestors, scope, labelTargets)
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (isFunctionNode(node)) {
|
|
347
|
+
const resetAncestors: AncestorState = {
|
|
348
|
+
labelDepth: 0,
|
|
349
|
+
consentGateDepth: ancestors.consentGateDepth,
|
|
350
|
+
interactiveAncestor: undefined,
|
|
351
|
+
inLoop: false,
|
|
352
|
+
}
|
|
353
|
+
visitChildren(node, resetAncestors, createRgaaScope(), collectDirectLabelTargets(node))
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (node.type === 'ConditionalExpression') {
|
|
358
|
+
visit(node.test, ancestors, scope, labelTargets)
|
|
359
|
+
const branchA = cloneRgaaScope(scope)
|
|
360
|
+
const branchB = cloneRgaaScope(scope)
|
|
361
|
+
visit(node.consequent, ancestors, branchA, labelTargets)
|
|
362
|
+
visit(node.alternate, ancestors, branchB, labelTargets)
|
|
363
|
+
mergeRgaaScope(scope, branchA)
|
|
364
|
+
mergeRgaaScope(scope, branchB)
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (node.type === 'IfStatement') {
|
|
369
|
+
visit(node.test, ancestors, scope, labelTargets)
|
|
370
|
+
const branchA = cloneRgaaScope(scope)
|
|
371
|
+
visit(node.consequent, ancestors, branchA, labelTargets)
|
|
372
|
+
const branchB = cloneRgaaScope(scope)
|
|
373
|
+
if (node.alternate !== null)
|
|
374
|
+
visit(node.alternate, ancestors, branchB, labelTargets)
|
|
375
|
+
if (!definitelyExits(node.consequent))
|
|
376
|
+
mergeRgaaScope(scope, branchA)
|
|
377
|
+
if (node.alternate !== null && !definitelyExits(node.alternate))
|
|
378
|
+
mergeRgaaScope(scope, branchB)
|
|
379
|
+
return
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (node.type === 'JSXElement') {
|
|
457
383
|
const tag = jsxTagName(node.openingElement.name)
|
|
458
|
-
|
|
459
|
-
|
|
384
|
+
const attrs = node.openingElement.attributes
|
|
385
|
+
if (tag !== '' && !isComponentTag(tag)) {
|
|
386
|
+
checkRgaaElement(node, tag, {
|
|
387
|
+
filename,
|
|
388
|
+
inLabel: ancestors.labelDepth > 0,
|
|
389
|
+
inLoop: ancestors.inLoop,
|
|
390
|
+
interactiveAncestor: ancestors.interactiveAncestor,
|
|
391
|
+
labelTargets,
|
|
392
|
+
scope,
|
|
393
|
+
isIgnored,
|
|
394
|
+
warnings,
|
|
395
|
+
})
|
|
396
|
+
if (ancestors.consentGateDepth === 0)
|
|
397
|
+
checkThirdPartyElement(node, tag, filename, ignores, warnings)
|
|
398
|
+
}
|
|
399
|
+
visit(attrs, ancestors, scope, labelTargets)
|
|
400
|
+
const opensLabel = tag === 'label' || (isComponentTag(tag) && hasNonEmptyAttr(attrs, 'label'))
|
|
460
401
|
const opensConsentGate = resolveTag(tag) === 'ConsentGate'
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
402
|
+
const nextInteractive = INTERACTIVE_ANCESTORS.has(tag) ? tag : ancestors.interactiveAncestor
|
|
403
|
+
const childAncestors = opensLabel || opensConsentGate || nextInteractive !== ancestors.interactiveAncestor
|
|
404
|
+
? {
|
|
405
|
+
labelDepth: ancestors.labelDepth + (opensLabel ? 1 : 0),
|
|
406
|
+
consentGateDepth: ancestors.consentGateDepth + (opensConsentGate ? 1 : 0),
|
|
407
|
+
interactiveAncestor: nextInteractive,
|
|
408
|
+
inLoop: ancestors.inLoop,
|
|
409
|
+
}
|
|
410
|
+
: ancestors
|
|
411
|
+
visit(node.children, childAncestors, scope, labelTargets)
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
visitChildren(node, ancestors, scope, labelTargets)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
visit(
|
|
419
|
+
program,
|
|
420
|
+
{ labelDepth: 0, consentGateDepth: 0, interactiveAncestor: undefined, inLoop: false },
|
|
421
|
+
createRgaaScope(),
|
|
422
|
+
collectDirectLabelTargets(program),
|
|
476
423
|
)
|
|
477
424
|
}
|
|
478
425
|
|
|
@@ -531,6 +478,11 @@ function normalizePath(path: string): string {
|
|
|
531
478
|
return withSlash.length > 1 && withSlash.endsWith('/') ? withSlash.slice(0, -1).toLowerCase() : withSlash.toLowerCase()
|
|
532
479
|
}
|
|
533
480
|
|
|
481
|
+
function stripLocalePrefix(normalizedPath: string): string {
|
|
482
|
+
const m = LOCALE_PREFIX_RE.exec(normalizedPath)
|
|
483
|
+
return m !== null ? m[1]! : normalizedPath
|
|
484
|
+
}
|
|
485
|
+
|
|
534
486
|
/** Checks project-level LCEN legal notice and RGAA accessibility statement routes. */
|
|
535
487
|
export function checkRouteCompliance(pageRoutePaths: readonly string[], compliance?: ComplianceConfig | undefined): string[] {
|
|
536
488
|
if (pageRoutePaths.length === 0)
|
|
@@ -541,8 +493,8 @@ export function checkRouteCompliance(pageRoutePaths: readonly string[], complian
|
|
|
541
493
|
if (!isRuleIgnored('lcen/legal-notice', compliance)) {
|
|
542
494
|
const custom = typeof compliance?.legalNotice === 'string' ? normalizePath(compliance.legalNotice) : undefined
|
|
543
495
|
const hasLegal = custom !== undefined
|
|
544
|
-
? normalized.has(custom)
|
|
545
|
-
: [...normalized].some(p => DEFAULT_LEGAL_PATHS.has(p))
|
|
496
|
+
? normalized.has(custom) || [...normalized].some(p => stripLocalePrefix(p) === custom)
|
|
497
|
+
: [...normalized].some(p => DEFAULT_LEGAL_PATHS.has(p) || DEFAULT_LEGAL_PATHS.has(stripLocalePrefix(p)))
|
|
546
498
|
if (!hasLegal) {
|
|
547
499
|
const expected = custom ?? '/mentions-legales (or /legal)'
|
|
548
500
|
out.push(formatDiagnostic('prunelle.config.ts:1:1', `[lcen/legal-notice] App has no legal notice route: add ${expected}, set compliance.legalNotice, or silence with compliance: { legalNotice: false }.`, 'warning'))
|
|
@@ -550,9 +502,9 @@ export function checkRouteCompliance(pageRoutePaths: readonly string[], complian
|
|
|
550
502
|
}
|
|
551
503
|
|
|
552
504
|
if (compliance?.publicBody === true && !isRuleIgnored('rgaa/accessibility-statement', compliance)) {
|
|
553
|
-
const hasA11y = [...normalized].some(p => ACCESSIBILITY_PATHS.has(p))
|
|
505
|
+
const hasA11y = [...normalized].some(p => ACCESSIBILITY_PATHS.has(p) || ACCESSIBILITY_PATHS.has(stripLocalePrefix(p)))
|
|
554
506
|
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)
|
|
507
|
+
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
508
|
}
|
|
557
509
|
}
|
|
558
510
|
|