@starci/eslint-canon-fe 2.0.0 → 3.0.1
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/README.md +38 -92
- package/class-names.mjs +148 -0
- package/file-layout.mjs +6 -7
- package/grammar-boundary.mjs +10 -425
- package/index.mjs +6 -2
- package/landmark.mjs +29 -242
- package/package.json +2 -4
- package/props-and-slots.mjs +148 -452
- package/vendor-boundary.mjs +25 -595
- package/contract.mjs +0 -1387
- package/contracts.ts +0 -312
- package/props.ts +0 -145
package/landmark.mjs
CHANGED
|
@@ -1,242 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
/** A route layout: `layout.tsx` anywhere under an `app/` router directory. */
|
|
32
|
-
export const isRouteLayoutFile = (filename) => /\/app\/(?:.*\/)?layout\.tsx$/.test(normalize(filename))
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* A route file: the layout OR the page of a route.
|
|
36
|
-
*
|
|
37
|
-
* WHY BOTH. The landmark belongs to the outermost file that composes the routed screen, and that is
|
|
38
|
-
* not always a layout. A route with no chrome-composing layout - a scaffold, a standalone screen -
|
|
39
|
-
* has its page as the outermost composer, and forcing the mark upward would mean inventing a layout
|
|
40
|
-
* whose only job is to wrap. That was not a hypothetical: an early version of this rule allowed only
|
|
41
|
-
* layouts, and it refused three route pages that were each the sole composer of their screen and
|
|
42
|
-
* each held exactly one `main`.
|
|
43
|
-
*/
|
|
44
|
-
export const isRouteFile = (filename) => /\/app\/(?:.*\/)?(?:layout|page)\.tsx$/.test(normalize(filename))
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* A page tier file: either half of a surface under `components/pages/<Name>/`.
|
|
48
|
-
*
|
|
49
|
-
* WHY THE PAGE TIER OWNS THE MARK TOO, AND WHY THIS WAS NOT ALWAYS TRUE.
|
|
50
|
-
*
|
|
51
|
-
* The landmark used to be a named branch, so "the outermost file that composes the screen" and "a
|
|
52
|
-
* file under `app/`" were the same sentence — the branch was imported into the route file and that
|
|
53
|
-
* was that. Then the mark moved into the contract entry as `host: "main"`, and the two sentences
|
|
54
|
-
* came apart: the entry is rendered by whoever renders the screen's outermost frame, and FILE-6
|
|
55
|
-
* says that is emphatically NOT the route file. A route names which page renders at which URL and
|
|
56
|
-
* draws nothing.
|
|
57
|
-
*
|
|
58
|
-
* Held to route files only, the two laws then refused each other. Every page moved out of `app/` to
|
|
59
|
-
* satisfy FILE-6 was reported for misplacing its landmark, and the only way to satisfy both at
|
|
60
|
-
* once was to leave the page owner in the routing tree — which is the defect FILE-6 exists to
|
|
61
|
-
* prevent. A rule that can only be satisfied by breaking another rule is a finding about the rule.
|
|
62
|
-
*
|
|
63
|
-
* What the guarantee actually was, and still is: ONE main per document, owned by whoever owns the
|
|
64
|
-
* whole screen. A route file and a page component are both that. A block, composite, leaf, branch,
|
|
65
|
-
* overlay or shared layout is not, and each of those still reports — which is the case this rule was
|
|
66
|
-
* written for, because a landmark added there is a SECOND main rather than a stronger one.
|
|
67
|
-
*/
|
|
68
|
-
export const isPageTierFile = (filename) =>
|
|
69
|
-
/\/components\/pages\/[A-Z][A-Za-z0-9]*\/(?:index|component)\.tsx$/.test(normalize(filename))
|
|
70
|
-
|
|
71
|
-
/** The branches that open a landmark element. One per element, by LANDMARK-1. */
|
|
72
|
-
export const LANDMARK_BRANCHES = new Set(["Main"])
|
|
73
|
-
|
|
74
|
-
/** The branch that composes an ordinary registry node, and therefore marks a layout as chrome-owning. */
|
|
75
|
-
const TREE_BRANCH = "Tree"
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The contract key a frame element is rendering, when it names one literally.
|
|
79
|
-
*
|
|
80
|
-
* @param node - A JSX opening element.
|
|
81
|
-
* @returns The key, or null when the element takes no literal `contract`.
|
|
82
|
-
*/
|
|
83
|
-
const contractKeyOf = (node) => {
|
|
84
|
-
const attribute = (node.attributes || []).find(
|
|
85
|
-
(candidate) => candidate.type === "JSXAttribute" && candidate.name && candidate.name.name === "contract",
|
|
86
|
-
)
|
|
87
|
-
const value = attribute && attribute.value
|
|
88
|
-
return value && value.type === "Literal" && typeof value.value === "string" ? value.value : null
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* True when this element draws a landmark.
|
|
93
|
-
*
|
|
94
|
-
* TWO SHAPES, AND THE SECOND IS THE ONE THAT LASTS. A landmark used to be a named branch, so this
|
|
95
|
-
* asked for the name. The element now belongs to the contract entry - `host: "main"` - which is
|
|
96
|
-
* why a repository can delete its `Main` branch entirely and still have exactly one main landmark:
|
|
97
|
-
* the frame reads the host from the key. Asking only for the branch name reported those repositories
|
|
98
|
-
* as having no landmark at all, which is the opposite of what they had done.
|
|
99
|
-
*
|
|
100
|
-
* @param node - A JSX opening element.
|
|
101
|
-
* @param filename - The file being linted, used to locate the contract table.
|
|
102
|
-
*/
|
|
103
|
-
const isLandmarkElement = (node, filename) =>
|
|
104
|
-
isLandmarkBranchElement(node) || isHostMainFrame(node, filename)
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* True when this element is a landmark BRANCH, named directly.
|
|
108
|
-
*
|
|
109
|
-
* @param node - A JSX opening element.
|
|
110
|
-
*/
|
|
111
|
-
const isLandmarkBranchElement = (node) =>
|
|
112
|
-
node.type === "JSXOpeningElement"
|
|
113
|
-
&& node.name
|
|
114
|
-
&& node.name.type === "JSXIdentifier"
|
|
115
|
-
&& LANDMARK_BRANCHES.has(node.name.name)
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* True when this element is an ordinary frame whose CONTRACT ENTRY declares the landmark.
|
|
119
|
-
*
|
|
120
|
-
* @param node - A JSX opening element.
|
|
121
|
-
* @param filename - The file being linted, used to locate the contract table.
|
|
122
|
-
*/
|
|
123
|
-
const isHostMainFrame = (node, filename) => {
|
|
124
|
-
if (node.type !== "JSXOpeningElement" || !node.name || node.name.type !== "JSXIdentifier") return false
|
|
125
|
-
if (LANDMARK_BRANCHES.has(node.name.name)) return false
|
|
126
|
-
const key = contractKeyOf(node)
|
|
127
|
-
return key !== null && contractHostOf(filename, key) === "main"
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* True when this file is a landmark branch's own implementation.
|
|
132
|
-
*
|
|
133
|
-
* That file draws the element by hand and must: it is the one place the element is allowed to
|
|
134
|
-
* appear, exactly as `Tree` is the one place a `div` is.
|
|
135
|
-
*
|
|
136
|
-
* @param filename - The file being linted.
|
|
137
|
-
*/
|
|
138
|
-
const isLandmarkBranchFile = (filename) =>
|
|
139
|
-
[...LANDMARK_BRANCHES].some((name) => new RegExp(`/branches/${name}/`).test(normalize(filename)))
|
|
140
|
-
|
|
141
|
-
export const rules = {
|
|
142
|
-
"routed-page-is-a-main-landmark": {
|
|
143
|
-
meta: {
|
|
144
|
-
type: "problem",
|
|
145
|
-
docs: {
|
|
146
|
-
description:
|
|
147
|
-
"A route layout that composes its own chrome must wrap the routed children in the Main branch, so the page is a landmark a reader can skip to.",
|
|
148
|
-
},
|
|
149
|
-
schema: [],
|
|
150
|
-
messages: {
|
|
151
|
-
missing:
|
|
152
|
-
"This layout composes the page chrome but never marks the routed page. Wrap `children` in the `Main` branch so assistive technology can skip the navigation to reach the page - a registry key named `*-main` is a name, not a landmark.",
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
create(context) {
|
|
156
|
-
const filename = context.filename || context.getFilename()
|
|
157
|
-
if (!isRouteLayoutFile(filename)) return {}
|
|
158
|
-
let rendersChildren = false
|
|
159
|
-
let composesChrome = false
|
|
160
|
-
let usesLandmark = false
|
|
161
|
-
let firstNode = null
|
|
162
|
-
return {
|
|
163
|
-
JSXExpressionContainer(node) {
|
|
164
|
-
if (node.expression && node.expression.type === "Identifier" && node.expression.name === "children") {
|
|
165
|
-
rendersChildren = true
|
|
166
|
-
firstNode = firstNode || node
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
Identifier(node) {
|
|
170
|
-
// `children` reaches the tree through a slot callback as often as through JSX, so the
|
|
171
|
-
// bare identifier counts too - otherwise a layout escapes by handing it to a builder.
|
|
172
|
-
if (node.name === "children" && node.parent && node.parent.type !== "Property") {
|
|
173
|
-
rendersChildren = true
|
|
174
|
-
firstNode = firstNode || node
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
JSXOpeningElement(node) {
|
|
178
|
-
if (isLandmarkElement(node, filename)) usesLandmark = true
|
|
179
|
-
if (node.name && node.name.type === "JSXIdentifier" && node.name.name === TREE_BRANCH) {
|
|
180
|
-
composesChrome = true
|
|
181
|
-
firstNode = firstNode || node
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
"Program:exit"(node) {
|
|
185
|
-
if (rendersChildren && composesChrome && !usesLandmark) {
|
|
186
|
-
context.report({ node: firstNode || node, messageId: "missing" })
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
"main-landmark-belongs-to-a-route-file": {
|
|
194
|
-
meta: {
|
|
195
|
-
type: "problem",
|
|
196
|
-
docs: {
|
|
197
|
-
description:
|
|
198
|
-
"The Main branch draws the document's one main landmark, so it belongs to the route file that composes the screen and nowhere below it.",
|
|
199
|
-
},
|
|
200
|
-
schema: [],
|
|
201
|
-
messages: {
|
|
202
|
-
misplaced:
|
|
203
|
-
"This draws the document's ONE main landmark, so it belongs to whoever owns the whole screen - the route's `layout.tsx` or `page.tsx`, or the page surface under `components/pages/<Name>/`. Used here it puts a second `main` in the document, which is an ambiguous landmark rather than a stronger one - a registry key named `*-main` inside a block or composite is a reading column, and its entry must not declare `host: \"main\"`.",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
/*
|
|
207
|
-
* TWO SHAPES, TWO DIFFERENT SETS OF FILES THAT MAY HOLD THEM, and collapsing them was the bug.
|
|
208
|
-
*
|
|
209
|
-
* The `Main` BRANCH is a component somebody imports in order to wrap a screen. It belongs to the
|
|
210
|
-
* route file that composes that screen and nowhere below - a page reaching for it is the trap
|
|
211
|
-
* this law was written for, because the thing it wraps is a reading COLUMN and the document then
|
|
212
|
-
* has two mains.
|
|
213
|
-
*
|
|
214
|
-
* A frame whose CONTRACT ENTRY declares `host: "main"` is not that. Nobody imported a landmark;
|
|
215
|
-
* the registry says which element this key's node opens, and the frame obeys. That entry is
|
|
216
|
-
* rendered by whoever renders the screen's outermost node - and FILE-6 says the route file is
|
|
217
|
-
* emphatically not it, because a route mounts a page and draws nothing. Holding both shapes to
|
|
218
|
-
* route files only made the two laws refuse each other, and the only way to satisfy both was to
|
|
219
|
-
* leave the page owner in the routing tree, which is the defect FILE-6 exists to prevent.
|
|
220
|
-
*/
|
|
221
|
-
create(context) {
|
|
222
|
-
const filename = context.filename || context.getFilename()
|
|
223
|
-
if (isLandmarkBranchFile(filename)) return {}
|
|
224
|
-
const isRoute = isRouteFile(filename)
|
|
225
|
-
const isPageTier = isPageTierFile(filename)
|
|
226
|
-
return {
|
|
227
|
-
JSXOpeningElement(node) {
|
|
228
|
-
if (isLandmarkBranchElement(node)) {
|
|
229
|
-
if (!isRoute) context.report({ node, messageId: "misplaced" })
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
if (isHostMainFrame(node, filename) && !isRoute && !isPageTier) {
|
|
233
|
-
context.report({ node, messageId: "misplaced" })
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** Every FE canon rule is an error; see `sources/fe/index.mjs` for why there is no warn tier. */
|
|
242
|
-
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-fe/${name}`, "error"]))
|
|
1
|
+
/**
|
|
2
|
+
* Accessibility landmarks for ordinary React route composition.
|
|
3
|
+
*
|
|
4
|
+
* Native HTML landmarks are intentionally independent of component implementation details. The
|
|
5
|
+
* application may pass children through layouts and pages normally.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const normalize = (filename) => String(filename || "").replace(/\\/g, "/")
|
|
9
|
+
|
|
10
|
+
/** Whether a file is a Next route layout. */
|
|
11
|
+
export const isRouteLayoutFile = (filename) => /\/app\/(?:.*\/)?layout\.tsx$/.test(normalize(filename))
|
|
12
|
+
|
|
13
|
+
/** Whether a file is a Next route entry. */
|
|
14
|
+
export const isRouteFile = (filename) => /\/app\/(?:.*\/)?(?:layout|page)\.tsx$/.test(normalize(filename))
|
|
15
|
+
|
|
16
|
+
/** Whether a file owns a page component. */
|
|
17
|
+
export const isPageTierFile = (filename) => /\/src\/components\/pages\//.test(normalize(filename))
|
|
18
|
+
|
|
19
|
+
/** Named branch owners that may provide landmark semantics. */
|
|
20
|
+
export const LANDMARK_BRANCHES = new Set(["Main"])
|
|
21
|
+
|
|
22
|
+
/** No custom landmark AST rule is needed; semantic ownership is enforced by the component code. */
|
|
23
|
+
export const rules = {}
|
|
24
|
+
|
|
25
|
+
/** No repository audit is coupled to landmark ownership. */
|
|
26
|
+
export const audits = {}
|
|
27
|
+
|
|
28
|
+
/** The landmark contribution has no mandatory rule levels. */
|
|
29
|
+
export const recommended = {}
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-canon-fe",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "The StarCi front-end lint canon: every rule its laws publish, gathered as one flat-config plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"private": false,
|
|
8
8
|
"exports": {
|
|
9
|
-
".": "./index.mjs"
|
|
10
|
-
"./contracts": "./contracts.ts",
|
|
11
|
-
"./props": "./props.ts"
|
|
9
|
+
".": "./index.mjs"
|
|
12
10
|
},
|
|
13
11
|
"main": "./index.mjs",
|
|
14
12
|
"files": [
|