@starci/eslint-canon-fe 9.1.9 → 9.1.11
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/CHANGELOG.md +8 -0
- package/LICENSE +1 -1
- package/README.md +9 -1
- package/docs/button-intent.md +1 -1
- package/docs/grammar-shim.md +25 -0
- package/grammar-shim.mjs +123 -0
- package/index.mjs +2 -0
- package/lib/config.mjs +1 -1
- package/lib/why.mjs +5 -0
- package/package.json +16 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 9.1.11 - 2026-10-27
|
|
4
|
+
|
|
5
|
+
- Changed: licensed MIT (was UNLICENSED); the package metadata names the repository, homepage and bugs so npm can attach provenance. No rule or behaviour changed.
|
|
6
|
+
|
|
7
|
+
## 9.1.10 - 2026-10-27
|
|
8
|
+
|
|
9
|
+
- Added: starci-fe/no-grammar-shim (R321 FE_GRAMMAR_SHIM): an app never re-exports a Grammar export under its own name (`export { X } from`, `export * from`, or an imported binding exported again); the Grammar defect a shim would hide is reported to the Grammar.
|
|
10
|
+
|
|
3
11
|
## 9.1.9 - 2026-10-26
|
|
4
12
|
|
|
5
13
|
- Added: starci-fe/control-height (R320 FE_CONTROL_HEIGHT), selection-fill-no-check and no-grammar-internal-selector.
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @starci/eslint-canon-fe
|
|
2
2
|
|
|
3
3
|
Universal front-end laws for TypeScript and Next.js applications, classified by
|
|
4
|
-
|
|
4
|
+
FE-RULE-OWNERSHIP (the StarCi runtime's `contexts/code/fe/index.yaml`).
|
|
5
5
|
The canon owns composition, data and effect boundaries, translations, accessibility, source
|
|
6
6
|
structure, typed contracts, token discipline and check integrity across Grammar families.
|
|
7
7
|
|
|
@@ -46,3 +46,11 @@ dialog, counts mutually exclusive render paths separately and reserves commit fo
|
|
|
46
46
|
decision rather than repeated collection items.
|
|
47
47
|
|
|
48
48
|
Regression specs belong to this package. Application front ends and Grammar libraries have no specs.
|
|
49
|
+
|
|
50
|
+
## The runtime copy
|
|
51
|
+
|
|
52
|
+
`runtime/` holds the StarCi runtime files the rules import (the slot manifest and view, the project graph and the
|
|
53
|
+
architecture machine it runs, the Sonar syntax rules), byte for byte at their runtime paths. In this repository it is a
|
|
54
|
+
committed snapshot taken from the legacy runtime (starci-academy-backend/.claude at 7424b89ca), where
|
|
55
|
+
`scripts/hfs/sync-runtime.mjs` generates it; refresh it by running that generator there and copying
|
|
56
|
+
`packages/eslint/fe/runtime/` over this folder. Nothing in this package edits it.
|
package/docs/button-intent.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Button intent (CTA-6)
|
|
2
2
|
|
|
3
|
-
Owner:
|
|
3
|
+
Owner: contexts/ui/composition/cta.yaml
|
|
4
4
|
|
|
5
5
|
App `Button` and `IconButton` commands declare `intent`. Grammar derives their variant from that intent and its placement context. These laws apply to every Grammar family in both app editions; aliases and namespace imports retain the same obligations.
|
|
6
6
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Grammar shims (R321)
|
|
2
|
+
|
|
3
|
+
Law module: `grammar-shim.mjs`. HFS rule: R321. Knowledge: `contexts/code/fe/ui.md` FE-UI-1 (the app makes no visual choice; the Grammar owns every visual element) and the Grammar follow-up C-7 in `contexts/decisions/open-grammar.md`.
|
|
4
|
+
|
|
5
|
+
An app imports a Grammar component where it renders it. It never hands one on from an app path under its own name: such a shim makes one app green while the defect it works around (a missing `"use client"`, a wrong prop, a broken export) stays in the Grammar for every other app. The defect is reported to the Grammar instead; an op files `blocked` naming the package, the component and the error.
|
|
6
|
+
|
|
7
|
+
| Rule | Finding code | Required behavior |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `starci-fe/no-grammar-shim` | `FE_GRAMMAR_SHIM` | No `export { X } from "@starci/grammar..."`, no `export * from "@starci/grammar..."`, and no re-export of a binding imported from the Grammar (`export { X }`, `export const Y = X`, `export const Y = G.X`, `export default X`). Rendering an imported component, wrapping it in an app component and type-only re-exports are allowed. Source inside the `@starci/grammar` package itself is out of scope. |
|
|
10
|
+
|
|
11
|
+
Invalid:
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
"use client"
|
|
15
|
+
|
|
16
|
+
export { SurfaceCard } from "@starci/grammar/common"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Valid:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { SurfaceCard } from "@starci/grammar/common"
|
|
23
|
+
|
|
24
|
+
export const Panel = ({ children }: PanelProps) => <SurfaceCard>{children}</SurfaceCard>
|
|
25
|
+
```
|
package/grammar-shim.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rule that holds `grammar-shim.md` (HFS R321, `FE_GRAMMAR_SHIM`).
|
|
3
|
+
*
|
|
4
|
+
* An app never re-exports a Grammar export under its own name. A shim, a file whose job is to hand a Grammar component
|
|
5
|
+
* on from an app path (often behind a directive the Grammar forgot), makes the app green while the defect stays in the
|
|
6
|
+
* Grammar for every other app; the defect is reported to the Grammar instead. Importing a Grammar component to render
|
|
7
|
+
* it, wrapping it in an app component and type-only re-exports are not shims. Source inside the Grammar package itself
|
|
8
|
+
* is out of scope: its entries re-export its components by design.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
11
|
+
import { dirname, resolve } from "node:path"
|
|
12
|
+
import { unwrap, variableOf } from "./lib/bindings.mjs"
|
|
13
|
+
|
|
14
|
+
/** Every published entry of the Grammar package, the root and each subpath. */
|
|
15
|
+
const GRAMMAR_SOURCE = /^@starci\/grammar(?:\/|$)/
|
|
16
|
+
/** The Grammar package's own manifest name; its source re-exports by design. */
|
|
17
|
+
const GRAMMAR_PACKAGE = "@starci/grammar"
|
|
18
|
+
|
|
19
|
+
/** The manifest name of the package owning each directory, read once per directory. */
|
|
20
|
+
const packageNames = new Map()
|
|
21
|
+
|
|
22
|
+
/** The `name` of the nearest `package.json` that declares one, or null at the filesystem root. */
|
|
23
|
+
const packageNameOf = (directory) => {
|
|
24
|
+
if (packageNames.has(directory)) return packageNames.get(directory)
|
|
25
|
+
const parent = dirname(directory)
|
|
26
|
+
const manifest = resolve(directory, "package.json")
|
|
27
|
+
let name = null
|
|
28
|
+
if (existsSync(manifest)) {
|
|
29
|
+
try {
|
|
30
|
+
const declared = JSON.parse(readFileSync(manifest, "utf8")).name
|
|
31
|
+
if (typeof declared === "string") name = declared
|
|
32
|
+
} catch {
|
|
33
|
+
name = null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (name === null && parent !== directory) name = packageNameOf(parent)
|
|
37
|
+
packageNames.set(directory, name)
|
|
38
|
+
return name
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** True for a type-only import or export, declaration-wide or per specifier; a type is no component to shim. */
|
|
42
|
+
const typeOnly = (...nodes) => nodes.some((node) => node.importKind === "type" || node.exportKind === "type")
|
|
43
|
+
|
|
44
|
+
/** The Grammar import an identifier binds, `{ source, name }`, or null for a local, foreign or type-only binding. */
|
|
45
|
+
const grammarImportOf = (context, identifier) => {
|
|
46
|
+
const definition = variableOf(context, identifier)?.defs.find((entry) => entry.type === "ImportBinding")
|
|
47
|
+
if (!definition) return null
|
|
48
|
+
const source = String(definition.parent.source.value)
|
|
49
|
+
if (!GRAMMAR_SOURCE.test(source) || typeOnly(definition.parent, definition.node)) return null
|
|
50
|
+
const specifier = definition.node
|
|
51
|
+
const name = specifier.type === "ImportSpecifier" ? specifier.imported.name ?? String(specifier.imported.value) : identifier.name
|
|
52
|
+
return { source, name }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The Grammar import an exported value is exactly (`X`, `G.X`), or null for anything computed or wrapped. */
|
|
56
|
+
const grammarValueOf = (context, expression) => {
|
|
57
|
+
let node = unwrap(expression)
|
|
58
|
+
const path = []
|
|
59
|
+
while (node?.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
|
|
60
|
+
path.unshift(node.property.name)
|
|
61
|
+
node = unwrap(node.object)
|
|
62
|
+
}
|
|
63
|
+
if (node?.type !== "Identifier") return null
|
|
64
|
+
const imported = grammarImportOf(context, node)
|
|
65
|
+
if (imported === null) return null
|
|
66
|
+
return path.length === 0 ? imported : { source: imported.source, name: path.join(".") }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The name an export specifier spells, identifier or string literal. */
|
|
70
|
+
const spelled = (node) => node.name ?? String(node.value)
|
|
71
|
+
|
|
72
|
+
const grammarShim = {
|
|
73
|
+
meta: {
|
|
74
|
+
type: "problem",
|
|
75
|
+
docs: { description: "R321: an app never re-exports a Grammar export under its own name; a Grammar defect is reported to the Grammar, not shimmed in the app." },
|
|
76
|
+
schema: [],
|
|
77
|
+
messages: {
|
|
78
|
+
FE_GRAMMAR_SHIM: "FE_GRAMMAR_SHIM: this file re-exports {{name}} of {{source}} under the app's own name. A defect in a Grammar component belongs to the Grammar: report it (the op files `blocked` naming the package, the component and the error), never shim it in the app; import the component from {{source}} where it is rendered.",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
create(context) {
|
|
82
|
+
const filename = resolve(context.cwd, context.physicalFilename)
|
|
83
|
+
if (packageNameOf(dirname(filename)) === GRAMMAR_PACKAGE) return {}
|
|
84
|
+
const report = (node, name, source) => context.report({ node, messageId: "FE_GRAMMAR_SHIM", data: { name: name === null ? "every export" : `\`${name}\``, source } })
|
|
85
|
+
return {
|
|
86
|
+
ExportAllDeclaration(node) {
|
|
87
|
+
const source = String(node.source.value)
|
|
88
|
+
if (!GRAMMAR_SOURCE.test(source) || typeOnly(node)) return
|
|
89
|
+
report(node, node.exported ? spelled(node.exported) : null, source)
|
|
90
|
+
},
|
|
91
|
+
ExportNamedDeclaration(node) {
|
|
92
|
+
if (typeOnly(node)) return
|
|
93
|
+
if (node.source) {
|
|
94
|
+
const source = String(node.source.value)
|
|
95
|
+
if (!GRAMMAR_SOURCE.test(source)) return
|
|
96
|
+
for (const specifier of node.specifiers) {
|
|
97
|
+
if (!typeOnly(specifier)) report(specifier, spelled(specifier.local), source)
|
|
98
|
+
}
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
for (const specifier of node.specifiers) {
|
|
102
|
+
const imported = typeOnly(specifier) || specifier.local.type !== "Identifier" ? null : grammarImportOf(context, specifier.local)
|
|
103
|
+
if (imported) report(specifier, imported.name, imported.source)
|
|
104
|
+
}
|
|
105
|
+
if (node.declaration?.type !== "VariableDeclaration") return
|
|
106
|
+
for (const declarator of node.declaration.declarations) {
|
|
107
|
+
const imported = declarator.init ? grammarValueOf(context, declarator.init) : null
|
|
108
|
+
if (imported) report(declarator, imported.name, imported.source)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
ExportDefaultDeclaration(node) {
|
|
112
|
+
const imported = grammarValueOf(context, node.declaration)
|
|
113
|
+
if (imported) report(node, imported.name, imported.source)
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The one rule of the law. */
|
|
120
|
+
export const rules = { "no-grammar-shim": grammarShim }
|
|
121
|
+
|
|
122
|
+
/** The rule reaches consumers at error. */
|
|
123
|
+
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-fe/${name}`, "error"]))
|
package/index.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { recommended as envOwnerRecommended, rules as envOwnerRules } from "./en
|
|
|
21
21
|
import { recommended as feStackRecommended, rules as feStackRules } from "./fe-stack.mjs"
|
|
22
22
|
import { recommended as fileLayoutRecommended, rules as fileLayoutRules } from "./file-layout.mjs"
|
|
23
23
|
import { recommended as formattingRecommended, rules as formattingRules } from "./formatting.mjs"
|
|
24
|
+
import { recommended as grammarShimRecommended, rules as grammarShimRules } from "./grammar-shim.mjs"
|
|
24
25
|
import { recommended as hooksFolderRecommended, rules as hooksFolderRules } from "./hooks-folder.mjs"
|
|
25
26
|
import { recommended as hygieneRecommended, rules as hygieneRules } from "./hygiene.mjs"
|
|
26
27
|
import { recommended as landmarkRecommended, rules as landmarkRules } from "./landmark.mjs"
|
|
@@ -65,6 +66,7 @@ const CONTRIBUTIONS = [
|
|
|
65
66
|
{ law: "fe-stack", rules: feStackRules, recommended: feStackRecommended },
|
|
66
67
|
{ law: "file-layout", rules: fileLayoutRules, recommended: fileLayoutRecommended },
|
|
67
68
|
{ law: "formatting", rules: formattingRules, recommended: formattingRecommended },
|
|
69
|
+
{ law: "grammar-shim", rules: grammarShimRules, recommended: grammarShimRecommended },
|
|
68
70
|
{ law: "hooks-folder", rules: hooksFolderRules, recommended: hooksFolderRecommended },
|
|
69
71
|
{ law: "hygiene", rules: hygieneRules, recommended: hygieneRecommended },
|
|
70
72
|
{ law: "landmark", rules: landmarkRules, recommended: landmarkRecommended },
|
package/lib/config.mjs
CHANGED
|
@@ -98,7 +98,7 @@ export const SLOT_FREE_RULES = Object.freeze([
|
|
|
98
98
|
"no-native-anchor", "no-inline-parameter-type", "no-hand-rolled-polling", "no-copy-in-call", "no-alert", "no-failure-collapse",
|
|
99
99
|
"outcome-kinds-exhaustive", "no-await-in-loop", "prefer-code-point", "prefer-string-raw", "no-nested-conditional", "no-void-operator", "no-unused-import",
|
|
100
100
|
"prefer-export-from", "no-unused-prop-types", "media-has-caption", "max-params",
|
|
101
|
-
"nested-control-variant", "no-list-panel-padding", "no-app-surface-paint", "divider-full-bleed", "control-height", "selection-fill-no-check",
|
|
101
|
+
"nested-control-variant", "no-list-panel-padding", "no-app-surface-paint", "divider-full-bleed", "control-height", "selection-fill-no-check", "no-grammar-shim",
|
|
102
102
|
"button-intent-required", "button-no-variant", "destructive-confirm-in-dialog", "single-commit-per-render", "no-commit-in-collection-item",
|
|
103
103
|
])
|
|
104
104
|
|
package/lib/why.mjs
CHANGED
|
@@ -44,6 +44,11 @@ export const why = {
|
|
|
44
44
|
en: "`<file>` picks a larger control size or mixes control sizes in one row.",
|
|
45
45
|
fix: "Omit size so Grammar draws the one 40px control height; use sm only for every control of an item or dense toolbar row, and lg only for a landing hero call to action.",
|
|
46
46
|
},
|
|
47
|
+
"no-grammar-shim": {
|
|
48
|
+
code: "FE_GRAMMAR_SHIM",
|
|
49
|
+
en: "`<file>` re-exports a Grammar component under the app's own name.",
|
|
50
|
+
fix: "Delete the shim and import the component from the Grammar where it is rendered; report the Grammar defect the shim worked around (the op files blocked) so the Grammar fixes it.",
|
|
51
|
+
},
|
|
47
52
|
"button-no-variant": {
|
|
48
53
|
code: "FE_BUTTON_NO_VARIANT",
|
|
49
54
|
en: "`<file>` chooses a Button or IconButton variant directly.",
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-canon-fe",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.11",
|
|
4
4
|
"description": "Universal front-end lint laws for TypeScript and Next.js, independent of the selected Grammar family.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"author": "starci183",
|
|
8
|
+
"homepage": "https://github.com/starci183/starci-harness/tree/main/packages/eslint-canon-fe#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/starci183/starci-harness.git",
|
|
12
|
+
"directory": "packages/eslint-canon-fe"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/starci183/starci-harness/issues"
|
|
16
|
+
},
|
|
7
17
|
"private": false,
|
|
8
18
|
"exports": {
|
|
9
19
|
".": "./index.mjs",
|
|
@@ -33,8 +43,6 @@
|
|
|
33
43
|
"access": "public"
|
|
34
44
|
},
|
|
35
45
|
"scripts": {
|
|
36
|
-
"prepack": "node ../../hfs/prep-runtime.mjs",
|
|
37
|
-
"pretest": "node ../../hfs/prep-runtime.mjs",
|
|
38
46
|
"test": "node --test \"*.spec.mjs\""
|
|
39
47
|
},
|
|
40
48
|
"keywords": [
|
|
@@ -48,5 +56,10 @@
|
|
|
48
56
|
"@typescript-eslint/parser": "^8.70.0",
|
|
49
57
|
"eslint-plugin-sonarjs": "4.2.1",
|
|
50
58
|
"eslint-plugin-unicorn": "65.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"eslint": "^9.18.0",
|
|
62
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
63
|
+
"typescript": "^6.0.3"
|
|
51
64
|
}
|
|
52
65
|
}
|