prunelle 0.8.0 → 0.9.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 +61 -44
- package/package.json +7 -2
- package/src/a11y/declaration.ts +6 -10
- 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 +88 -134
- 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 +20 -10
- package/src/build/islands.ts +4 -1
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +19 -1
- package/src/build/plugin-host.ts +2 -0
- package/src/build/prerender.ts +2 -2
- package/src/build/reach.ts +14 -1
- package/src/build/report.ts +1 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +24 -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 +2 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +16 -100
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +40 -18
- package/src/cli/commands.ts +134 -14
- package/src/cli/docs.ts +21 -2
- 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 +2 -2
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +284 -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-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +70 -42
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +177 -346
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +170 -121
- package/src/compiler/ssr.ts +25 -440
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -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 +1 -1
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/extras.ts +2 -1
- package/src/dom/field-marks.ts +24 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +25 -5
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/prefetch.ts +132 -0
- package/src/dom/regions.ts +498 -0
- package/src/dom/swap.ts +245 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +39 -40
- package/src/eco/index.ts +5 -5
- package/src/href.ts +31 -0
- package/src/index.ts +9 -3
- 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 +8 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +120 -9
- package/src/reactivity/hmr.ts +90 -0
- package/src/reactivity/index.ts +38 -18
- package/src/reactivity/resource.ts +115 -0
- package/src/reactivity/seed.ts +39 -0
- package/src/reactivity/server-seed.ts +194 -0
- package/src/reactivity/store.ts +55 -1
- 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-registry.ts +6 -8
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +96 -0
- package/src/server/compress.ts +3 -1
- package/src/server/consent.ts +16 -2
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +50 -0
- package/src/server/csp-report.ts +86 -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 +33 -12
- package/src/server/http.ts +25 -10
- package/src/server/index.ts +101 -298
- package/src/server/loader.ts +1 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +26 -8
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +39 -10
- package/src/server/region.ts +3 -0
- package/src/server/request-handler.ts +370 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +41 -6
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +35 -19
- package/src/server/routing.ts +12 -11
- package/src/server/sanitize-html.ts +1 -1
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +9 -5
- package/src/server/shared-store.ts +314 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +14 -10
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +48 -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 +26 -3
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +23 -13
- package/src/ssr/navigation.ts +161 -14
- package/src/test/browser.ts +50 -22
- package/src/test/build-reuse.ts +70 -0
- package/src/test/index.ts +45 -6
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- 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 +3674 -2196
|
@@ -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,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[] = []
|
|
@@ -4,6 +4,8 @@ import type { JSXElement, Node, Program } from 'oxc-parser'
|
|
|
4
4
|
import type { ModuleAnalysis } from './analyze'
|
|
5
5
|
import type { EcoJsxRule } from './compliance-eco'
|
|
6
6
|
import type { RgaaJsxRule, RgaaScope } from './compliance-rgaa'
|
|
7
|
+
import type { ContrastRule } from './compliance-contrast'
|
|
8
|
+
import type { RgaaPageRule } from './compliance-rgaa-pages'
|
|
7
9
|
import type { CompilerWarning } from './mistakes'
|
|
8
10
|
import { existsSync, readFileSync } from 'node:fs'
|
|
9
11
|
import { basename, join } from 'node:path'
|
|
@@ -26,23 +28,33 @@ import {
|
|
|
26
28
|
} from './compliance-rgaa'
|
|
27
29
|
import { STATEMENT_PLACEHOLDER } from '../a11y/declaration'
|
|
28
30
|
import { checkEcoElement, ECO_JSX_RULES, largePublicFileWarnings } from './compliance-eco'
|
|
29
|
-
import {
|
|
31
|
+
import { contrastFindings } from './compliance-contrast'
|
|
32
|
+
import { rendersNoText } from './compliance-empty'
|
|
33
|
+
import { rgaaPageFindings } from './compliance-rgaa-pages'
|
|
34
|
+
import { checkThirdPartyComponent, checkThirdPartyElement } from './compliance-third-party'
|
|
35
|
+
import { CSS_IMPORT_RE, CSS_URL_RE, parseOrigin, thirdPartyOrigin } from './compliance-urls'
|
|
30
36
|
import { formatDiagnostic, formatLoc, getLineStarts, isComponentTag, jsxTagName, lineIndexAtOffset, unwrapTsExpr } from './shared'
|
|
31
37
|
|
|
32
38
|
export type ComplianceRule =
|
|
33
39
|
| RgaaJsxRule
|
|
40
|
+
| RgaaPageRule
|
|
41
|
+
| ContrastRule
|
|
34
42
|
| EcoJsxRule
|
|
35
43
|
| 'rgesn/large-public-file'
|
|
36
44
|
| 'rgesn/declaration'
|
|
37
45
|
| 'rgesn/island-by-value'
|
|
38
46
|
| 'rgpd/third-party-url'
|
|
39
47
|
| 'rgpd/consent-retention'
|
|
48
|
+
| 'rgpd/consent-preferences'
|
|
49
|
+
| 'rgpd/cookie-category'
|
|
50
|
+
| 'rgpd/cookie-purpose'
|
|
40
51
|
| 'rgpd/privacy-notice'
|
|
41
52
|
| 'lcen/legal-notice'
|
|
42
53
|
| 'rgaa/document-lang'
|
|
43
54
|
| 'rgaa/accessibility-statement'
|
|
44
55
|
| 'security/csrf-off'
|
|
45
56
|
| 'security/proxy-no-site'
|
|
57
|
+
| 'security/html-sink'
|
|
46
58
|
| FormWarningRule
|
|
47
59
|
|
|
48
60
|
/** The warnings of the form-vs-action check (`cli/check-forms.ts`), silenced like the compliance rules. */
|
|
@@ -67,12 +79,19 @@ const COMPLIANCE_RULES = new Set<ComplianceRule>([
|
|
|
67
79
|
'rgesn/island-by-value',
|
|
68
80
|
'rgpd/third-party-url',
|
|
69
81
|
'rgpd/consent-retention',
|
|
82
|
+
'rgpd/consent-preferences',
|
|
83
|
+
'rgpd/cookie-category',
|
|
84
|
+
'rgpd/cookie-purpose',
|
|
70
85
|
'rgpd/privacy-notice',
|
|
71
86
|
'lcen/legal-notice',
|
|
72
87
|
'rgaa/document-lang',
|
|
73
88
|
'rgaa/accessibility-statement',
|
|
89
|
+
'rgaa/skip-link',
|
|
90
|
+
'rgaa/page-title',
|
|
91
|
+
'rgaa/contrast',
|
|
74
92
|
'security/csrf-off',
|
|
75
93
|
'security/proxy-no-site',
|
|
94
|
+
'security/html-sink',
|
|
76
95
|
'action/unguarded-public-form',
|
|
77
96
|
'form/invalid-option',
|
|
78
97
|
'form/schema-unsupported',
|
|
@@ -91,14 +110,15 @@ const PERSONAL_DATA_TYPES = new Set(['email', 'tel'])
|
|
|
91
110
|
const PERSONAL_DATA_NAMES = new Set(['email', 'phone', 'tel'])
|
|
92
111
|
const ACCESSIBILITY_PATHS = new Set(['/accessibilite', '/accessibility', '/declaration-accessibilite', '/accessibility-statement'])
|
|
93
112
|
const ECO_DECLARATION_PATHS = new Set(['/ecoconception', '/declaration-ecoconception', '/eco-design'])
|
|
94
|
-
// The
|
|
95
|
-
const TEMPLATE_PLACEHOLDER =
|
|
113
|
+
// The markers in front of every detail the publisher must supply: `[to fill in` in the `prunelle new` notices, `[à compléter` in the pages `prunelle a11y`, `prunelle eco` and `prunelle rgpd` draft.
|
|
114
|
+
const TEMPLATE_PLACEHOLDER = /\[to fill in/g
|
|
115
|
+
const DRAFT_PLACEHOLDER = new RegExp(STATEMENT_PLACEHOLDER.replace('[', '\\['), 'g')
|
|
96
116
|
|
|
97
|
-
interface NoticeDetails { rule: ComplianceRule, page: string, law: string, marker:
|
|
117
|
+
interface NoticeDetails { rule: ComplianceRule, page: string, law: string, marker: RegExp }
|
|
98
118
|
const LEGAL_NOTICE_DETAILS: NoticeDetails = { rule: 'lcen/legal-notice', page: 'legal notice', law: 'French law (LCEN art. 1-1) requires the publisher\'s identity, address and phone, the publication director and the host\'s name, address and phone', marker: TEMPLATE_PLACEHOLDER }
|
|
99
|
-
const PRIVACY_NOTICE_DETAILS: NoticeDetails = { rule: 'rgpd/privacy-notice', page: 'privacy notice', law: 'the RGPD (art. 13) requires the controller\'s identity and contact, the purposes and legal basis, the retention periods, the recipients and the rights of the people concerned', marker: TEMPLATE_PLACEHOLDER }
|
|
100
|
-
const ECO_DECLARATION_DETAILS: NoticeDetails = { rule: 'rgesn/declaration', page: 'eco-design declaration', law: 'the RGESN 2024 asks it to name the service, the evaluating entity and a contact, the minimum hardware profile and the planned actions, and to justify each criterion', marker:
|
|
101
|
-
const STATEMENT_DETAILS: NoticeDetails = { rule: 'rgaa/accessibility-statement', page: 'accessibility statement', law: 'the RGAA requires it to name the publisher, the site it covers and the pages audited, and to give a contact for accessibility feedback', marker:
|
|
119
|
+
const PRIVACY_NOTICE_DETAILS: NoticeDetails = { rule: 'rgpd/privacy-notice', page: 'privacy notice', law: 'the RGPD (art. 13) requires the controller\'s identity and contact, the purposes and legal basis, the retention periods, the recipients and the rights of the people concerned', marker: new RegExp(`${TEMPLATE_PLACEHOLDER.source}|${DRAFT_PLACEHOLDER.source}`, 'g') }
|
|
120
|
+
const ECO_DECLARATION_DETAILS: NoticeDetails = { rule: 'rgesn/declaration', page: 'eco-design declaration', law: 'the RGESN 2024 asks it to name the service, the evaluating entity and a contact, the minimum hardware profile and the planned actions, and to justify each criterion', marker: DRAFT_PLACEHOLDER }
|
|
121
|
+
const STATEMENT_DETAILS: NoticeDetails = { rule: 'rgaa/accessibility-statement', page: 'accessibility statement', law: 'the RGAA requires it to name the publisher, the site it covers and the pages audited, and to give a contact for accessibility feedback', marker: DRAFT_PLACEHOLDER }
|
|
102
122
|
const LOCALE_PREFIX_RE = /^\/(?:[a-z]{2}(?:-[a-z]{2})?|:[a-z_]\w*(?:=[^/]+)?\??|\[\[?[^\]]+\]\]?)(\/.+)$/i
|
|
103
123
|
|
|
104
124
|
const LINE_IGNORE_RE = /(?:^|[\s{;(,])\/\/\s*prunelle-ignore(-file)?[ \t]+([^\r\n]+)/g
|
|
@@ -248,25 +268,6 @@ function collectDirectLabelTargets(root: Node | null | undefined): Set<string> {
|
|
|
248
268
|
return targets
|
|
249
269
|
}
|
|
250
270
|
|
|
251
|
-
function checkThirdPartyElement(
|
|
252
|
-
element: JSXElement,
|
|
253
|
-
tag: string,
|
|
254
|
-
filename: string,
|
|
255
|
-
ignores: IgnoreMap,
|
|
256
|
-
warnings: CompilerWarning[],
|
|
257
|
-
): void {
|
|
258
|
-
for (const load of thirdPartyLoads(element, tag)) {
|
|
259
|
-
if (isIgnoredAt(ignores, 'rgpd/third-party-url', load.start))
|
|
260
|
-
continue
|
|
261
|
-
warnings.push({
|
|
262
|
-
rule: 'rgpd/third-party-url',
|
|
263
|
-
urlOrigin: load.origin,
|
|
264
|
-
start: load.start,
|
|
265
|
-
message: `[rgpd/third-party-url] <${tag} ${load.attr}="${load.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="...">.`,
|
|
266
|
-
})
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
271
|
// A gate on the essential category always renders its children, so it holds nothing back until consent.
|
|
271
272
|
function opensConsentGate(element: JSXElement, resolvedTag: string | undefined): boolean {
|
|
272
273
|
return resolvedTag === 'ConsentGate' && staticStringValueOf(findAttr(element.openingElement.attributes, 'category')?.value ?? null) !== 'essential'
|
|
@@ -377,14 +378,17 @@ export function checkCompliance(
|
|
|
377
378
|
isIgnored,
|
|
378
379
|
warnings,
|
|
379
380
|
}
|
|
381
|
+
const thirdPartyIgnored = (offset: number): boolean => isIgnoredAt(ignores, 'rgpd/third-party-url', offset)
|
|
380
382
|
if (isComponentTag(tag)) {
|
|
381
383
|
checkRgaaComponent(node, tag, ctx)
|
|
384
|
+
if (ancestors.consentGateDepth === 0)
|
|
385
|
+
checkThirdPartyComponent(node, tag, filename, thirdPartyIgnored, warnings)
|
|
382
386
|
}
|
|
383
387
|
else {
|
|
384
388
|
checkRgaaElement(node, tag, ctx)
|
|
385
389
|
checkEcoElement(node, tag, ctx)
|
|
386
390
|
if (ancestors.consentGateDepth === 0)
|
|
387
|
-
checkThirdPartyElement(node, tag, filename,
|
|
391
|
+
checkThirdPartyElement(node, tag, filename, thirdPartyIgnored, warnings)
|
|
388
392
|
}
|
|
389
393
|
}
|
|
390
394
|
visit(attrs, ancestors, scope, labelTargets)
|
|
@@ -531,6 +535,8 @@ export interface ProjectComplianceInput {
|
|
|
531
535
|
lang?: string | undefined
|
|
532
536
|
/** A plugin sets `<html lang>` per request, so a missing `lang` is not a mistake. */
|
|
533
537
|
langFromPlugin?: boolean | undefined
|
|
538
|
+
/** A plugin reports a page with no title itself, so `rgaa/page-title` would say it twice. */
|
|
539
|
+
titleChecked?: boolean | undefined
|
|
534
540
|
}
|
|
535
541
|
|
|
536
542
|
/** True when a plugin sets `<html lang>` from the request's locale (`@prunellejs/i18n`). */
|
|
@@ -538,6 +544,18 @@ export function pluginSetsLang(plugins: readonly { name: string }[]): boolean {
|
|
|
538
544
|
return plugins.some(p => p.name === '@prunellejs/i18n')
|
|
539
545
|
}
|
|
540
546
|
|
|
547
|
+
function contrastWarnings(relFile: string, code: string): string[] {
|
|
548
|
+
const ignores = parsePrunelleIgnores(code)
|
|
549
|
+
return contrastFindings(code)
|
|
550
|
+
.filter(finding => !isIgnoredAt(ignores, 'rgaa/contrast', finding.offset))
|
|
551
|
+
.map(finding => formatDiagnostic(formatLoc(relFile, code, finding.offset), finding.message, 'warning'))
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** True when a plugin warns about a page with no title (`@prunellejs/seo`). */
|
|
555
|
+
export function pluginChecksTitle(plugins: readonly { name: string }[]): boolean {
|
|
556
|
+
return plugins.some(p => p.name === '@prunellejs/seo')
|
|
557
|
+
}
|
|
558
|
+
|
|
541
559
|
/** Collects project-level CSS third-party URL warnings and the LCEN, RGPD and RGAA notice warnings for `prunelle check` and production `prunelle build`. */
|
|
542
560
|
export function collectProjectComplianceWarnings(input: ProjectComplianceInput): string[] {
|
|
543
561
|
const { root, srcDir, routesDir, routeFiles, analyses, compliance, consentMaxAge, site, lang, langFromPlugin } = input
|
|
@@ -557,6 +575,8 @@ export function collectProjectComplianceWarnings(input: ProjectComplianceInput):
|
|
|
557
575
|
for (const cssFile of [...srcFiles.filter(file => file.endsWith('.css')), ...publicCss]) {
|
|
558
576
|
const code = readFileSync(cssFile, 'utf8')
|
|
559
577
|
warnings.push(...checkCssCompliance(relPosix(root, cssFile), code, compliance, site))
|
|
578
|
+
if (!isRuleIgnored('rgaa/contrast', compliance))
|
|
579
|
+
warnings.push(...contrastWarnings(relPosix(root, cssFile), code))
|
|
560
580
|
}
|
|
561
581
|
|
|
562
582
|
const pagePaths: string[] = []
|
|
@@ -569,7 +589,7 @@ export function collectProjectComplianceWarnings(input: ProjectComplianceInput):
|
|
|
569
589
|
const routePath = fileToRoutePath(routesDir, file)
|
|
570
590
|
pagePaths.push(routePath)
|
|
571
591
|
if (isLegalNoticePath(routePath, compliance) && !isRuleIgnored('lcen/legal-notice', compliance))
|
|
572
|
-
warnings.push(...
|
|
592
|
+
warnings.push(...legalNoticeWarnings(relPosix(root, file), readFileSync(file, 'utf8'), analysis))
|
|
573
593
|
if (matchesNoticePath(routePath, compliance?.privacyNotice, DEFAULT_PRIVACY_PATHS) && !isRuleIgnored('rgpd/privacy-notice', compliance))
|
|
574
594
|
warnings.push(...placeholderWarnings(relPosix(root, file), readFileSync(file, 'utf8'), PRIVACY_NOTICE_DETAILS))
|
|
575
595
|
// Any site that publishes a statement, public body or not, publishes what it says.
|
|
@@ -581,6 +601,10 @@ export function collectProjectComplianceWarnings(input: ProjectComplianceInput):
|
|
|
581
601
|
warnings.push(...checkRouteCompliance(pagePaths, compliance))
|
|
582
602
|
if (pagePaths.length > 0 && lang === undefined && langFromPlugin !== true && !isRuleIgnored('rgaa/document-lang', compliance))
|
|
583
603
|
warnings.push(formatDiagnostic('prunelle.config.ts:1:1', '[rgaa/document-lang] No lang in prunelle.config.ts, so every page says <html lang="en"> and @prunellejs/ui speaks English: set lang: \'fr\' (or the language your pages are written in).', 'warning'))
|
|
604
|
+
for (const finding of rgaaPageFindings({ root, routesDir, routeFiles, analyses, titleChecked: input.titleChecked === true, source: file => readFileSync(file, 'utf8') })) {
|
|
605
|
+
if (!isRuleIgnored(finding.rule, compliance) && !parsePrunelleIgnores(readFileSync(join(root, finding.file), 'utf8')).fileRules.has(finding.rule))
|
|
606
|
+
warnings.push(formatDiagnostic(`${finding.file}:${finding.line}:1`, `[${finding.rule}] ${finding.message}`, 'warning'))
|
|
607
|
+
}
|
|
584
608
|
warnings.push(...largePublicFileWarnings(root, isRuleIgnored('rgesn/large-public-file', compliance), publicDir))
|
|
585
609
|
if (!isRuleIgnored('rgpd/privacy-notice', compliance) && !pagePaths.some(p => matchesNoticePath(p, compliance?.privacyNotice, DEFAULT_PRIVACY_PATHS))) {
|
|
586
610
|
const tsxFiles = [...new Set([...srcFiles.filter(file => file.endsWith('.tsx')), ...routeFiles.filter(file => file.endsWith('.tsx'))])].sort()
|
|
@@ -589,7 +613,7 @@ export function collectProjectComplianceWarnings(input: ProjectComplianceInput):
|
|
|
589
613
|
return warnings
|
|
590
614
|
}
|
|
591
615
|
|
|
592
|
-
function isPersonalDataInput(el: JSXElement): boolean {
|
|
616
|
+
export function isPersonalDataInput(el: JSXElement): boolean {
|
|
593
617
|
if (jsxTagName(el.openingElement.name) !== 'input')
|
|
594
618
|
return false
|
|
595
619
|
const attrs = el.openingElement.attributes
|
|
@@ -637,21 +661,25 @@ function privacyNoticeWarnings(root: string, tsxFiles: readonly string[], analys
|
|
|
637
661
|
return []
|
|
638
662
|
}
|
|
639
663
|
|
|
664
|
+
// A legal notice route that renders no text is a page, not a notice; one with text still has its placeholders checked.
|
|
665
|
+
function legalNoticeWarnings(relFile: string, code: string, analysis: ModuleAnalysis): string[] {
|
|
666
|
+
const { rule, page, law } = LEGAL_NOTICE_DETAILS
|
|
667
|
+
if (parsePrunelleIgnores(code).fileRules.has(rule) || !rendersNoText(analysis.program))
|
|
668
|
+
return placeholderWarnings(relFile, code, LEGAL_NOTICE_DETAILS)
|
|
669
|
+
return [formatDiagnostic(`${relFile}:1:1`, `[${rule}] The ${page} page ${relFile} renders no text: ${law}; write it in the page.`, 'warning')]
|
|
670
|
+
}
|
|
671
|
+
|
|
640
672
|
// One warning for the first unfilled detail outside comments and ignores: the publisher fills them all in one pass.
|
|
641
673
|
function placeholderWarnings(relFile: string, code: string, notice: NoticeDetails): string[] {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const comments = parseSync(relFile, code, { lang: relFile.endsWith('.tsx') ? 'tsx' : 'ts' }).comments
|
|
648
|
-
const inComment = (offset: number): boolean => comments.some(c => offset >= c.start && offset < c.end)
|
|
649
|
-
for (let from = 0; ;) {
|
|
650
|
-
const offset = code.indexOf(notice.marker, from)
|
|
651
|
-
if (offset === -1)
|
|
674
|
+
let ignores: ReturnType<typeof parsePrunelleIgnores> | undefined
|
|
675
|
+
let comments: { start: number, end: number }[] | undefined
|
|
676
|
+
for (const { index: offset, 0: marker } of code.matchAll(notice.marker)) {
|
|
677
|
+
ignores ??= parsePrunelleIgnores(code)
|
|
678
|
+
if (ignores.fileRules.has(notice.rule))
|
|
652
679
|
return []
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
680
|
+
comments ??= parseSync(relFile, code, { lang: relFile.endsWith('.tsx') ? 'tsx' : 'ts' }).comments
|
|
681
|
+
if (!comments.some(c => offset >= c.start && offset < c.end) && !isIgnoredAt(ignores, notice.rule, offset))
|
|
682
|
+
return [formatDiagnostic(formatLoc(relFile, code, offset), `[${notice.rule}] The ${notice.page} still holds "${marker} ...]" placeholders: ${notice.law}; replace every placeholder in ${relFile}.`, 'warning')]
|
|
656
683
|
}
|
|
684
|
+
return []
|
|
657
685
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The cookies an app sets with `cookies.set(...)`, read from its source for `<CookieTable>` and `prunelle check`.
|
|
2
|
+
|
|
3
|
+
import type { Argument, Expression, Node, ObjectExpression, Program } from 'oxc-parser'
|
|
4
|
+
import { parseSync } from 'oxc-parser'
|
|
5
|
+
import { walk } from './ast'
|
|
6
|
+
import { unwrapTsExpr } from './shared'
|
|
7
|
+
import { staticLiteralOrTemplate } from './ssr-helpers'
|
|
8
|
+
|
|
9
|
+
/** One cookie the app sets; a field left out could not be read from the source. `lifetime` is in seconds, or `'session'` for a cookie that ends with the browser session. */
|
|
10
|
+
export interface AppCookie {
|
|
11
|
+
name?: string | undefined
|
|
12
|
+
purpose?: string | undefined
|
|
13
|
+
category?: string | undefined
|
|
14
|
+
lifetime?: number | 'session' | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ScannedCookie extends AppCookie {
|
|
18
|
+
file: string
|
|
19
|
+
/** Offset of the first `cookies.set` call for this cookie. */
|
|
20
|
+
start: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** `ctx.cookies.set(...)` and `cookies.set(...)`, but not `map.set(...)`. */
|
|
24
|
+
export function isCookieSet(callee: Expression): boolean {
|
|
25
|
+
const member = unwrapTsExpr(callee)
|
|
26
|
+
if (member.type !== 'MemberExpression' || member.computed || member.property.type !== 'Identifier' || member.property.name !== 'set')
|
|
27
|
+
return false
|
|
28
|
+
const owner = unwrapTsExpr(member.object)
|
|
29
|
+
if (owner.type === 'Identifier')
|
|
30
|
+
return owner.name === 'cookies'
|
|
31
|
+
return owner.type === 'MemberExpression' && !owner.computed && owner.property.type === 'Identifier' && owner.property.name === 'cookies'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function staticString(node: Node | undefined): string | undefined {
|
|
35
|
+
if (node === undefined)
|
|
36
|
+
return undefined
|
|
37
|
+
const literal = staticLiteralOrTemplate(node)
|
|
38
|
+
return literal.ok && typeof literal.value === 'string' ? literal.value : undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// `31536000` and `60 * 60 * 24 * 365`.
|
|
42
|
+
function staticSeconds(node: Node): number | undefined {
|
|
43
|
+
const n = unwrapTsExpr(node)
|
|
44
|
+
if (n.type === 'Literal')
|
|
45
|
+
return typeof n.value === 'number' ? n.value : undefined
|
|
46
|
+
if (n.type !== 'BinaryExpression' || (n.operator !== '*' && n.operator !== '+'))
|
|
47
|
+
return undefined
|
|
48
|
+
const left = staticSeconds(n.left)
|
|
49
|
+
const right = staticSeconds(n.right)
|
|
50
|
+
if (left === undefined || right === undefined)
|
|
51
|
+
return undefined
|
|
52
|
+
return n.operator === '*' ? left * right : left + right
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function propertiesOf(options: ObjectExpression): { props: Map<string, Node>, open: boolean } {
|
|
56
|
+
const props = new Map<string, Node>()
|
|
57
|
+
let open = false
|
|
58
|
+
for (const prop of options.properties) {
|
|
59
|
+
const key = prop.type === 'Property' && !prop.computed && prop.key.type === 'Identifier' ? prop.key.name : undefined
|
|
60
|
+
if (key === undefined || prop.type !== 'Property')
|
|
61
|
+
open = true
|
|
62
|
+
else
|
|
63
|
+
props.set(key, prop.value)
|
|
64
|
+
}
|
|
65
|
+
return { props, open }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// A spread or computed key may hold any option, so an option it could hold is unreadable rather than absent.
|
|
69
|
+
function readOptions(options: Argument | undefined): Omit<AppCookie, 'name'> {
|
|
70
|
+
if (options === undefined)
|
|
71
|
+
return { category: 'essential', lifetime: 'session' }
|
|
72
|
+
if (options.type !== 'ObjectExpression')
|
|
73
|
+
return {}
|
|
74
|
+
const { props, open } = propertiesOf(options)
|
|
75
|
+
const maxAge = props.get('maxAge')
|
|
76
|
+
return {
|
|
77
|
+
purpose: staticString(props.get('purpose')),
|
|
78
|
+
category: props.has('category') ? staticString(props.get('category')) : open ? undefined : 'essential',
|
|
79
|
+
lifetime: maxAge !== undefined ? staticSeconds(maxAge) : props.has('expires') || open ? undefined : 'session',
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Each `cookies.set(...)` call of a module, in source order. */
|
|
84
|
+
export function scanCookieSets(file: string, code: string, program?: Program): ScannedCookie[] {
|
|
85
|
+
if (!code.includes('cookies'))
|
|
86
|
+
return []
|
|
87
|
+
const found: ScannedCookie[] = []
|
|
88
|
+
walk(program ?? parseSync(file, code, { lang: file.endsWith('x') ? 'tsx' : 'ts' }).program, (node): undefined => {
|
|
89
|
+
if (node.type === 'CallExpression' && isCookieSet(node.callee))
|
|
90
|
+
found.push({ file, start: node.start, name: staticString(node.arguments[0]), ...readOptions(node.arguments[2]) })
|
|
91
|
+
return undefined
|
|
92
|
+
})
|
|
93
|
+
return found
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One entry per cookie name, each field from the first call that sets it readably; a cookie whose name cannot be read keeps an entry of its own. */
|
|
97
|
+
export function mergeCookies(scanned: readonly ScannedCookie[]): ScannedCookie[] {
|
|
98
|
+
const byName = new Map<string, ScannedCookie>()
|
|
99
|
+
const merged: ScannedCookie[] = []
|
|
100
|
+
for (const cookie of scanned) {
|
|
101
|
+
const seen = cookie.name === undefined ? undefined : byName.get(cookie.name)
|
|
102
|
+
if (seen !== undefined) {
|
|
103
|
+
seen.purpose ??= cookie.purpose
|
|
104
|
+
seen.category ??= cookie.category
|
|
105
|
+
seen.lifetime ??= cookie.lifetime
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
const entry = { ...cookie }
|
|
109
|
+
merged.push(entry)
|
|
110
|
+
if (cookie.name !== undefined)
|
|
111
|
+
byName.set(cookie.name, entry)
|
|
112
|
+
}
|
|
113
|
+
return merged
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The fields `<CookieTable>` cannot show, in the order of its columns. */
|
|
117
|
+
export function unreadableFields(cookie: AppCookie): ('name' | 'purpose' | 'category' | 'lifetime')[] {
|
|
118
|
+
return (['name', 'purpose', 'category', 'lifetime'] as const).filter(field => cookie[field] === undefined)
|
|
119
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Refuses a reactive primitive imported from another framework, with the prunelle name to write instead.
|
|
2
2
|
|
|
3
|
-
import { mistake } from './mistakes'
|
|
3
|
+
import { mistake, NEXT_GUIDE, withGuide } from './mistakes'
|
|
4
4
|
|
|
5
5
|
const REACT: Record<string, string> = {
|
|
6
6
|
useState: 'signal() from \'prunelle\' (count.value reads and writes it)',
|
|
@@ -83,6 +83,8 @@ const FOREIGN = new Map<string, Record<string, string>>([
|
|
|
83
83
|
/** Throws on a name a React, Solid, Vue or Svelte app imports for what prunelle spells differently, naming the prunelle form. */
|
|
84
84
|
export function assertNoForeignImport(source: string, imported: string, filename: string): void {
|
|
85
85
|
const table = FOREIGN.get(source)
|
|
86
|
-
if (table !== undefined && Object.hasOwn(table, imported))
|
|
87
|
-
|
|
86
|
+
if (table !== undefined && Object.hasOwn(table, imported)) {
|
|
87
|
+
const fix = `prunelle has no ${source}; write ${table[imported]}`
|
|
88
|
+
throw mistake(`import { ${imported} } from '${source}'`, filename, source.startsWith('react') ? withGuide(fix, NEXT_GUIDE) : fix)
|
|
89
|
+
}
|
|
88
90
|
}
|
package/src/compiler/mistakes.ts
CHANGED
|
@@ -66,6 +66,15 @@ export function mistake(what: string, filename: string, fix: string): PrunelleMi
|
|
|
66
66
|
return new PrunelleMistake(`prunelle compiler: ${what} in ${filename}: ${fix}.`)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
const GUIDES = 'https://prunelle.kaynooo.fr/docs/getting-started'
|
|
70
|
+
// The pages mapping another framework's concepts to prunelle's, linked from each error refusing a habit that framework taught.
|
|
71
|
+
export const ASTRO_GUIDE = `${GUIDES}/coming-from-astro`
|
|
72
|
+
export const NEXT_GUIDE = `${GUIDES}/coming-from-next`
|
|
73
|
+
|
|
74
|
+
export function withGuide(fix: string, guide: string): string {
|
|
75
|
+
return `${fix}; see ${guide}`
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
/** `$hydrate` where nothing can hydrate: on an element (`component` false) or on a component that is not an island. The one wording the compiler, the build and `prunelle check` share. */
|
|
70
79
|
export function hydrateMistake(tag: string, filename: string, component: boolean): PrunelleMistake {
|
|
71
80
|
return mistake(`$hydrate on <${tag}>`, filename, component
|
|
@@ -121,7 +130,7 @@ export function serverOnlyTagError(filename: string, { tag, island, reason, offs
|
|
|
121
130
|
|
|
122
131
|
/** The error for an Astro `---` block opening a file, at the first dash. */
|
|
123
132
|
export function frontmatterMistake(filename: string, start: number): PrunelleMistake {
|
|
124
|
-
const err = mistake('a --- frontmatter block', filename, 'prunelle files are plain TypeScript with no --- fence; write that code above the component, or inside it, and delete both --- lines')
|
|
133
|
+
const err = mistake('a --- frontmatter block', filename, withGuide('prunelle files are plain TypeScript with no --- fence; write that code above the component, or inside it, and delete both --- lines', ASTRO_GUIDE))
|
|
125
134
|
err.start = start
|
|
126
135
|
return err
|
|
127
136
|
}
|
|
@@ -242,13 +251,13 @@ function checkNamespacedAttribute(namespace: string, name: string, filename: str
|
|
|
242
251
|
if (namespace === 'on')
|
|
243
252
|
throw mistake(what, filename, `write ${eventProp(name.toLowerCase())}={...}`)
|
|
244
253
|
if (namespace === 'client')
|
|
245
|
-
throw mistake(what, filename, `write $hydrate="${CLIENT_DIRECTIVES.get(name) ?? 'load'}"
|
|
254
|
+
throw mistake(what, filename, withGuide(`write $hydrate="${CLIENT_DIRECTIVES.get(name) ?? 'load'}"`, ASTRO_GUIDE))
|
|
246
255
|
if (what === 'class:list')
|
|
247
|
-
throw mistake(what, filename, 'pass one string to class, joining the names yourself')
|
|
256
|
+
throw mistake(what, filename, withGuide('pass one string to class, joining the names yourself', ASTRO_GUIDE))
|
|
248
257
|
if (what === 'set:html')
|
|
249
|
-
throw mistake(what, filename, 'write innerHTML={...}')
|
|
258
|
+
throw mistake(what, filename, withGuide('write innerHTML={...}', ASTRO_GUIDE))
|
|
250
259
|
if (what === 'set:text')
|
|
251
|
-
throw mistake(what, filename, 'write the text as children')
|
|
260
|
+
throw mistake(what, filename, withGuide('write the text as children', ASTRO_GUIDE))
|
|
252
261
|
if (namespace === 'use')
|
|
253
262
|
throw mistake(what, filename, `call ${name} in a ref`)
|
|
254
263
|
if (namespace === 'prop' || namespace === 'attr' || namespace === 'bool')
|
|
@@ -389,7 +398,7 @@ export function checkMistakes(
|
|
|
389
398
|
const isCustomElement = tag.includes('-')
|
|
390
399
|
if (tag === 'slot') {
|
|
391
400
|
const named = staticAttr(element.openingElement.attributes, 'name') !== undefined
|
|
392
|
-
guarded(element.start, () => { throw mistake('<slot>', filename, named ? 'prunelle has no slots, pass the named part as its own prop, <Card footer={<p />} />, and write {footer} where it goes' : 'prunelle has no slots, take children as a prop, function Card({ children }) { return <div>{children}</div> }, and write {children} where the content goes') })
|
|
401
|
+
guarded(element.start, () => { throw mistake('<slot>', filename, withGuide(named ? 'prunelle has no slots, pass the named part as its own prop, <Card footer={<p />} />, and write {footer} where it goes' : 'prunelle has no slots, take children as a prop, function Card({ children }) { return <div>{children}</div> }, and write {children} where the content goes', ASTRO_GUIDE)) })
|
|
393
402
|
}
|
|
394
403
|
if (canonical === 'Suspense') {
|
|
395
404
|
const children = filterMeaningfulChildren(element.children).length
|
|
@@ -452,7 +461,7 @@ function checkRegionNesting(
|
|
|
452
461
|
})
|
|
453
462
|
}
|
|
454
463
|
|
|
455
|
-
// The markup
|
|
464
|
+
// The markup core `<Region>` reads: <Region name>, and data-pru-target, data-pru-append and data-pru-live on the elements that can use them.
|
|
456
465
|
function checkRegionMarkup(
|
|
457
466
|
tag: string,
|
|
458
467
|
canonical: string | undefined,
|
|
@@ -500,8 +509,8 @@ function checkKeepScroll(element: JSXElement, attributes: readonly JSXAttributeI
|
|
|
500
509
|
}
|
|
501
510
|
|
|
502
511
|
const DIRECTIVE_FIXES: Record<string, string> = {
|
|
503
|
-
'use client': 'delete it, prunelle makes a component an island by itself when it uses state or handlers',
|
|
504
|
-
'use server': 'delete it, a server function is an action() exported from its own file',
|
|
512
|
+
'use client': withGuide('delete it, prunelle makes a component an island by itself when it uses state or handlers', NEXT_GUIDE),
|
|
513
|
+
'use server': withGuide('delete it, a server function is an action() exported from its own file', NEXT_GUIDE),
|
|
505
514
|
}
|
|
506
515
|
|
|
507
516
|
/** Throws on a React or Next habit plain code carries: a 'use client' or 'use server' directive, or an effect(async ...). */
|