prunelle 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// What an element says or carries, read from its children: a link's whole text (RGAA 6.1), a video's caption track (4.3), a table's caption (5.4).
|
|
2
|
+
|
|
3
|
+
import type { JSXChild, JSXElement } from 'oxc-parser'
|
|
4
|
+
import { isComponentTag, jsxTagName, staticLiteral, unwrapTsExpr } from './shared'
|
|
5
|
+
|
|
6
|
+
// Link texts that say nothing of where the link goes once read alone, as a screen reader's list of links reads them.
|
|
7
|
+
const GENERIC_LINK_TEXTS = new Set([
|
|
8
|
+
'ici', 'cliquez ici', 'cliquer ici', 'en savoir plus', 'savoir plus', 'lire la suite', 'la suite', 'suite', 'voir plus', 'voir', 'plus', 'plus de détails', 'détails', 'lien', 'ce lien',
|
|
9
|
+
'here', 'click here', 'read more', 'more', 'learn more', 'see more', 'more details', 'details', 'link', 'this link',
|
|
10
|
+
])
|
|
11
|
+
// Punctuation and arrows a generic text is often dressed in: "Lire la suite…", "En savoir plus →".
|
|
12
|
+
// Pieces join as the browser renders them, so `<span>Lire</span>la suite` reads "Lirela suite".
|
|
13
|
+
const DRESSING_RE = /[\s.,;:!?…»«›‹→←>()[\]-]+/g
|
|
14
|
+
const CAPTION_KINDS = new Set(['captions', 'subtitles'])
|
|
15
|
+
|
|
16
|
+
function textOf(children: readonly JSXChild[]): string | undefined {
|
|
17
|
+
let text = ''
|
|
18
|
+
for (const child of children) {
|
|
19
|
+
if (child.type === 'JSXText') {
|
|
20
|
+
text += child.value
|
|
21
|
+
}
|
|
22
|
+
else if (child.type === 'JSXFragment') {
|
|
23
|
+
const inner = textOf(child.children)
|
|
24
|
+
if (inner === undefined)
|
|
25
|
+
return undefined
|
|
26
|
+
text += inner
|
|
27
|
+
}
|
|
28
|
+
else if (child.type === 'JSXElement') {
|
|
29
|
+
const tag = jsxTagName(child.openingElement.name)
|
|
30
|
+
// A component may render anything, and an image or a drawing adds its own name.
|
|
31
|
+
const inner = isComponentTag(tag) || tag === 'img' || tag === 'svg' ? undefined : textOf(child.children)
|
|
32
|
+
if (inner === undefined)
|
|
33
|
+
return undefined
|
|
34
|
+
text += inner
|
|
35
|
+
}
|
|
36
|
+
else if (child.type === 'JSXExpressionContainer' && child.expression.type !== 'JSXEmptyExpression') {
|
|
37
|
+
const literal = staticLiteral(unwrapTsExpr(child.expression))
|
|
38
|
+
if (!literal.ok || typeof literal.value !== 'string')
|
|
39
|
+
return undefined
|
|
40
|
+
text += literal.value
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return text
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The text of a link when the whole of it is generic ("Lire la suite", "click here"); undefined when it names its target or is not known before render. */
|
|
47
|
+
export function genericLinkText(element: JSXElement): string | undefined {
|
|
48
|
+
const text = textOf(element.children)
|
|
49
|
+
if (text === undefined)
|
|
50
|
+
return undefined
|
|
51
|
+
return GENERIC_LINK_TEXTS.has(text.toLowerCase().replace(DRESSING_RE, ' ').trim()) ? text.replace(/\s+/g, ' ').trim() : undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether `children` may hold an element `matches` accepts: a component or an expression might render one. */
|
|
55
|
+
function mayHold(children: readonly JSXChild[], matches: (el: JSXElement, tag: string) => boolean): boolean {
|
|
56
|
+
for (const child of children) {
|
|
57
|
+
if (child.type === 'JSXExpressionContainer' && child.expression.type !== 'JSXEmptyExpression')
|
|
58
|
+
return true
|
|
59
|
+
if (child.type === 'JSXFragment' && mayHold(child.children, matches))
|
|
60
|
+
return true
|
|
61
|
+
if (child.type === 'JSXElement') {
|
|
62
|
+
const tag = jsxTagName(child.openingElement.name)
|
|
63
|
+
if (isComponentTag(tag) || matches(child, tag))
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A track whose kind is captions or subtitles, or is set by a spread or an expression known only at render.
|
|
71
|
+
function mayCaption(track: JSXElement): boolean {
|
|
72
|
+
for (const attr of track.openingElement.attributes) {
|
|
73
|
+
if (attr.type === 'JSXSpreadAttribute')
|
|
74
|
+
return true
|
|
75
|
+
if (attr.name.type !== 'JSXIdentifier' || attr.name.name !== 'kind' || attr.value === null)
|
|
76
|
+
continue
|
|
77
|
+
if (attr.value.type === 'Literal')
|
|
78
|
+
return CAPTION_KINDS.has(String(attr.value.value).toLowerCase())
|
|
79
|
+
if (attr.value.type !== 'JSXExpressionContainer' || attr.value.expression.type === 'JSXEmptyExpression')
|
|
80
|
+
return false
|
|
81
|
+
const literal = staticLiteral(unwrapTsExpr(attr.value.expression))
|
|
82
|
+
return !literal.ok || CAPTION_KINDS.has(String(literal.value).toLowerCase())
|
|
83
|
+
}
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A `<video>` none of whose children is, or may render, a `<track kind="captions">` or `kind="subtitles"`. */
|
|
88
|
+
export function videoWithoutCaptions(element: JSXElement): boolean {
|
|
89
|
+
return !mayHold(element.children, (el, tag) => tag === 'track' && mayCaption(el))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A `<table>` none of whose children is, or may render, a `<caption>`. */
|
|
93
|
+
export function tableWithoutCaption(element: JSXElement): boolean {
|
|
94
|
+
return !mayHold(element.children, (_el, tag) => tag === 'caption')
|
|
95
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The RGAA 4.1 criteria each static rule partly covers, so `prunelle check` can say how little a clean run proves.
|
|
2
|
+
|
|
3
|
+
import type { ContrastRule } from './compliance-contrast'
|
|
4
|
+
import type { RgaaJsxRule } from './compliance-rgaa'
|
|
5
|
+
import type { RgaaPageRule } from './compliance-rgaa-pages'
|
|
6
|
+
|
|
7
|
+
/** The criteria of the RGAA 4.1. */
|
|
8
|
+
export const RGAA_CRITERIA_TOTAL = 106
|
|
9
|
+
|
|
10
|
+
// Every rule has an entry, so a new rule cannot ship without saying which criteria it touches. `rgaa/autofocus` maps to none: no criterion names it.
|
|
11
|
+
const CRITERIA_BY_RULE: Record<RgaaJsxRule | RgaaPageRule | ContrastRule | 'rgaa/document-lang', readonly string[]> = {
|
|
12
|
+
'rgaa/img-alt': ['1.1', '1.2'],
|
|
13
|
+
'rgaa/form-label': ['11.1'],
|
|
14
|
+
'rgaa/accessible-name': ['1.1', '6.2', '11.9'],
|
|
15
|
+
'rgaa/duplicate-id': ['8.2'],
|
|
16
|
+
'rgaa/positive-tabindex': ['12.8'],
|
|
17
|
+
'rgaa/nested-control': ['8.2'],
|
|
18
|
+
'rgaa/link-as-button': ['7.1'],
|
|
19
|
+
'rgaa/unknown-role': ['7.1'],
|
|
20
|
+
'rgaa/unknown-aria': ['7.1'],
|
|
21
|
+
'rgaa/invalid-aria-value': ['7.1'],
|
|
22
|
+
'rgaa/skipped-heading': ['9.1'],
|
|
23
|
+
'rgaa/table-without-header': ['5.6'],
|
|
24
|
+
'rgaa/fieldset-without-legend': ['11.5', '11.6'],
|
|
25
|
+
'rgaa/click-without-key': ['7.3'],
|
|
26
|
+
'rgaa/autofocus': [],
|
|
27
|
+
'rgaa/meta-refresh': ['13.1'],
|
|
28
|
+
'rgaa/role-without-focus': ['7.3'],
|
|
29
|
+
'rgaa/mouse-only': ['7.3'],
|
|
30
|
+
'rgaa/frame-title': ['2.1'],
|
|
31
|
+
'rgaa/empty-heading': ['9.1'],
|
|
32
|
+
'rgaa/autocomplete': ['11.13'],
|
|
33
|
+
'rgaa/generic-link-text': ['6.1'],
|
|
34
|
+
'rgaa/video-captions': ['4.3'],
|
|
35
|
+
'rgaa/table-caption': ['5.4'],
|
|
36
|
+
'rgaa/document-lang': ['8.3'],
|
|
37
|
+
'rgaa/skip-link': ['12.7'],
|
|
38
|
+
'rgaa/page-title': ['8.5'],
|
|
39
|
+
'rgaa/contrast': ['3.2'],
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** How many distinct RGAA criteria at least one rule of `prunelle check` partly covers. */
|
|
43
|
+
export function rgaaCriteriaCovered(): number {
|
|
44
|
+
return new Set(Object.values(CRITERIA_BY_RULE).flat()).size
|
|
45
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// The RGAA criteria a page meets through its layouts as much as through itself: a link past the blocks every page repeats (12.7) and a title (8.5).
|
|
2
|
+
|
|
3
|
+
import type { JSXChild, JSXElement, Program } from 'oxc-parser'
|
|
4
|
+
import type { ModuleAnalysis } from './analyze'
|
|
5
|
+
import { basename } from 'node:path'
|
|
6
|
+
import { relPosix } from '../build/files'
|
|
7
|
+
import { ancestorFiles, fileToRoutePath } from '../build/routes'
|
|
8
|
+
import { walk } from './ast'
|
|
9
|
+
import { isComponentTag, jsxTagName, staticLiteral, unwrapTsExpr } from './shared'
|
|
10
|
+
|
|
11
|
+
export type RgaaPageRule = 'rgaa/skip-link' | 'rgaa/page-title'
|
|
12
|
+
|
|
13
|
+
export interface RgaaPageFinding {
|
|
14
|
+
rule: RgaaPageRule
|
|
15
|
+
/** From the project root. */
|
|
16
|
+
file: string
|
|
17
|
+
line: number
|
|
18
|
+
message: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Blocks a layout repeats on every page, which a keyboard user tabs through on each one unless a link jumps past them.
|
|
22
|
+
const REPEATED_BLOCKS = new Set(['header', 'nav'])
|
|
23
|
+
|
|
24
|
+
function hrefOf(el: JSXElement): string | undefined {
|
|
25
|
+
for (const attr of el.openingElement.attributes) {
|
|
26
|
+
if (attr.type !== 'JSXAttribute' || attr.name.type !== 'JSXIdentifier' || attr.name.name !== 'href' || attr.value === null)
|
|
27
|
+
continue
|
|
28
|
+
if (attr.value.type === 'Literal')
|
|
29
|
+
return String(attr.value.value)
|
|
30
|
+
if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
31
|
+
const literal = staticLiteral(unwrapTsExpr(attr.value.expression))
|
|
32
|
+
return literal.ok && typeof literal.value === 'string' ? literal.value : undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What a layout renders that 12.7 cares about: the offset of its first `<header>` or `<nav>`, and whether it links to an anchor of the page (`<a href="#main">`). */
|
|
39
|
+
function layoutBlocks(program: Program): { block: number | undefined, skipLink: boolean } {
|
|
40
|
+
let block: number | undefined
|
|
41
|
+
let skipLink = false
|
|
42
|
+
walk(program, (node) => {
|
|
43
|
+
if (node.type !== 'JSXElement')
|
|
44
|
+
return
|
|
45
|
+
const tag = jsxTagName(node.openingElement.name)
|
|
46
|
+
if (block === undefined && REPEATED_BLOCKS.has(tag))
|
|
47
|
+
block = node.start
|
|
48
|
+
const href = tag === 'a' ? hrefOf(node) : undefined
|
|
49
|
+
if (href !== undefined && href.length > 1 && href.startsWith('#'))
|
|
50
|
+
skipLink = true
|
|
51
|
+
})
|
|
52
|
+
return { block, skipLink }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A <title> with text, or a component or an expression that may render one.
|
|
56
|
+
function mayHoldTitle(children: readonly JSXChild[]): boolean {
|
|
57
|
+
for (const child of children) {
|
|
58
|
+
if (child.type === 'JSXExpressionContainer' && child.expression.type !== 'JSXEmptyExpression')
|
|
59
|
+
return true
|
|
60
|
+
if (child.type === 'JSXFragment' && mayHoldTitle(child.children))
|
|
61
|
+
return true
|
|
62
|
+
if (child.type !== 'JSXElement')
|
|
63
|
+
continue
|
|
64
|
+
const tag = jsxTagName(child.openingElement.name)
|
|
65
|
+
if (isComponentTag(tag) && tag !== 'Head')
|
|
66
|
+
return true
|
|
67
|
+
if (tag === 'title' && child.children.some(c => c.type !== 'JSXText' || c.value.trim() !== ''))
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether a module renders a `<Head>` holding a title, or something that may render one. */
|
|
74
|
+
function rendersTitle(program: Program): boolean {
|
|
75
|
+
let found = false
|
|
76
|
+
walk(program, (node) => {
|
|
77
|
+
if (found)
|
|
78
|
+
return false
|
|
79
|
+
if (node.type === 'JSXElement' && jsxTagName(node.openingElement.name) === 'Head' && mayHoldTitle(node.children))
|
|
80
|
+
found = true
|
|
81
|
+
return undefined
|
|
82
|
+
})
|
|
83
|
+
return found
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function lineAt(code: string, offset: number): number {
|
|
87
|
+
let line = 1
|
|
88
|
+
for (let i = code.indexOf('\n'); i !== -1 && i < offset; i = code.indexOf('\n', i + 1))
|
|
89
|
+
line++
|
|
90
|
+
return line
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface RgaaPageInput {
|
|
94
|
+
root: string
|
|
95
|
+
routesDir: string
|
|
96
|
+
routeFiles: readonly string[]
|
|
97
|
+
analyses: ReadonlyMap<string, ModuleAnalysis>
|
|
98
|
+
/** Whether a plugin (`@prunellejs/seo`) reports a page with no title itself. */
|
|
99
|
+
titleChecked: boolean
|
|
100
|
+
source: (file: string) => string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A layout that renders a header or a navigation with no skip link in it or above it, and a page that neither it nor its layouts give a title. A file not analysed counts as compliant, as nothing is known of it. */
|
|
104
|
+
export function rgaaPageFindings(input: RgaaPageInput): RgaaPageFinding[] {
|
|
105
|
+
const { root, routesDir, routeFiles, analyses, titleChecked, source } = input
|
|
106
|
+
const findings: RgaaPageFinding[] = []
|
|
107
|
+
const blocks = new Map<string, { block: number | undefined, skipLink: boolean }>()
|
|
108
|
+
const blocksOf = (file: string): { block: number | undefined, skipLink: boolean } => {
|
|
109
|
+
let found = blocks.get(file)
|
|
110
|
+
if (found === undefined) {
|
|
111
|
+
const program = analyses.get(file)?.program
|
|
112
|
+
found = program === undefined ? { block: undefined, skipLink: true } : layoutBlocks(program)
|
|
113
|
+
blocks.set(file, found)
|
|
114
|
+
}
|
|
115
|
+
return found
|
|
116
|
+
}
|
|
117
|
+
for (const file of routeFiles) {
|
|
118
|
+
const layouts = ancestorFiles(routesDir, file, ['_layout.tsx'])
|
|
119
|
+
if (basename(file) === '_layout.tsx') {
|
|
120
|
+
const { block } = blocksOf(file)
|
|
121
|
+
if (block !== undefined && !layouts.some(layout => blocksOf(layout).skipLink)) {
|
|
122
|
+
const rel = relPosix(root, file)
|
|
123
|
+
findings.push({ rule: 'rgaa/skip-link', file: rel, line: lineAt(source(file), block), message: `${rel} repeats a header or a navigation on every page with no link to jump past it, which a keyboard user tabs through on each page: add <a href="#main" class="skip-link">Aller au contenu</a> as its first element and id="main" on <main>.` })
|
|
124
|
+
}
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
const analysis = analyses.get(file)
|
|
128
|
+
if (titleChecked || basename(file).startsWith('_') || analysis === undefined || !analysis.exportedNames.includes('default'))
|
|
129
|
+
continue
|
|
130
|
+
const titled = [file, ...layouts].some((f) => {
|
|
131
|
+
const program = analyses.get(f)?.program
|
|
132
|
+
return program === undefined || rendersTitle(program)
|
|
133
|
+
})
|
|
134
|
+
if (!titled) {
|
|
135
|
+
const rel = relPosix(root, file)
|
|
136
|
+
findings.push({ rule: 'rgaa/page-title', file: rel, line: 1, message: `Route "${fileToRoutePath(routesDir, file)}" has no <title>, so a tab, a bookmark and a screen reader all name it by its URL: add <Head><title>...</title></Head> to ${rel}, or a default one to its _layout.tsx.` })
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return findings
|
|
140
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { JSXAttribute, JSXAttributeItem, JSXChild, JSXElement, Node } from 'oxc-parser'
|
|
4
4
|
import type { CompilerWarning } from './mistakes'
|
|
5
|
+
import { genericLinkText, tableWithoutCaption, videoWithoutCaptions } from './compliance-rgaa-content'
|
|
5
6
|
import { cleanJsxText, isComponentTag, jsxTagName, staticLiteral, unwrapParens, unwrapTsExpr } from './shared'
|
|
6
7
|
|
|
7
8
|
export const RGAA_JSX_RULES = [
|
|
@@ -26,6 +27,9 @@ export const RGAA_JSX_RULES = [
|
|
|
26
27
|
'rgaa/frame-title',
|
|
27
28
|
'rgaa/empty-heading',
|
|
28
29
|
'rgaa/autocomplete',
|
|
30
|
+
'rgaa/generic-link-text',
|
|
31
|
+
'rgaa/video-captions',
|
|
32
|
+
'rgaa/table-caption',
|
|
29
33
|
] as const
|
|
30
34
|
|
|
31
35
|
export type RgaaJsxRule = (typeof RGAA_JSX_RULES)[number]
|
|
@@ -567,6 +571,20 @@ function checkAutocomplete(element: JSXElement, tag: string, ctx: RgaaElementCon
|
|
|
567
571
|
emitWarning(ctx, 'rgaa/autocomplete', element.start, `[rgaa/autocomplete] <${tag}${name !== undefined ? ` name="${name}"` : ''}> in ${ctx.filename} collects personal data without autocomplete: add autocomplete="${token}".`)
|
|
568
572
|
}
|
|
569
573
|
|
|
574
|
+
// What a link says read alone, a video's captions and a table's title.
|
|
575
|
+
function checkContent(element: JSXElement, tag: string, ctx: RgaaElementContext): void {
|
|
576
|
+
const attrs = element.openingElement.attributes
|
|
577
|
+
const text = tag === 'a' && !hasLabelAttr(attrs) ? genericLinkText(element) : undefined
|
|
578
|
+
if (text !== undefined)
|
|
579
|
+
emitWarning(ctx, 'rgaa/generic-link-text', element.start, `[rgaa/generic-link-text] <a>${text}</a> in ${ctx.filename} does not say where it goes when read alone, as a screen reader lists links: name the target in its text, or add an aria-label that starts with "${text}" and names it.`)
|
|
580
|
+
// A muted video with no controls has no sound to caption: a background loop.
|
|
581
|
+
const silent = hasHandler(attrs, ['muted']) && !hasHandler(attrs, ['controls'])
|
|
582
|
+
if (tag === 'video' && !silent && !isAriaHidden(attrs) && videoWithoutCaptions(element))
|
|
583
|
+
emitWarning(ctx, 'rgaa/video-captions', element.start, `[rgaa/video-captions] <video> in ${ctx.filename} has no captions: add <track kind="captions" src="....vtt" srclang="fr">, or mute it and drop its controls when it has no sound to follow.`)
|
|
584
|
+
if (tag === 'table' && !isPresentational(attrs) && !hasLabelAttr(attrs) && tableWithoutCaption(element))
|
|
585
|
+
emitWarning(ctx, 'rgaa/table-caption', element.start, `[rgaa/table-caption] <table> in ${ctx.filename} has no title: add a <caption> as its first child, or aria-labelledby naming the heading above it; a layout table takes role="presentation".`)
|
|
586
|
+
}
|
|
587
|
+
|
|
570
588
|
// The ui Select draws its own combobox, so it needs a name as a native <select> does.
|
|
571
589
|
const SELECT_COMPONENT_RE = /(?:^|\.)Select$/
|
|
572
590
|
|
|
@@ -610,5 +628,6 @@ export function checkRgaaElement(element: JSXElement, tag: string, ctx: RgaaElem
|
|
|
610
628
|
checkKeyboardReach(element, tag, ctx)
|
|
611
629
|
checkMissingNames(element, tag, ctx)
|
|
612
630
|
checkAutocomplete(element, tag, ctx)
|
|
631
|
+
checkContent(element, tag, ctx)
|
|
613
632
|
}
|
|
614
633
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The rule ids `compliance.ignore` and `prunelle-ignore` comments name, and the config that silences them.
|
|
2
|
+
|
|
3
|
+
import type { ContrastRule } from './compliance-contrast'
|
|
4
|
+
import type { EcoJsxRule } from './compliance-eco'
|
|
5
|
+
import type { RgaaJsxRule } from './compliance-rgaa'
|
|
6
|
+
import type { RgaaPageRule } from './compliance-rgaa-pages'
|
|
7
|
+
import type { PrunellePluginRules } from '../plugins/public'
|
|
8
|
+
import { ECO_JSX_RULES } from './compliance-eco'
|
|
9
|
+
import { RGAA_JSX_RULES } from './compliance-rgaa'
|
|
10
|
+
|
|
11
|
+
export type ComplianceRule =
|
|
12
|
+
| RgaaJsxRule
|
|
13
|
+
| RgaaPageRule
|
|
14
|
+
| ContrastRule
|
|
15
|
+
| EcoJsxRule
|
|
16
|
+
| 'rgesn/large-public-file'
|
|
17
|
+
| 'rgesn/declaration'
|
|
18
|
+
| 'rgesn/island-by-value'
|
|
19
|
+
| 'rgpd/third-party-url'
|
|
20
|
+
| 'rgpd/consent-retention'
|
|
21
|
+
| 'rgpd/consent-preferences'
|
|
22
|
+
| 'rgpd/cookie-category'
|
|
23
|
+
| 'rgpd/cookie-purpose'
|
|
24
|
+
| 'rgpd/privacy-notice'
|
|
25
|
+
| 'lcen/legal-notice'
|
|
26
|
+
| 'rgaa/document-lang'
|
|
27
|
+
| 'rgaa/accessibility-statement'
|
|
28
|
+
| 'security/csrf-off'
|
|
29
|
+
| 'security/proxy-no-site'
|
|
30
|
+
| 'security/html-sink'
|
|
31
|
+
| FormWarningRule
|
|
32
|
+
|
|
33
|
+
/** The warnings of the form-vs-action check (`cli/check-forms.ts`), silenced like the compliance rules. */
|
|
34
|
+
export type FormWarningRule = 'action/unguarded-public-form' | 'form/invalid-option' | 'form/schema-unsupported' | 'form/unchecked'
|
|
35
|
+
|
|
36
|
+
export interface ComplianceConfig {
|
|
37
|
+
/** Compliance rules to silence across the app, the warning rules of the plugins it uses included. */
|
|
38
|
+
ignore?: readonly (ComplianceRule | keyof PrunellePluginRules)[] | undefined
|
|
39
|
+
/** Set `true` for French public-sector sites (RGAA requires an accessibility statement page). */
|
|
40
|
+
publicBody?: boolean | undefined
|
|
41
|
+
/** Custom route path for the legal notice page, or `false` to silence `lcen/legal-notice`. */
|
|
42
|
+
legalNotice?: string | false | undefined
|
|
43
|
+
/** Custom route path for the privacy notice page, or `false` to silence `rgpd/privacy-notice`. */
|
|
44
|
+
privacyNotice?: string | false | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const COMPLIANCE_RULES = new Set<ComplianceRule>([
|
|
48
|
+
...RGAA_JSX_RULES,
|
|
49
|
+
...ECO_JSX_RULES,
|
|
50
|
+
'rgesn/large-public-file',
|
|
51
|
+
'rgesn/declaration',
|
|
52
|
+
'rgesn/island-by-value',
|
|
53
|
+
'rgpd/third-party-url',
|
|
54
|
+
'rgpd/consent-retention',
|
|
55
|
+
'rgpd/consent-preferences',
|
|
56
|
+
'rgpd/cookie-category',
|
|
57
|
+
'rgpd/cookie-purpose',
|
|
58
|
+
'rgpd/privacy-notice',
|
|
59
|
+
'lcen/legal-notice',
|
|
60
|
+
'rgaa/document-lang',
|
|
61
|
+
'rgaa/accessibility-statement',
|
|
62
|
+
'rgaa/skip-link',
|
|
63
|
+
'rgaa/page-title',
|
|
64
|
+
'rgaa/contrast',
|
|
65
|
+
'security/csrf-off',
|
|
66
|
+
'security/proxy-no-site',
|
|
67
|
+
'security/html-sink',
|
|
68
|
+
'action/unguarded-public-form',
|
|
69
|
+
'form/invalid-option',
|
|
70
|
+
'form/schema-unsupported',
|
|
71
|
+
'form/unchecked',
|
|
72
|
+
])
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The rgpd/third-party-url warnings of a JSX element: a literal URL, a URL the source does not show, and a URL given to a component.
|
|
2
|
+
|
|
3
|
+
import type { JSXElement } from 'oxc-parser'
|
|
4
|
+
import type { CompilerWarning } from './mistakes'
|
|
5
|
+
import { thirdPartyComponentLoads, thirdPartyLoads, unreadableLoads } from './compliance-urls'
|
|
6
|
+
|
|
7
|
+
const FIX = 'self-host it (e.g. @prunellejs/seo fonts or public/) or wrap it in <ConsentGate category="...">'
|
|
8
|
+
|
|
9
|
+
/** Warns about the URLs a plain element loads, the ones prunelle can read and the ones it cannot. */
|
|
10
|
+
export function checkThirdPartyElement(
|
|
11
|
+
element: JSXElement,
|
|
12
|
+
tag: string,
|
|
13
|
+
filename: string,
|
|
14
|
+
isIgnored: (offset: number) => boolean,
|
|
15
|
+
warnings: CompilerWarning[],
|
|
16
|
+
): void {
|
|
17
|
+
const named = new Set<string>()
|
|
18
|
+
for (const load of thirdPartyLoads(element, tag)) {
|
|
19
|
+
named.add(load.attr)
|
|
20
|
+
if (isIgnored(load.start))
|
|
21
|
+
continue
|
|
22
|
+
warnings.push({
|
|
23
|
+
rule: 'rgpd/third-party-url',
|
|
24
|
+
urlOrigin: load.origin,
|
|
25
|
+
start: load.start,
|
|
26
|
+
message: `[rgpd/third-party-url] <${tag} ${load.attr}="${load.url}"> in ${filename} loads a third-party resource without consent: ${FIX}.`,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
for (const load of unreadableLoads(element, tag)) {
|
|
30
|
+
// An attribute that already names a third-party URL has its warning.
|
|
31
|
+
if (named.has(load.attr) || isIgnored(load.start))
|
|
32
|
+
continue
|
|
33
|
+
warnings.push({
|
|
34
|
+
rule: 'rgpd/third-party-url',
|
|
35
|
+
start: load.start,
|
|
36
|
+
message: `[rgpd/third-party-url] <${tag} ${load.attr}={...}> in ${filename} loads a URL prunelle cannot read, which may be another site's: ${FIX}, or add // prunelle-ignore rgpd/third-party-url when it always stays on this site.`,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Warns about a third-party URL given to a component, which may load it. */
|
|
42
|
+
export function checkThirdPartyComponent(
|
|
43
|
+
element: JSXElement,
|
|
44
|
+
tag: string,
|
|
45
|
+
filename: string,
|
|
46
|
+
isIgnored: (offset: number) => boolean,
|
|
47
|
+
warnings: CompilerWarning[],
|
|
48
|
+
): void {
|
|
49
|
+
for (const load of thirdPartyComponentLoads(element, tag)) {
|
|
50
|
+
if (isIgnored(load.start))
|
|
51
|
+
continue
|
|
52
|
+
warnings.push({
|
|
53
|
+
rule: 'rgpd/third-party-url',
|
|
54
|
+
urlOrigin: load.origin,
|
|
55
|
+
start: load.start,
|
|
56
|
+
message: `[rgpd/third-party-url] <${tag} ${load.attr}="${load.url}"> in ${filename} gives a third-party URL to a component that may load it without consent: ${FIX}.`,
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -128,6 +128,58 @@ function loadingAttrs(element: JSXElement, tag: string): Array<[string, JSXAttri
|
|
|
128
128
|
return out
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// What a template literal's static head says about where its URL points: a path on this site, a complete host, or a scheme with no URL to read.
|
|
132
|
+
const DECIDED_HEAD_RES = [/^\/(?!\/)./s, /^(?:https?:)?\/\/[^/?#]+[/?#]/i, /^(?:data|blob|mailto|tel):/i, /^[^:/?#]+\//, /^[#?]/]
|
|
133
|
+
|
|
134
|
+
// Whether an expression gives a URL the source does not show: a name, a call, a member, or a template whose start does not tell where it points.
|
|
135
|
+
function isUnreadableUrl(expr: Expression): boolean {
|
|
136
|
+
const node = unwrapTsExpr(expr)
|
|
137
|
+
switch (node.type) {
|
|
138
|
+
case 'Literal':
|
|
139
|
+
case 'ObjectExpression':
|
|
140
|
+
return false
|
|
141
|
+
case 'TemplateLiteral':
|
|
142
|
+
return node.expressions.length > 0 && !DECIDED_HEAD_RES.some(re => re.test(node.quasis[0]?.value.cooked ?? ''))
|
|
143
|
+
case 'ConditionalExpression':
|
|
144
|
+
return isUnreadableUrl(node.consequent) || isUnreadableUrl(node.alternate)
|
|
145
|
+
case 'LogicalExpression':
|
|
146
|
+
return isUnreadableUrl(node.left) || isUnreadableUrl(node.right)
|
|
147
|
+
default:
|
|
148
|
+
return true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The loading attributes of a plain element whose URL the source does not show, so prunelle cannot tell if it leaves the site. */
|
|
153
|
+
export function unreadableLoads(element: JSXElement, tag: string): Array<{ attr: string, start: number }> {
|
|
154
|
+
const out: Array<{ attr: string, start: number }> = []
|
|
155
|
+
for (const [name, attr] of loadingAttrs(element, tag)) {
|
|
156
|
+
const value = attr?.value
|
|
157
|
+
if (name !== 'style' && attr !== undefined && value?.type === 'JSXExpressionContainer' && value.expression.type !== 'JSXEmptyExpression' && isUnreadableUrl(value.expression))
|
|
158
|
+
out.push({ attr: name, start: attr.start })
|
|
159
|
+
}
|
|
160
|
+
return out
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// A link component takes the visitor somewhere else, it does not load anything.
|
|
164
|
+
const LINK_COMPONENT_RE = /(?:^|\.)(?:\w*Link|A|Anchor)$/
|
|
165
|
+
|
|
166
|
+
/** Third-party origins a component receives as a literal `src`, `href` or `url` prop, which it may well load. */
|
|
167
|
+
export function thirdPartyComponentLoads(element: JSXElement, tag: string): ThirdPartyLoad[] {
|
|
168
|
+
const out: ThirdPartyLoad[] = []
|
|
169
|
+
const attrs = element.openingElement.attributes
|
|
170
|
+
for (const name of ['src', 'href', 'url']) {
|
|
171
|
+
const attr = findAttr(attrs, name)
|
|
172
|
+
if (attr === undefined || (name === 'href' && LINK_COMPONENT_RE.test(tag)))
|
|
173
|
+
continue
|
|
174
|
+
for (const url of attrStrings(attr)) {
|
|
175
|
+
const origin = thirdPartyOrigin(url.split(EXPR_PLACEHOLDER, 1)[0]!)
|
|
176
|
+
if (origin !== undefined)
|
|
177
|
+
out.push({ attr: name, url, origin, start: attr.start })
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return out
|
|
181
|
+
}
|
|
182
|
+
|
|
131
183
|
/** Distinct third-party origins each loading attribute of a plain element points at. */
|
|
132
184
|
export function thirdPartyLoads(element: JSXElement, tag: string): ThirdPartyLoad[] {
|
|
133
185
|
const out: ThirdPartyLoad[] = []
|