@homepages/concrete 1.0.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/CHANGELOG.md +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CONCRETE_RULES } from "../rules/registry.js";
|
|
2
|
+
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
|
3
|
+
|
|
4
|
+
//#region src/eslint/correctness.ts
|
|
5
|
+
const typescriptPlugin = tsPlugin;
|
|
6
|
+
const CORRECTNESS_SETTINGS = {
|
|
7
|
+
"@typescript-eslint/no-base-to-string": "error",
|
|
8
|
+
"@typescript-eslint/restrict-template-expressions": ["error", {
|
|
9
|
+
allowNumber: true,
|
|
10
|
+
allowBoolean: true
|
|
11
|
+
}],
|
|
12
|
+
"@typescript-eslint/restrict-plus-operands": "error",
|
|
13
|
+
"@typescript-eslint/no-misused-promises": "error",
|
|
14
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
15
|
+
"@typescript-eslint/await-thenable": "error",
|
|
16
|
+
"@typescript-eslint/no-for-in-array": "error",
|
|
17
|
+
"@typescript-eslint/no-implied-eval": "error"
|
|
18
|
+
};
|
|
19
|
+
/** The enabled tier: every `@typescript-eslint/` rule the registry lists, with its setting. */
|
|
20
|
+
const CORRECTNESS_RULES = Object.fromEntries(CONCRETE_RULES.flatMap((rule) => {
|
|
21
|
+
if (rule.venue !== "eslint" || rule.engineId?.startsWith("@typescript-eslint/") !== true) return [];
|
|
22
|
+
const setting = CORRECTNESS_SETTINGS[rule.engineId];
|
|
23
|
+
if (setting === void 0) throw new Error(`The rule registry lists ${rule.engineId}, but the correctness tier has no setting for it.`);
|
|
24
|
+
return [[rule.engineId, setting]];
|
|
25
|
+
}));
|
|
26
|
+
/**
|
|
27
|
+
* The correctness tier as a flat-config entry. Composed into the preset's default
|
|
28
|
+
* export, so a workspace's whole `eslint.config.mjs` stays one re-export and these
|
|
29
|
+
* rules apply with no manifest change: the checks a template is judged by when it is
|
|
30
|
+
* published are checks its author could already run.
|
|
31
|
+
*/
|
|
32
|
+
const correctnessConfig = [{
|
|
33
|
+
name: "concrete/correctness",
|
|
34
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
35
|
+
ignores: ["**/*.config.{ts,mts,cts,tsx}"],
|
|
36
|
+
languageOptions: { parserOptions: { projectService: true } },
|
|
37
|
+
plugins: { "@typescript-eslint": typescriptPlugin },
|
|
38
|
+
rules: CORRECTNESS_RULES
|
|
39
|
+
}];
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CORRECTNESS_RULES, CORRECTNESS_SETTINGS, correctnessConfig };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { hasClientDirective } from "../../islands/client-module.js";
|
|
2
|
+
|
|
3
|
+
//#region src/eslint/rules/editor-declaration.ts
|
|
4
|
+
function unwrap(node) {
|
|
5
|
+
let current = node;
|
|
6
|
+
while (current && (current.type === "TSSatisfiesExpression" || current.type === "TSAsExpression" || current.type === "TSTypeAssertion")) current = current.expression;
|
|
7
|
+
return current;
|
|
8
|
+
}
|
|
9
|
+
function propertyNamed(object, want) {
|
|
10
|
+
for (const prop of object.properties ?? []) {
|
|
11
|
+
if (prop.type !== "Property" || prop.computed === true || prop.kind !== "init") continue;
|
|
12
|
+
if ((prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" ? String(prop.key.value) : void 0) === want) return prop;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const editorDeclaration = {
|
|
16
|
+
meta: {
|
|
17
|
+
type: "problem",
|
|
18
|
+
docs: { description: "Every island must declare whether it is live in the editor canvas" },
|
|
19
|
+
schema: [],
|
|
20
|
+
messages: {
|
|
21
|
+
missingEditor: "this island does not declare its editor-canvas behavior. Fix: add `export const editor = { live: false };` if it should stay static server-rendered HTML in the editor, or `{ live: true }` to hydrate it there behind the selection gate.",
|
|
22
|
+
missingLive: "`editor` does not declare `live`. Fix: add `live: true` to hydrate this island in the editor canvas, or `live: false` to leave it as static server-rendered HTML there. There is no default.",
|
|
23
|
+
liveNotBoolean: "`editor.live` must be `true` or `false` written literally, not a computed value. Fix: write the literal. The canvas reads `editor` once when the module loads, so a value that varies at runtime cannot mean anything, and a declaration a reader cannot see is the one this rule exists to prevent.",
|
|
24
|
+
serverFrameNotLiteral: "`serverFrame` must be `true` or `false` written literally, not a computed value. Fix: write the literal. The build reads this declaration out of your source, with no module to evaluate, so a computed value means nothing to it and the island silently keeps its server frame.",
|
|
25
|
+
serverFrameNotDeclared: "`serverFrame` is exported here, but not as an `export const serverFrame = <literal>;` statement, which is the only form the build reads. Fix: declare it directly in this module. A re-export or an aliased binding is invisible to the build and does nothing.",
|
|
26
|
+
serverFrameNeedsLive: "`serverFrame: false` requires `editor.live: true`. Fix: set `live: true`, or drop the `serverFrame` declaration. An island with no server frame renders no markup for the canvas to show, so one that also does not hydrate there is a permanent blank hole the author can neither see nor select."
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
create(context) {
|
|
30
|
+
return { "Program:exit"(program) {
|
|
31
|
+
if (!hasClientDirective(context.sourceCode.getText())) return;
|
|
32
|
+
let hasDefaultExport = false;
|
|
33
|
+
let editorInit;
|
|
34
|
+
let editorReportNode;
|
|
35
|
+
let serverFrameInit;
|
|
36
|
+
let serverFrameReportNode;
|
|
37
|
+
let serverFrameIndirectNode;
|
|
38
|
+
for (const statement of program.body) {
|
|
39
|
+
if (statement.type === "ExportDefaultDeclaration") {
|
|
40
|
+
hasDefaultExport = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
44
|
+
for (const specifier of statement.specifiers) {
|
|
45
|
+
const exported = specifier.exported;
|
|
46
|
+
if ((exported.type === "Identifier" ? exported.name : String(exported.value)) === "serverFrame") serverFrameIndirectNode = specifier;
|
|
47
|
+
}
|
|
48
|
+
if (statement.declaration?.type !== "VariableDeclaration") continue;
|
|
49
|
+
for (const declarator of statement.declaration.declarations) {
|
|
50
|
+
if (declarator.id.type !== "Identifier") continue;
|
|
51
|
+
const init = declarator.init;
|
|
52
|
+
const reportAt = declarator.init ?? declarator.id;
|
|
53
|
+
if (declarator.id.name === "editor") {
|
|
54
|
+
editorInit = unwrap(init);
|
|
55
|
+
editorReportNode = reportAt;
|
|
56
|
+
}
|
|
57
|
+
if (declarator.id.name === "serverFrame") {
|
|
58
|
+
serverFrameInit = unwrap(init);
|
|
59
|
+
serverFrameReportNode = reportAt;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!hasDefaultExport) return;
|
|
64
|
+
const editorObject = editorInit?.type === "ObjectExpression" ? editorInit : void 0;
|
|
65
|
+
const live = editorObject ? propertyNamed(editorObject, "live") : void 0;
|
|
66
|
+
const liveIsFalse = live?.value.type === "Literal" && live.value.value === false;
|
|
67
|
+
if (serverFrameReportNode) {
|
|
68
|
+
if (serverFrameInit?.type !== "Literal" || typeof serverFrameInit.value !== "boolean") context.report({
|
|
69
|
+
node: serverFrameReportNode,
|
|
70
|
+
messageId: "serverFrameNotLiteral"
|
|
71
|
+
});
|
|
72
|
+
else if (serverFrameInit.value === false && liveIsFalse) context.report({
|
|
73
|
+
node: serverFrameReportNode,
|
|
74
|
+
messageId: "serverFrameNeedsLive"
|
|
75
|
+
});
|
|
76
|
+
} else if (serverFrameIndirectNode) context.report({
|
|
77
|
+
node: serverFrameIndirectNode,
|
|
78
|
+
messageId: "serverFrameNotDeclared"
|
|
79
|
+
});
|
|
80
|
+
if (!editorReportNode) {
|
|
81
|
+
context.report({
|
|
82
|
+
node: program,
|
|
83
|
+
messageId: "missingEditor"
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!live) {
|
|
88
|
+
context.report({
|
|
89
|
+
node: editorReportNode,
|
|
90
|
+
messageId: "missingLive"
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (live.value.type !== "Literal" || typeof live.value.value !== "boolean") context.report({
|
|
95
|
+
node: live.value,
|
|
96
|
+
messageId: "liveNotBoolean"
|
|
97
|
+
});
|
|
98
|
+
} };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { editorDeclaration };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
//#region src/eslint/rules/editor-reason.ts
|
|
2
|
+
/** Opens the comment block above the fork, and must actually say something. */
|
|
3
|
+
const REASON = /^\s*editor-reason:\s*\S/;
|
|
4
|
+
function isCallTo(node, name) {
|
|
5
|
+
return node?.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === name;
|
|
6
|
+
}
|
|
7
|
+
/** The property name a member expression resolves to, or null when it is computed at runtime. */
|
|
8
|
+
function memberName(node) {
|
|
9
|
+
if (node.computed === true) return node.property?.type === "Literal" && typeof node.property.value === "string" ? node.property.value : null;
|
|
10
|
+
return node.property?.type === "Identifier" ? node.property.name ?? null : null;
|
|
11
|
+
}
|
|
12
|
+
/** The key an object pattern's property declares, or null when computed. */
|
|
13
|
+
function propertyKey(node) {
|
|
14
|
+
if (node.computed === true) return null;
|
|
15
|
+
if (node.key?.type === "Identifier") return node.key.name ?? null;
|
|
16
|
+
if (node.key?.type === "Literal" && typeof node.key.value === "string") return node.key.value;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function readReferences(variables, name) {
|
|
20
|
+
return variables.find((variable) => variable.name === name)?.references.filter((ref) => ref.isRead()) ?? [];
|
|
21
|
+
}
|
|
22
|
+
const editorReason = {
|
|
23
|
+
meta: {
|
|
24
|
+
type: "problem",
|
|
25
|
+
docs: { description: "Every fork on the editor canvas must name the published-only behavior it protects" },
|
|
26
|
+
schema: [],
|
|
27
|
+
messages: { missingReason: "this forks the island's behavior in the editor canvas without saying why. Fix: put a comment directly above it opening with `editor-reason:`, naming the published-only behavior the fork protects, e.g. `// editor-reason: the lightbox is a fullscreen takeover that would cover the page being edited.` If you cannot name one, the fork is not an escape hatch: drop it and let the island run its published behavior in the canvas, or declare the whole island `editor = { live: false }`." }
|
|
28
|
+
},
|
|
29
|
+
create(context) {
|
|
30
|
+
const sourceCode = context.sourceCode;
|
|
31
|
+
const canvasReads = [];
|
|
32
|
+
const refDeclarations = [];
|
|
33
|
+
/** `const inCanvasRef = useRef(inCanvas)` makes every `inCanvasRef.current` a canvas read. One level, through `useRef` only. */
|
|
34
|
+
function followRefMirrors() {
|
|
35
|
+
const seeded = new Set(canvasReads);
|
|
36
|
+
for (const ref of refDeclarations) {
|
|
37
|
+
if (!seeded.has(ref.argument)) continue;
|
|
38
|
+
for (const reference of readReferences(ref.variables, ref.name)) {
|
|
39
|
+
const identifier = reference.identifier;
|
|
40
|
+
const parent = identifier.parent;
|
|
41
|
+
if (parent?.type === "MemberExpression" && parent.object === identifier && memberName(parent) === "current") canvasReads.push(parent);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The three shapes that move the value rather than decide with it. */
|
|
46
|
+
function isCarrier(read) {
|
|
47
|
+
const parent = read.parent;
|
|
48
|
+
if (parent === void 0) return false;
|
|
49
|
+
if (isCallTo(parent, "useRef") && (parent.arguments ?? []).includes(read)) return true;
|
|
50
|
+
if (parent.type === "AssignmentExpression") {
|
|
51
|
+
if (parent.left === read) return true;
|
|
52
|
+
if (parent.right === read && parent.left?.type === "MemberExpression" && memberName(parent.left) === "current") return true;
|
|
53
|
+
}
|
|
54
|
+
return parent.type === "ArrayExpression" && parent.parent?.type === "CallExpression" && (parent.parent.arguments ?? []).includes(parent);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Own-line comments, keyed by the line each ENDS on. Both `//` and the block form
|
|
58
|
+
* count, and the `{`/`}` of a JSX expression container is ignored: JSX children accept
|
|
59
|
+
* only the braced block form, so a line-comment-only rule would be unsatisfiable there.
|
|
60
|
+
*/
|
|
61
|
+
function ownLineComments() {
|
|
62
|
+
const byEndLine = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
64
|
+
const loc = comment.loc;
|
|
65
|
+
if (loc === void 0 || loc === null) continue;
|
|
66
|
+
const before = sourceCode.lines[loc.start.line - 1]?.slice(0, loc.start.column) ?? "";
|
|
67
|
+
const after = sourceCode.lines[loc.end.line - 1]?.slice(loc.end.column) ?? "";
|
|
68
|
+
if (!/^[\s{]*$/.test(before) || !/^[\s}]*$/.test(after)) continue;
|
|
69
|
+
byEndLine.set(loc.end.line, {
|
|
70
|
+
value: comment.value,
|
|
71
|
+
startLine: loc.start.line
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return byEndLine;
|
|
75
|
+
}
|
|
76
|
+
/** A comment block immediately above `line` whose FIRST comment opens with the marker. */
|
|
77
|
+
function hasReasonAbove(line, comments) {
|
|
78
|
+
let comment = comments.get(line - 1);
|
|
79
|
+
if (comment === void 0) return false;
|
|
80
|
+
for (;;) {
|
|
81
|
+
const above = comments.get(comment.startLine - 1);
|
|
82
|
+
if (above === void 0) break;
|
|
83
|
+
comment = above;
|
|
84
|
+
}
|
|
85
|
+
return REASON.test(comment.value);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
VariableDeclarator(raw) {
|
|
89
|
+
const node = raw;
|
|
90
|
+
if (isCallTo(node.init, "useRef") && node.id?.type === "Identifier" && node.id.name !== void 0) {
|
|
91
|
+
const argument = (node.init?.arguments ?? [])[0];
|
|
92
|
+
if (argument !== void 0) refDeclarations.push({
|
|
93
|
+
name: node.id.name,
|
|
94
|
+
argument,
|
|
95
|
+
variables: sourceCode.getDeclaredVariables(raw)
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!isCallTo(node.init, "useEditor")) return;
|
|
100
|
+
const declared = sourceCode.getDeclaredVariables(raw);
|
|
101
|
+
if (node.id?.type === "Identifier" && node.id.name !== void 0) {
|
|
102
|
+
for (const reference of readReferences(declared, node.id.name)) {
|
|
103
|
+
const identifier = reference.identifier;
|
|
104
|
+
const parent = identifier.parent;
|
|
105
|
+
if (parent?.type === "MemberExpression" && parent.object === identifier && memberName(parent) === "inCanvas") canvasReads.push(parent);
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (node.id?.type !== "ObjectPattern") return;
|
|
110
|
+
for (const property of node.id.properties ?? []) {
|
|
111
|
+
if (property.type !== "Property" || propertyKey(property) !== "inCanvas") continue;
|
|
112
|
+
const bound = property.value;
|
|
113
|
+
if (bound?.type !== "Identifier" || bound.name === void 0) continue;
|
|
114
|
+
for (const reference of readReferences(declared, bound.name)) canvasReads.push(reference.identifier);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"Program:exit"() {
|
|
118
|
+
followRefMirrors();
|
|
119
|
+
const comments = ownLineComments();
|
|
120
|
+
for (const read of canvasReads) {
|
|
121
|
+
if (isCarrier(read)) continue;
|
|
122
|
+
const line = read.loc?.start.line;
|
|
123
|
+
if (line !== void 0 && hasReasonAbove(line, comments)) continue;
|
|
124
|
+
context.report({
|
|
125
|
+
node: read,
|
|
126
|
+
messageId: "missingReason"
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
export { editorReason };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isClientFile, resolveImportedFile } from "../../islands/client-module.js";
|
|
2
|
+
|
|
3
|
+
//#region src/eslint/rules/island-imports.ts
|
|
4
|
+
function islandImports(context) {
|
|
5
|
+
const islands = /* @__PURE__ */ new Map();
|
|
6
|
+
return {
|
|
7
|
+
ImportDeclaration(node) {
|
|
8
|
+
const source = node.source.value;
|
|
9
|
+
if (typeof source !== "string") return;
|
|
10
|
+
const resolved = resolveImportedFile(source, context.filename);
|
|
11
|
+
if (resolved === null) return;
|
|
12
|
+
const island = isClientFile(resolved);
|
|
13
|
+
for (const specifier of node.specifiers) islands.set(specifier.local.name, island);
|
|
14
|
+
},
|
|
15
|
+
isIsland: (name) => islands.get(name) ?? false
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { islandImports };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/eslint/rules/jsx-visitor.ts
|
|
2
|
+
/**
|
|
3
|
+
* Types a JSX visitor for `Rule.RuleListener`.
|
|
4
|
+
*
|
|
5
|
+
* ESLint's `Rule.Node` union is ESTree-only — JSX lives in the parser's AST, never in
|
|
6
|
+
* `@types/estree` — so no JSX visitor can be declared with an honest parameter type, and
|
|
7
|
+
* ESLint 10's listener is a mapped type over that union, so a handler narrowed to a JSX
|
|
8
|
+
* shape does not assign. The cast is what the types cannot express, not a claim about
|
|
9
|
+
* runtime: the parser really does hand these visitors JSX nodes. Applied per visitor, not
|
|
10
|
+
* to the listener object, so every sibling handler stays contextually typed.
|
|
11
|
+
*
|
|
12
|
+
* `TNode` is each rule's own structural type for the fields it reads, never
|
|
13
|
+
* `TSESTree.JSXAttribute`: `@typescript-eslint/types` is not a dependency of this package.
|
|
14
|
+
*/
|
|
15
|
+
function jsxVisitor(visit) {
|
|
16
|
+
return visit;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { jsxVisitor };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { hasClientDirective } from "../../islands/client-module.js";
|
|
2
|
+
import { islandImports } from "./island-imports.js";
|
|
3
|
+
import { jsxVisitor } from "./jsx-visitor.js";
|
|
4
|
+
|
|
5
|
+
//#region src/eslint/rules/no-client-runtime.ts
|
|
6
|
+
const BANNED_HOOKS = /* @__PURE__ */ new Set([
|
|
7
|
+
"useEffect",
|
|
8
|
+
"useLayoutEffect",
|
|
9
|
+
"useState",
|
|
10
|
+
"useReducer",
|
|
11
|
+
"useRef",
|
|
12
|
+
"useSyncExternalStore",
|
|
13
|
+
"useImperativeHandle"
|
|
14
|
+
]);
|
|
15
|
+
const BANNED_GLOBALS = /* @__PURE__ */ new Set([
|
|
16
|
+
"fetch",
|
|
17
|
+
"XMLHttpRequest",
|
|
18
|
+
"window",
|
|
19
|
+
"document",
|
|
20
|
+
"localStorage",
|
|
21
|
+
"sessionStorage",
|
|
22
|
+
"navigator"
|
|
23
|
+
]);
|
|
24
|
+
const noClientRuntime = {
|
|
25
|
+
meta: {
|
|
26
|
+
type: "problem",
|
|
27
|
+
docs: { description: "Ban effects, state, handlers, network and browser globals in server-rendered code" },
|
|
28
|
+
schema: [],
|
|
29
|
+
messages: {
|
|
30
|
+
clientRuntime: "`{{what}}` is browser-only and is banned in server-rendered code: a section's render function must be a pure function of its bindings. Fix: move this into a `\"use client\"` component and render it from the section; it hydrates as an island.",
|
|
31
|
+
clientHandler: "`{{what}}` is an event handler, which cannot cross from the server to the browser: it is dropped from the published HTML. Fix: move the interactive markup into a `\"use client\"` component and render it from the section."
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
create(context) {
|
|
35
|
+
if (hasClientDirective(context.sourceCode.getText())) return {};
|
|
36
|
+
const sourceCode = context.sourceCode;
|
|
37
|
+
const imports = islandImports(context);
|
|
38
|
+
return {
|
|
39
|
+
ImportDeclaration: imports.ImportDeclaration,
|
|
40
|
+
CallExpression(node) {
|
|
41
|
+
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && BANNED_HOOKS.has(node.callee.property.name)) {
|
|
42
|
+
context.report({
|
|
43
|
+
node,
|
|
44
|
+
messageId: "clientRuntime",
|
|
45
|
+
data: { what: node.callee.property.name }
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (node.callee.type !== "Identifier" || !BANNED_HOOKS.has(node.callee.name)) return;
|
|
50
|
+
const ref = sourceCode.getScope(node).references.find((r) => r.identifier === node.callee);
|
|
51
|
+
if (ref?.resolved && ref.resolved.defs.some((d) => d.type !== "ImportBinding")) return;
|
|
52
|
+
context.report({
|
|
53
|
+
node,
|
|
54
|
+
messageId: "clientRuntime",
|
|
55
|
+
data: { what: node.callee.name }
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
Identifier(node) {
|
|
59
|
+
if (!BANNED_GLOBALS.has(node.name)) return;
|
|
60
|
+
const ref = sourceCode.getScope(node).references.find((r) => r.identifier === node);
|
|
61
|
+
if (!ref) return;
|
|
62
|
+
if (ref.resolved && ref.resolved.defs.length > 0) return;
|
|
63
|
+
context.report({
|
|
64
|
+
node,
|
|
65
|
+
messageId: "clientRuntime",
|
|
66
|
+
data: { what: node.name }
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
JSXAttribute: jsxVisitor((node) => {
|
|
70
|
+
const attrName = node.name.name;
|
|
71
|
+
if (typeof attrName !== "string" || !/^on[A-Z]/.test(attrName)) return;
|
|
72
|
+
if (node.value === null || node.value.type !== "JSXExpressionContainer") return;
|
|
73
|
+
const expr = node.value.expression;
|
|
74
|
+
if (expr && (expr.type === "Literal" || expr.type === "JSXElement")) return;
|
|
75
|
+
const element = node.parent;
|
|
76
|
+
if (element?.type === "JSXOpeningElement" && element.name?.type === "JSXIdentifier" && typeof element.name.name === "string" && imports.isIsland(element.name.name)) return;
|
|
77
|
+
context.report({
|
|
78
|
+
node,
|
|
79
|
+
messageId: "clientHandler",
|
|
80
|
+
data: { what: attrName }
|
|
81
|
+
});
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { noClientRuntime };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/eslint/rules/no-editor-globals.ts
|
|
2
|
+
const INTERNAL_PREFIX = "__tr";
|
|
3
|
+
const GLOBAL_OBJECTS = /* @__PURE__ */ new Set([
|
|
4
|
+
"window",
|
|
5
|
+
"globalThis",
|
|
6
|
+
"self"
|
|
7
|
+
]);
|
|
8
|
+
/** The global object's name when this node is one, else null. */
|
|
9
|
+
function globalObjectName(node) {
|
|
10
|
+
if (node?.type !== "Identifier" || node.name === void 0) return null;
|
|
11
|
+
return GLOBAL_OBJECTS.has(node.name) ? node.name : null;
|
|
12
|
+
}
|
|
13
|
+
/** The property name a member access or pattern key resolves to, or null when computed at runtime. */
|
|
14
|
+
function staticKey(key, computed) {
|
|
15
|
+
if (!computed && key.type === "Identifier") return key.name ?? null;
|
|
16
|
+
if (key.type === "Literal" && typeof key.value === "string") return key.value;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const noEditorGlobals = {
|
|
20
|
+
meta: {
|
|
21
|
+
type: "problem",
|
|
22
|
+
docs: { description: "Template code must not read the editor canvas's internal globals" },
|
|
23
|
+
schema: [],
|
|
24
|
+
messages: { editorGlobal: "`{{global}}` is a platform internal, not an API: it can be renamed or removed without notice, and a published island bundle is immutable, so the island would silently behave as though it were never in the canvas. Fix: call `useEditor()` from `@homepages/concrete`. It returns `{ inCanvas, selection }`, is hydration-safe, and returns published-page values everywhere outside the canvas." }
|
|
25
|
+
},
|
|
26
|
+
create(context) {
|
|
27
|
+
return {
|
|
28
|
+
MemberExpression(node) {
|
|
29
|
+
const object = globalObjectName(node.object);
|
|
30
|
+
if (object === null) return;
|
|
31
|
+
const key = staticKey(node.property, node.computed);
|
|
32
|
+
if (key === null || !key.startsWith(INTERNAL_PREFIX)) return;
|
|
33
|
+
context.report({
|
|
34
|
+
node,
|
|
35
|
+
messageId: "editorGlobal",
|
|
36
|
+
data: { global: `${object}.${key}` }
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
ObjectPattern(node) {
|
|
40
|
+
const declarator = node.parent;
|
|
41
|
+
if (declarator.type !== "VariableDeclarator") return;
|
|
42
|
+
const object = globalObjectName(declarator.init);
|
|
43
|
+
if (object === null) return;
|
|
44
|
+
for (const property of node.properties) {
|
|
45
|
+
if (property.type !== "Property") continue;
|
|
46
|
+
const key = staticKey(property.key, property.computed);
|
|
47
|
+
if (key === null || !key.startsWith(INTERNAL_PREFIX)) continue;
|
|
48
|
+
context.report({
|
|
49
|
+
node: property,
|
|
50
|
+
messageId: "editorGlobal",
|
|
51
|
+
data: { global: `${object}.${key}` }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { noEditorGlobals };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/eslint/rules/no-hard-coded-color.ts
|
|
2
|
+
const HEX = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})\b/g;
|
|
3
|
+
const SEPARATOR = /[\s_]/;
|
|
4
|
+
const TRIM_SEPARATORS = /^[\s_]+|[\s_]+$/g;
|
|
5
|
+
const PERCENTAGE = /^[+-]?(?:\d+\.?\d*|\.\d+)%$/;
|
|
6
|
+
const VAR_REF = /^var\((.*)\)$/s;
|
|
7
|
+
const NESTED_COLOR_MIX = /^color-mix[\s_]*\((.*)\)$/s;
|
|
8
|
+
const CUSTOM_PROPERTY_NAME = /^--[A-Za-z0-9_-]+$/;
|
|
9
|
+
const PALETTE_FREE_KEYWORDS = /* @__PURE__ */ new Set(["transparent", "currentcolor"]);
|
|
10
|
+
function splitTopLevel(text, isSeparator) {
|
|
11
|
+
const parts = [];
|
|
12
|
+
let depth = 0;
|
|
13
|
+
let current = "";
|
|
14
|
+
for (const char of text) {
|
|
15
|
+
if (char === "(") depth += 1;
|
|
16
|
+
else if (char === ")") depth -= 1;
|
|
17
|
+
if (depth === 0 && isSeparator(char)) {
|
|
18
|
+
if (current !== "") parts.push(current);
|
|
19
|
+
current = "";
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
current += char;
|
|
23
|
+
}
|
|
24
|
+
if (current !== "") parts.push(current);
|
|
25
|
+
return parts;
|
|
26
|
+
}
|
|
27
|
+
function findColorFunctionCalls(text) {
|
|
28
|
+
const head = /(?:oklch|oklab|rgba?|hsla?|color-mix)[\s_]*\(/g;
|
|
29
|
+
const calls = [];
|
|
30
|
+
let match;
|
|
31
|
+
while (match = head.exec(text)) {
|
|
32
|
+
const open = match.index + match[0].length - 1;
|
|
33
|
+
let depth = 0;
|
|
34
|
+
let close = -1;
|
|
35
|
+
for (let i = open; i < text.length; i += 1) if (text[i] === "(") depth += 1;
|
|
36
|
+
else if (text[i] === ")") {
|
|
37
|
+
depth -= 1;
|
|
38
|
+
if (depth === 0) {
|
|
39
|
+
close = i;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (close === -1) continue;
|
|
44
|
+
calls.push({
|
|
45
|
+
raw: text.slice(match.index, close + 1),
|
|
46
|
+
name: match[0].replace(/[\s_]*\($/, "").toLowerCase(),
|
|
47
|
+
args: text.slice(open + 1, close)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return calls;
|
|
51
|
+
}
|
|
52
|
+
function isThemeDerivedColor(token) {
|
|
53
|
+
const value = token.replace(TRIM_SEPARATORS, "");
|
|
54
|
+
if (PALETTE_FREE_KEYWORDS.has(value.toLowerCase())) return true;
|
|
55
|
+
const varRef = VAR_REF.exec(value);
|
|
56
|
+
if (varRef) {
|
|
57
|
+
const [name, ...fallback] = splitTopLevel(varRef[1] ?? "", (char) => char === ",");
|
|
58
|
+
if (name === void 0 || !CUSTOM_PROPERTY_NAME.test(name.replace(TRIM_SEPARATORS, ""))) return false;
|
|
59
|
+
return fallback.length === 0 || isThemeDerivedColor(fallback.join(","));
|
|
60
|
+
}
|
|
61
|
+
const nested = NESTED_COLOR_MIX.exec(value);
|
|
62
|
+
return nested !== null && isThemeDerivedColorMix(nested[1] ?? "");
|
|
63
|
+
}
|
|
64
|
+
function isThemeDerivedColorMix(args) {
|
|
65
|
+
const [interpolation, ...colors] = splitTopLevel(args, (char) => char === ",");
|
|
66
|
+
if (interpolation === void 0 || !/^in[\s_]/.test(interpolation.replace(TRIM_SEPARATORS, ""))) return false;
|
|
67
|
+
if (colors.length === 0) return false;
|
|
68
|
+
return colors.every((color) => {
|
|
69
|
+
const [colorToken, ...rest] = splitTopLevel(color, (char) => SEPARATOR.test(char)).filter((token) => !PERCENTAGE.test(token));
|
|
70
|
+
return colorToken !== void 0 && rest.length === 0 && isThemeDerivedColor(colorToken);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const COLOR_UTILITY_PREFIXES = [
|
|
74
|
+
"bg",
|
|
75
|
+
"text",
|
|
76
|
+
"border",
|
|
77
|
+
"ring",
|
|
78
|
+
"outline",
|
|
79
|
+
"shadow",
|
|
80
|
+
"fill",
|
|
81
|
+
"stroke",
|
|
82
|
+
"decoration",
|
|
83
|
+
"divide",
|
|
84
|
+
"accent",
|
|
85
|
+
"caret",
|
|
86
|
+
"placeholder",
|
|
87
|
+
"from",
|
|
88
|
+
"via",
|
|
89
|
+
"to"
|
|
90
|
+
];
|
|
91
|
+
const COLOR_PROPERTY_NAMES = [
|
|
92
|
+
"color",
|
|
93
|
+
"background",
|
|
94
|
+
"background-color",
|
|
95
|
+
"border-color",
|
|
96
|
+
"outline-color",
|
|
97
|
+
"box-shadow",
|
|
98
|
+
"text-shadow",
|
|
99
|
+
"fill",
|
|
100
|
+
"stroke",
|
|
101
|
+
"caret-color",
|
|
102
|
+
"accent-color",
|
|
103
|
+
"text-decoration-color"
|
|
104
|
+
];
|
|
105
|
+
function colorBracketRanges(text) {
|
|
106
|
+
const ranges = [];
|
|
107
|
+
const re = /\[[^[\]]*\]/g;
|
|
108
|
+
let m;
|
|
109
|
+
while (m = re.exec(text)) {
|
|
110
|
+
const start = m.index;
|
|
111
|
+
const end = m.index + m[0].length;
|
|
112
|
+
const inner = m[0].slice(1, -1);
|
|
113
|
+
if (COLOR_PROPERTY_NAMES.some((prop) => inner.startsWith(`${prop}:`))) {
|
|
114
|
+
ranges.push([start, end]);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (inner.startsWith("--") && inner.includes(":")) {
|
|
118
|
+
ranges.push([start, end]);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const before = text.slice(0, start).match(/\S+$/)?.[0] ?? "";
|
|
122
|
+
const lastColon = before.lastIndexOf(":");
|
|
123
|
+
const utility = lastColon === -1 ? before : before.slice(lastColon + 1);
|
|
124
|
+
if (COLOR_UTILITY_PREFIXES.some((prefix) => utility === prefix || utility.startsWith(`${prefix}-`))) ranges.push([start, end]);
|
|
125
|
+
}
|
|
126
|
+
return ranges;
|
|
127
|
+
}
|
|
128
|
+
function isWithinStyleAttribute(node) {
|
|
129
|
+
let cur = node;
|
|
130
|
+
while (cur) {
|
|
131
|
+
if (cur.type === "JSXAttribute" && cur.name?.type === "JSXIdentifier" && cur.name.name === "style") return true;
|
|
132
|
+
cur = cur.parent;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const noHardCodedColor = {
|
|
137
|
+
meta: {
|
|
138
|
+
type: "suggestion",
|
|
139
|
+
docs: { description: "Take colours from the theme, not from hard-coded literals" },
|
|
140
|
+
schema: [],
|
|
141
|
+
messages: {
|
|
142
|
+
hardCodedColor: "`{{value}}` is a hard-coded colour, outside the palette your stylesheet's theme defines. Fix: use one of your theme's colour utilities; if the value has no token yet, add one to the `@theme` block in your stylesheet (`--color-brand: …;`) and use the `bg-brand` / `text-brand` utility it yields.",
|
|
143
|
+
hardCodedColorFunction: "`{{value}}` bakes a colour into the markup, outside the palette your stylesheet's theme defines. Fix: derive the colour from the theme instead. A `color-mix()` over theme variables is allowed (e.g. `color-mix(in srgb, var(--color-primary) 80%, var(--color-surface))`, or mix toward `transparent` for a translucent tint); only a hard-coded argument makes it a violation."
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
create(context) {
|
|
147
|
+
function check(node, text) {
|
|
148
|
+
for (const call of findColorFunctionCalls(text)) {
|
|
149
|
+
if (call.name === "color-mix" && isThemeDerivedColorMix(call.args)) continue;
|
|
150
|
+
context.report({
|
|
151
|
+
node,
|
|
152
|
+
messageId: "hardCodedColorFunction",
|
|
153
|
+
data: { value: call.raw }
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const hexMatches = [...text.matchAll(HEX)];
|
|
158
|
+
if (hexMatches.length === 0) return;
|
|
159
|
+
const inStyle = isWithinStyleAttribute(node);
|
|
160
|
+
const colorRanges = colorBracketRanges(text);
|
|
161
|
+
for (const hex of hexMatches) {
|
|
162
|
+
if (!colorRanges.some(([start, end]) => hex.index >= start && hex.index < end) && !inStyle) continue;
|
|
163
|
+
context.report({
|
|
164
|
+
node,
|
|
165
|
+
messageId: "hardCodedColor",
|
|
166
|
+
data: { value: hex[0] }
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
Literal(node) {
|
|
173
|
+
if (typeof node.value === "string") check(node, node.value);
|
|
174
|
+
},
|
|
175
|
+
TemplateElement(node) {
|
|
176
|
+
check(node, node.value.raw);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { noHardCodedColor };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { hasClientDirective } from "../../islands/client-module.js";
|
|
2
|
+
import { jsxVisitor } from "./jsx-visitor.js";
|
|
3
|
+
|
|
4
|
+
//#region src/eslint/rules/no-inline-style.ts
|
|
5
|
+
const noInlineStyle = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Ban the inline style prop in server-rendered JSX" },
|
|
9
|
+
schema: [],
|
|
10
|
+
messages: { inlineStyle: "The inline `style=` prop is banned in server-rendered JSX: it bypasses the cascade and Tailwind's responsive prefixes. Fix: use Tailwind utility classes, or a rule in a stylesheet the module imports; for a value that only exists at runtime, move the markup into a `\"use client\"` island, where `style` is allowed." }
|
|
11
|
+
},
|
|
12
|
+
create(context) {
|
|
13
|
+
if (hasClientDirective(context.sourceCode.getText())) return {};
|
|
14
|
+
return { JSXAttribute: jsxVisitor((node) => {
|
|
15
|
+
if (node.name.type === "JSXIdentifier" && node.name.name === "style") context.report({
|
|
16
|
+
node,
|
|
17
|
+
messageId: "inlineStyle"
|
|
18
|
+
});
|
|
19
|
+
}) };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { noInlineStyle };
|