@orthograph/lint 0.0.0-stage → 0.1.0-next.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.
Files changed (49) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +38 -2
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +2 -0
  5. package/dist/main.d.ts +2 -0
  6. package/dist/main.js +3 -0
  7. package/dist/modules/baseline/internal/order.d.ts +3 -0
  8. package/dist/modules/baseline/internal/order.js +8 -0
  9. package/dist/modules/baseline/service.d.ts +2 -0
  10. package/dist/modules/baseline/service.js +29 -0
  11. package/dist/modules/baseline/types.d.ts +30 -0
  12. package/dist/modules/baseline/types.js +4 -0
  13. package/dist/modules/rules/internal/baselined.d.ts +11 -0
  14. package/dist/modules/rules/internal/baselined.js +45 -0
  15. package/dist/modules/rules/internal/drift.d.ts +3 -0
  16. package/dist/modules/rules/internal/drift.js +91 -0
  17. package/dist/modules/rules/internal/effect-only.d.ts +2 -0
  18. package/dist/modules/rules/internal/effect-only.js +69 -0
  19. package/dist/modules/rules/internal/facts.d.ts +10 -0
  20. package/dist/modules/rules/internal/facts.js +13 -0
  21. package/dist/modules/rules/internal/imports.d.ts +5 -0
  22. package/dist/modules/rules/internal/imports.js +36 -0
  23. package/dist/modules/rules/internal/max-lines.d.ts +4 -0
  24. package/dist/modules/rules/internal/max-lines.js +31 -0
  25. package/dist/modules/rules/internal/names.d.ts +2 -0
  26. package/dist/modules/rules/internal/names.js +23 -0
  27. package/dist/modules/rules/internal/old-names.d.ts +5 -0
  28. package/dist/modules/rules/internal/old-names.js +53 -0
  29. package/dist/modules/rules/internal/place.d.ts +3 -0
  30. package/dist/modules/rules/internal/place.js +57 -0
  31. package/dist/modules/rules/internal/pro.d.ts +7 -0
  32. package/dist/modules/rules/internal/pro.js +16 -0
  33. package/dist/modules/rules/internal/refusals.d.ts +3 -0
  34. package/dist/modules/rules/internal/refusals.js +64 -0
  35. package/dist/modules/rules/internal/six-slots.d.ts +2 -0
  36. package/dist/modules/rules/internal/six-slots.js +46 -0
  37. package/dist/modules/rules/internal/sql-clock.d.ts +5 -0
  38. package/dist/modules/rules/internal/sql-clock.js +24 -0
  39. package/dist/modules/rules/internal/steps.d.ts +2 -0
  40. package/dist/modules/rules/internal/steps.js +40 -0
  41. package/dist/modules/rules/internal/ui.d.ts +7 -0
  42. package/dist/modules/rules/internal/ui.js +16 -0
  43. package/dist/modules/rules/internal/viem.d.ts +2 -0
  44. package/dist/modules/rules/internal/viem.js +15 -0
  45. package/dist/modules/rules/service.d.ts +3 -0
  46. package/dist/modules/rules/service.js +34 -0
  47. package/dist/modules/rules/types.d.ts +64 -0
  48. package/dist/modules/rules/types.js +3 -0
  49. package/package.json +25 -3
@@ -0,0 +1,36 @@
1
+ /** The module a source node names: a string literal, a literal type, or a template with no holes. */
2
+ const moduleName = (source) => {
3
+ const node = source;
4
+ if (node?.type === "TSLiteralType")
5
+ return moduleName(node["literal"]);
6
+ if (node?.type === "Literal" && typeof node["value"] === "string")
7
+ return node["value"];
8
+ if (node?.type === "TemplateLiteral") {
9
+ const quasis = node["quasis"];
10
+ if (quasis.length === 1)
11
+ return quasis[0]?.value.cooked;
12
+ }
13
+ };
14
+ /** Visitors that call `seen` for every module a file reaches: imports, export-froms, dynamic imports, import types and `require`. */
15
+ export const everyImport = (seen) => {
16
+ const check = (node, source) => {
17
+ const name = moduleName(source);
18
+ if (name !== undefined)
19
+ seen(node, name);
20
+ };
21
+ const checkSource = (node) => check(node, node["source"]);
22
+ return {
23
+ ImportDeclaration: checkSource,
24
+ ExportNamedDeclaration: checkSource,
25
+ ExportAllDeclaration: checkSource,
26
+ ImportExpression: checkSource,
27
+ TSImportType: (node) => check(node, node["source"] ?? node["argument"]),
28
+ TSExternalModuleReference: (node) => check(node, node["expression"]),
29
+ CallExpression: (node) => {
30
+ const callee = node["callee"];
31
+ if (callee?.type === "Identifier" && callee["name"] === "require") {
32
+ check(node, node["arguments"][0]);
33
+ }
34
+ },
35
+ };
36
+ };
@@ -0,0 +1,4 @@
1
+ import type { Context, Rule } from "../types.ts";
2
+ /** Lines holding code: the text with every comment blanked (newlines kept), then the lines that aren't blank. */
3
+ export declare const codeLines: (context: Context) => number;
4
+ export declare const maxLines: Rule;
@@ -0,0 +1,31 @@
1
+ import { SCHEMA } from "./facts.js";
2
+ import { collector, optionsOf, sourcePath } from "./baselined.js";
3
+ /** Lines holding code: the text with every comment blanked (newlines kept), then the lines that aren't blank. */
4
+ export const codeLines = (context) => {
5
+ const chars = context.sourceCode.text.split(""); // UTF-16 units, as comment ranges count
6
+ for (const c of context.sourceCode.getAllComments()) {
7
+ const [from, to] = c.range ?? [c.start ?? 0, c.end ?? 0];
8
+ for (let i = from; i < to; i++)
9
+ if (chars[i] !== "\n")
10
+ chars[i] = " ";
11
+ }
12
+ return chars.join("").split("\n").filter((line) => line.trim() !== "").length;
13
+ };
14
+ export const maxLines = {
15
+ meta: { schema: SCHEMA, docs: { description: "A source file holds at most 250 lines of code (blank lines and comments aside): split it by what it is about." } },
16
+ create: (context) => {
17
+ const path = sourcePath(context);
18
+ if (path === undefined)
19
+ return {};
20
+ const max = optionsOf(context).max ?? 250;
21
+ const { add, flush } = collector(context, "max-lines", path);
22
+ return {
23
+ Program: (node) => {
24
+ const lines = codeLines(context);
25
+ if (lines > max)
26
+ add(node, `${lines} lines of code, over ${max}: split the file by what each part is about`);
27
+ },
28
+ "Program:exit": flush,
29
+ };
30
+ },
31
+ };
@@ -0,0 +1,2 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const noNameAsString: Rule;
@@ -0,0 +1,23 @@
1
+ import { SCHEMA, factsOf, pathOf } from "./facts.js";
2
+ export const noNameAsString = {
3
+ meta: { schema: SCHEMA, docs: { description: "A declared name comes from its path or export, never a string." } },
4
+ create: (context) => {
5
+ const facts = factsOf(context);
6
+ const names = new Set(facts.names);
7
+ const path = pathOf(context, facts);
8
+ if (path === undefined || path.startsWith("generated/"))
9
+ return {};
10
+ const check = (node, value) => {
11
+ if (typeof value === "string" && names.has(value))
12
+ context.report({ node, message: `"${value}" is a declared name written as a string: import the declaration instead` });
13
+ };
14
+ return {
15
+ Literal: (node) => check(node, node["value"]),
16
+ TemplateLiteral: (node) => {
17
+ const quasis = node["quasis"];
18
+ if (quasis.length === 1)
19
+ check(node, quasis[0].value.cooked);
20
+ },
21
+ };
22
+ },
23
+ };
@@ -0,0 +1,5 @@
1
+ import type { Rule } from "../types.ts";
2
+ /** What an old name is now, or undefined when the text holds none. */
3
+ export declare const oldName: (text: string) => string | undefined;
4
+ /** No old name: the old package scopes, variable prefixes, folders, config file, command or product name, in any string or name. */
5
+ export declare const noOldNames: Rule;
@@ -0,0 +1,53 @@
1
+ import { SCHEMA } from "./facts.js";
2
+ // The framework's names before M0 (`decisions/M0-packages.md`) and before K6 (`decisions/K6-orthograph.md`), spelled in
3
+ // pieces so this file doesn't match itself. `design/naming.md` maps every old name to its new one.
4
+ const ARCH = "arch" + "itect";
5
+ const FOR = "for" + "man";
6
+ const CAP = "For" + "man";
7
+ const UP = FOR.toUpperCase();
8
+ // The one form that stays: the file name of a dated record (`decisions/K2-…-frame.md`), never a name in use.
9
+ const RECORD = new RegExp(`K2-${FOR}-frame`, "g");
10
+ /** Each old form, most specific first, with what it is now. The first that matches gives the advice. */
11
+ const OLD = [
12
+ [new RegExp(`@${ARCH}/`), "@orthograph/"],
13
+ [new RegExp(`\\b${ARCH.toUpperCase()}_`), "ORTHO_"],
14
+ [new RegExp(`\\.${ARCH}(?![\\w-])`), ".ortho"],
15
+ [new RegExp(`@${FOR}ts/${FOR}(?![\\w-])`), "orthograph"],
16
+ [new RegExp(`@${FOR}ts/`), "@orthograph/"],
17
+ [new RegExp(`@${FOR}ts`), "@orthograph"],
18
+ [new RegExp(`(?<![A-Z])${UP}_`), "ORTHO_"],
19
+ [new RegExp(`\\.${FOR}/|\\.${FOR}(?![\\w-])`), ".ortho"],
20
+ [new RegExp(`_${FOR}/`), "_ortho/"],
21
+ [new RegExp(`(?<![a-z])${FOR}\\.config`), "ortho.config"],
22
+ [new RegExp(CAP), "Orthograph"],
23
+ [new RegExp(`(?<![A-Z])${UP}`), "ORTHO"],
24
+ // Lowercase, but not inside a word such as "performance" or "conformance".
25
+ [new RegExp(`(?<![a-z])${FOR}`), "ortho (or orthograph, the front door)"],
26
+ ];
27
+ /** What an old name is now, or undefined when the text holds none. */
28
+ export const oldName = (text) => {
29
+ const plain = text.replace(RECORD, "");
30
+ return OLD.find(([old]) => old.test(plain))?.[1];
31
+ };
32
+ const check = (report) => (node) => {
33
+ const value = node["value"];
34
+ const text = typeof value === "string" ? value : typeof value === "object" && value !== null ? value.raw : undefined;
35
+ if (typeof text === "string" && oldName(text) !== undefined)
36
+ report(node, text);
37
+ };
38
+ /** No old name: the old package scopes, variable prefixes, folders, config file, command or product name, in any string or name. */
39
+ export const noOldNames = {
40
+ meta: { schema: SCHEMA, docs: { description: "The framework's old names are gone (M0, K6); use orthograph, @orthograph/, ortho, ORTHO_, .ortho and ortho.config" } },
41
+ create: (context) => {
42
+ const report = (node, text) => context.report({ node, message: `\`${text}\` uses the framework's old name: it is ${oldName(text)} now` });
43
+ return {
44
+ Literal: check(report),
45
+ TemplateElement: check(report),
46
+ Identifier: (node) => {
47
+ const name = node["name"];
48
+ if (typeof name === "string" && oldName(name) !== undefined)
49
+ report(node, name);
50
+ },
51
+ };
52
+ },
53
+ };
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const noWallClock: Rule;
3
+ export declare const handlerMatchesPath: Rule;
@@ -0,0 +1,57 @@
1
+ import { SCHEMA, constructed, factsOf, pathOf } from "./facts.js";
2
+ import { sqlClockMessage } from "./sql-clock.js";
3
+ export const noWallClock = {
4
+ meta: { schema: SCHEMA, docs: { description: "No Date.now, new Date(), setTimeout or raw Effect.sleep outside the runtime: use Clock and Timers." } },
5
+ create: (context) => {
6
+ const path = pathOf(context, factsOf(context));
7
+ if (path === undefined || path.startsWith("generated/"))
8
+ return {};
9
+ return {
10
+ MemberExpression: (node) => {
11
+ const o = node["object"];
12
+ const p = node["property"];
13
+ if (o.type === "Identifier" && o.name === "Date" && p.name === "now")
14
+ context.report({ node, message: "Date.now reads the wall clock: use Clock" });
15
+ if (o.type === "Identifier" && o.name === "Effect" && p.name === "sleep")
16
+ context.report({ node, message: "a raw Effect.sleep waits outside counted work: use Timers" });
17
+ },
18
+ NewExpression: (node) => {
19
+ if (constructed(node) === "Date" && node["arguments"].length === 0)
20
+ context.report({ node, message: "new Date() reads the wall clock: use Clock" });
21
+ },
22
+ CallExpression: (node) => {
23
+ const name = constructed(node);
24
+ if (name === "setTimeout" || name === "setInterval")
25
+ context.report({ node, message: `${name} waits outside counted work: use Timers` });
26
+ },
27
+ // SQL that asks the database for the time: a world has one clock, and the database is not it (K23 section 6).
28
+ Literal: (node) => {
29
+ const message = sqlClockMessage(node);
30
+ if (message !== undefined)
31
+ context.report({ node, message });
32
+ },
33
+ TemplateElement: (node) => {
34
+ const message = sqlClockMessage(node);
35
+ if (message !== undefined)
36
+ context.report({ node, message });
37
+ },
38
+ };
39
+ },
40
+ };
41
+ // A thing's other code (workflows, contracts) lives in the same folder under other names: only <verb>.ts is a handler.
42
+ const HANDLER_SHAPE = /^src\/[^/]+\/[^/.]+\.ts$/;
43
+ export const handlerMatchesPath = {
44
+ meta: { schema: SCHEMA, docs: { description: "src/<thing>/<verb>.ts belongs to a declared operation." } },
45
+ create: (context) => {
46
+ const facts = factsOf(context);
47
+ const path = pathOf(context, facts);
48
+ if (path === undefined || !HANDLER_SHAPE.test(path) || path in facts.handlers)
49
+ return {};
50
+ return {
51
+ Program: (node) => {
52
+ const [, thing, file] = path.split("/");
53
+ context.report({ node, message: `no declared operation ${thing}.${file?.replace(/\.ts$/, "")} has its handler here` });
54
+ },
55
+ };
56
+ },
57
+ };
@@ -0,0 +1,7 @@
1
+ import type { Rule } from "../types.ts";
2
+ /**
3
+ * One package behind the portal's components (F7, M1.34; today HeroUI Pro, K24 moves it to UI SDK). `no-restricted-imports` bans Pro's scope too, but oxlint puts a
4
+ * pattern's message in its help, which the GitHub reporter drops; this rule says where to import from in the
5
+ * diagnostic itself, in every reporter. Off in `packages/portal-ui` and `spikes/` (`.oxlintrc.json`).
6
+ */
7
+ export declare const noProOutsidePortalUi: Rule;
@@ -0,0 +1,16 @@
1
+ import { everyImport } from "./imports.js";
2
+ // Pro's scope, spelled in pieces: check 15 allows its name only in portal-ui, the config and the design.
3
+ const PRO = "@heroui" + "-pro";
4
+ /**
5
+ * One package behind the portal's components (F7, M1.34; today HeroUI Pro, K24 moves it to UI SDK). `no-restricted-imports` bans Pro's scope too, but oxlint puts a
6
+ * pattern's message in its help, which the GitHub reporter drops; this rule says where to import from in the
7
+ * diagnostic itself, in every reporter. Off in `packages/portal-ui` and `spikes/` (`.oxlintrc.json`).
8
+ */
9
+ export const noProOutsidePortalUi = {
10
+ meta: { schema: [], docs: { description: "Only @orthograph/portal-ui imports HeroUI Pro (F7)." } },
11
+ create: (context) => everyImport((node, name) => {
12
+ if (name === PRO || name.startsWith(`${PRO}/`)) {
13
+ context.report({ node, message: `HeroUI Pro is imported only by @orthograph/portal-ui (F7): import the component from @orthograph/portal-ui, not ${name}` });
14
+ }
15
+ }),
16
+ };
@@ -0,0 +1,3 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const refusalHasLog: Rule;
3
+ export declare const declaredErrorsOnly: Rule;
@@ -0,0 +1,64 @@
1
+ import { SCHEMA, constructed, factsOf, pathOf } from "./facts.js";
2
+ const FUNCTION = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
3
+ /** Whether some statement before `node`'s own, in a block around it (up to its function), logs with Effect.log*. */
4
+ const loggedBefore = (node, text) => {
5
+ let child = node;
6
+ for (let at = node.parent; at && !FUNCTION.has(at.type); child = at, at = at.parent) {
7
+ if (at.type !== "BlockStatement" && at.type !== "Program")
8
+ continue;
9
+ const body = at["body"];
10
+ const before = body.slice(0, body.indexOf(child));
11
+ if (before.some((s) => /\bEffect\.log(Info|Warning|Error|Debug|Trace|Fatal)?\b/.test(text(s))))
12
+ return true;
13
+ }
14
+ return false;
15
+ };
16
+ /**
17
+ * A call step's failure mapping, `steps.price([...], (failure) => new PriceUnavailable({}))`: the step itself logs what
18
+ * decided the refusal, naming it and never the foreign failure, so the mapping has no place for a log of its own.
19
+ */
20
+ const mappingOfACall = (node, text) => {
21
+ let at = node.parent;
22
+ while (at && !FUNCTION.has(at.type))
23
+ at = at.parent;
24
+ const call = at?.parent;
25
+ return call?.type === "CallExpression" && /^steps\.\w+$/.test(text(call["callee"]));
26
+ };
27
+ export const refusalHasLog = {
28
+ meta: { schema: SCHEMA, docs: { description: "A handler logs why before it refuses, so the refusal explains itself." } },
29
+ create: (context) => {
30
+ const facts = factsOf(context);
31
+ const path = pathOf(context, facts);
32
+ if (path === undefined || !path.startsWith("src/"))
33
+ return {};
34
+ const errors = new Set(facts.errors);
35
+ return {
36
+ NewExpression: (node) => {
37
+ const name = constructed(node);
38
+ const text = (n) => context.sourceCode.getText(n);
39
+ if (name && errors.has(name) && !loggedBefore(node, text) && !mappingOfACall(node, text)) {
40
+ context.report({ node, message: `${name} is refused with no Effect.log* before it saying why` });
41
+ }
42
+ },
43
+ };
44
+ },
45
+ };
46
+ export const declaredErrorsOnly = {
47
+ meta: { schema: SCHEMA, docs: { description: "A handler constructs only the errors its operation declares (D2 #50)." } },
48
+ create: (context) => {
49
+ const facts = factsOf(context);
50
+ const path = pathOf(context, facts);
51
+ const declared = path === undefined ? undefined : facts.handlers[path];
52
+ if (declared === undefined)
53
+ return {};
54
+ const errors = new Set(facts.errors);
55
+ return {
56
+ NewExpression: (node) => {
57
+ const name = constructed(node);
58
+ if (name && errors.has(name) && !declared.includes(name)) {
59
+ context.report({ node, message: `${name} is not one of this operation's errors: ${declared.join(", ") || "it declares none"}` });
60
+ }
61
+ },
62
+ };
63
+ },
64
+ };
@@ -0,0 +1,2 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const sixSlots: Rule;
@@ -0,0 +1,46 @@
1
+ // six-slots: every module is README.md, types.ts, service.ts, internal/ and <name>.test.ts (~/AGENTS.md, the six-slot
2
+ // shape; main.ts is the package's). A module is judged once, from one file of it, so a gap is reported once.
3
+ import { existsSync, readdirSync, statSync } from "node:fs";
4
+ import { join, resolve } from "node:path";
5
+ import { SCHEMA } from "./facts.js";
6
+ import { collector, sourcePath } from "./baselined.js";
7
+ const MODULE = /^(packages\/[^/]+\/src\/modules\/([^/]+))\/(.+)$/;
8
+ const CODE = /\.tsx?$/;
9
+ /** Every .ts and .tsx file under `dir`, as paths from it, in code-point order. */
10
+ const codeFiles = (dir, prefix = "") => readdirSync(dir).sort().flatMap((name) => {
11
+ const path = join(dir, name);
12
+ return statSync(path).isDirectory() ? codeFiles(path, `${prefix}${name}/`) : CODE.test(name) ? [`${prefix}${name}`] : [];
13
+ });
14
+ /** The file a module is judged from: its first direct-child code file, or else its first code file at any depth. */
15
+ const anchorOf = (dir) => {
16
+ const files = codeFiles(dir);
17
+ return files.find((f) => !f.includes("/")) ?? files[0];
18
+ };
19
+ export const sixSlots = {
20
+ meta: { schema: SCHEMA, docs: { description: "A module holds README.md, types.ts, service.ts, internal/ and <name>.test.ts." } },
21
+ create: (context) => {
22
+ const path = sourcePath(context);
23
+ const m = path === undefined ? null : MODULE.exec(path);
24
+ if (path === undefined || m === null)
25
+ return {};
26
+ const [, folder = "", name = "", inside = ""] = m;
27
+ const dir = resolve(context.cwd, folder);
28
+ if (anchorOf(dir) !== inside)
29
+ return {};
30
+ const slots = [
31
+ ["README.md", false], ["types.ts", false], ["service.ts", false], ["internal/", true], [`${name}.test.ts`, false],
32
+ ];
33
+ const missing = slots.filter(([slot, isDir]) => {
34
+ const at = join(dir, slot);
35
+ return !existsSync(at) || statSync(at).isDirectory() !== isDir;
36
+ });
37
+ const { add, flush } = collector(context, "six-slots", path);
38
+ return {
39
+ Program: (node) => {
40
+ for (const [slot] of missing)
41
+ add(node, `module ${name} has no ${slot}: every module has README.md, types.ts, service.ts, internal/ and ${name}.test.ts`);
42
+ },
43
+ "Program:exit": flush,
44
+ };
45
+ },
46
+ };
@@ -0,0 +1,5 @@
1
+ import type { Node } from "../types.ts";
2
+ /** What in this string reads the database's clock, or nothing. */
3
+ export declare const sqlClockRead: (text: string) => string | undefined;
4
+ /** The report for a string literal or a template's piece that reads the database's clock; nothing for any other node. */
5
+ export declare const sqlClockMessage: (node: Node) => string | undefined;
@@ -0,0 +1,24 @@
1
+ const ALWAYS = /\bcurrent_(timestamp|date|time)\b|\b(datetime|date|time|julianday|strftime)\s*\([^)]*['"]now['"]/i;
2
+ // `now()` is a word of prose and of other APIs too: it counts only inside text that reads as SQL.
3
+ const NOW = /\bnow\s*\(\s*\)/i;
4
+ const SQL = /\b(select|insert|update|delete|values|where|default|create\s+table|alter\s+table|returning)\b/i;
5
+ /** What in this string reads the database's clock, or nothing. */
6
+ export const sqlClockRead = (text) => {
7
+ const always = ALWAYS.exec(text);
8
+ if (always)
9
+ return always[0].trim();
10
+ return NOW.test(text) && SQL.test(text) ? "now()" : undefined;
11
+ };
12
+ /** The text of a string literal or a template's piece, when the node is one. */
13
+ const textOf = (node) => {
14
+ if (typeof node["value"] === "string")
15
+ return node["value"];
16
+ const value = node["value"];
17
+ return typeof value?.raw === "string" ? value.raw : undefined;
18
+ };
19
+ /** The report for a string literal or a template's piece that reads the database's clock; nothing for any other node. */
20
+ export const sqlClockMessage = (node) => {
21
+ const text = textOf(node);
22
+ const read = text === undefined ? undefined : sqlClockRead(text);
23
+ return read === undefined ? undefined : `${read} reads the database's clock, not the world's: pass the time as a parameter, from Clock`;
24
+ };
@@ -0,0 +1,2 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const requiredStepUsed: Rule;
@@ -0,0 +1,40 @@
1
+ import { SCHEMA, factsOf, pathOf } from "./facts.js";
2
+ const nameOf = (node) => node?.type === "Identifier" ? node["name"] : node?.type === "Literal" ? node["value"] : undefined;
3
+ const member = (node) => {
4
+ if (node?.type !== "MemberExpression")
5
+ return undefined;
6
+ const property = node["property"];
7
+ return node["computed"] === true && property.type !== "Literal" ? undefined : nameOf(property);
8
+ };
9
+ export const requiredStepUsed = {
10
+ meta: { schema: SCHEMA, docs: { description: "Warns when the handler never calls a required step runner." } },
11
+ create: (context) => {
12
+ const facts = factsOf(context);
13
+ const path = pathOf(context, facts);
14
+ const missing = new Set(path === undefined ? [] : facts.requiredSteps?.[path]);
15
+ if (missing.size === 0)
16
+ return {};
17
+ const steps = new Set(["steps"]);
18
+ const isSteps = (node) => steps.has(nameOf(node)) || member(node) === "steps";
19
+ return {
20
+ Property: (node) => {
21
+ if (node.parent?.type === "ObjectPattern" && nameOf(node["key"]) === "steps") {
22
+ const binding = nameOf(node["value"]);
23
+ if (typeof binding === "string")
24
+ steps.add(binding);
25
+ }
26
+ },
27
+ CallExpression: (node) => {
28
+ const callee = node["callee"];
29
+ const key = member(callee);
30
+ // shortcut: statically named runner calls only, follow indirect calls if handlers start sharing runners.
31
+ if (typeof key === "string" && isSteps(callee["object"]))
32
+ missing.delete(key);
33
+ },
34
+ "Program:exit": (node) => {
35
+ for (const key of missing)
36
+ context.report({ node, message: `required step steps.${key} is never called` });
37
+ },
38
+ };
39
+ },
40
+ };
@@ -0,0 +1,7 @@
1
+ import type { Rule } from "../types.ts";
2
+ /**
3
+ * K19, the portal ships prebuilt: the code a Worker bundles never imports the UI. A Worker has no use for React, and a project that
4
+ * bundled `@orthograph/portal-ui` would need a HeroUI Pro licence to build. On for `generated/` folders and the portal's server half;
5
+ * off for the client half (`.oxlintrc.json`), which is built once in this repository and shipped as static files.
6
+ */
7
+ export declare const noUiInWorker: Rule;
@@ -0,0 +1,16 @@
1
+ import { everyImport } from "./imports.js";
2
+ // The UI's names: React, the portal's UI and HeroUI (both packages). Pro's scope is spelled in pieces, as `pro.ts` does.
3
+ const UI = [/^react(-dom)?(\/|$)/, /^@orthograph\/portal-ui(\/|$)/, /^@heroui(-pro)?\//];
4
+ /**
5
+ * K19, the portal ships prebuilt: the code a Worker bundles never imports the UI. A Worker has no use for React, and a project that
6
+ * bundled `@orthograph/portal-ui` would need a HeroUI Pro licence to build. On for `generated/` folders and the portal's server half;
7
+ * off for the client half (`.oxlintrc.json`), which is built once in this repository and shipped as static files.
8
+ */
9
+ export const noUiInWorker = {
10
+ meta: { schema: [], docs: { description: "K19: nothing a Worker bundles imports react, @orthograph/portal-ui or HeroUI." } },
11
+ create: (context) => everyImport((node, name) => {
12
+ if (UI.some((pattern) => pattern.test(name))) {
13
+ context.report({ node, message: `K19: '${name}' is the portal's UI, and a Worker never imports it: the client is built once, in this repository, and ships as static files; the Worker imports only @orthograph/portal/server` });
14
+ }
15
+ }),
16
+ };
@@ -0,0 +1,2 @@
1
+ import type { Rule } from "../types.ts";
2
+ export declare const noViemOutsideChain: Rule;
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { everyImport } from "./imports.js";
3
+ const CHAIN = fileURLToPath(new URL("../../../../../chain-evm/", import.meta.url));
4
+ export const noViemOutsideChain = {
5
+ meta: { schema: [], docs: { description: "The EVM chain package owns all hand-written viem imports." } },
6
+ create: (context) => {
7
+ if (context.filename.startsWith(CHAIN))
8
+ return {};
9
+ return everyImport((node, name) => {
10
+ if (name === "viem" || name.startsWith("viem/")) {
11
+ context.report({ node, message: "Import EVM functionality from @orthograph/chain-evm instead of viem" });
12
+ }
13
+ });
14
+ },
15
+ };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "./types.ts";
2
+ /** The oxlint plugin. `ortho check` registers it by path and passes every rule the same `ProjectFacts`. */
3
+ export declare const plugin: Plugin;
@@ -0,0 +1,34 @@
1
+ import { noNameAsString } from "./internal/names.js";
2
+ import { declaredErrorsOnly, refusalHasLog } from "./internal/refusals.js";
3
+ import { handlerMatchesPath, noWallClock } from "./internal/place.js";
4
+ import { noViemOutsideChain } from "./internal/viem.js";
5
+ import { noProOutsidePortalUi } from "./internal/pro.js";
6
+ import { noUiInWorker } from "./internal/ui.js";
7
+ import { noOldNames } from "./internal/old-names.js";
8
+ import { requiredStepUsed } from "./internal/steps.js";
9
+ import { declaredErrorNamed, outcomeChosen } from "./internal/drift.js";
10
+ import { effectOnly } from "./internal/effect-only.js";
11
+ import { maxLines } from "./internal/max-lines.js";
12
+ import { sixSlots } from "./internal/six-slots.js";
13
+ /** The oxlint plugin. `ortho check` registers it by path and passes every rule the same `ProjectFacts`. */
14
+ export const plugin = {
15
+ meta: { name: "ortho" },
16
+ rules: {
17
+ "no-name-as-string": noNameAsString,
18
+ "refusal-has-log": refusalHasLog,
19
+ "declared-errors-only": declaredErrorsOnly,
20
+ "no-wall-clock": noWallClock,
21
+ "handler-matches-path": handlerMatchesPath,
22
+ "no-old-names": noOldNames,
23
+ "required-step-used": requiredStepUsed,
24
+ "outcome-chosen": outcomeChosen,
25
+ "declared-error-named": declaredErrorNamed,
26
+ "no-viem-outside-chain": noViemOutsideChain,
27
+ "no-pro-outside-portal-ui": noProOutsidePortalUi,
28
+ "no-ui-in-worker": noUiInWorker,
29
+ // The repository's own code rules (AGENTS.md), each with a baseline of the breaches it tolerates.
30
+ "effect-only": effectOnly,
31
+ "max-lines": maxLines,
32
+ "six-slots": sixSlots,
33
+ },
34
+ };
@@ -0,0 +1,64 @@
1
+ /** What `ortho check` tells every rule about the project. */
2
+ export interface ProjectFacts {
3
+ /** The project's root, absolute: rules see absolute file names and judge them by their path from here. */
4
+ readonly root: string;
5
+ /** Every declared name: operations, steps, events and errors. None may be written as a string outside generated/. */
6
+ readonly names: ReadonlyArray<string>;
7
+ /** Every declared error class name, across all things. */
8
+ readonly errors: ReadonlyArray<string>;
9
+ /** Each handler file (from the root) and the errors its operation declares. */
10
+ readonly handlers: Readonly<Record<string, ReadonlyArray<string>>>;
11
+ /** Required runner keys per handler file. */
12
+ readonly requiredSteps?: Readonly<Record<string, ReadonlyArray<string>>>;
13
+ /** Per handler file, the outcomes of its move when it has more than one: each should be named in a `move("…")`. */
14
+ readonly outcomes?: Readonly<Record<string, ReadonlyArray<string>>>;
15
+ }
16
+ /** The subset of oxlint's (ESLint's) rule context the rules use. */
17
+ export interface Context {
18
+ readonly options: ReadonlyArray<unknown>;
19
+ readonly filename: string;
20
+ /** The directory oxlint runs in: the repository's own rules judge a file by its path from here. */
21
+ readonly cwd: string;
22
+ readonly sourceCode: {
23
+ readonly getText: (node?: Node) => string;
24
+ readonly text: string;
25
+ readonly getAllComments: () => ReadonlyArray<{
26
+ readonly range?: readonly [number, number];
27
+ readonly start?: number;
28
+ readonly end?: number;
29
+ }>;
30
+ };
31
+ readonly report: (r: {
32
+ readonly node: Node;
33
+ readonly message: string;
34
+ }) => void;
35
+ }
36
+ export interface Node {
37
+ readonly type: string;
38
+ readonly parent?: Node;
39
+ readonly [key: string]: unknown;
40
+ }
41
+ /** The options every repository code rule takes: a baseline of the breaches it tolerates, file by file. */
42
+ export interface CodeRuleOptions {
43
+ /** Path from cwd to the baseline JSON, `{ "<rule>": { "<path from cwd>": <count> } }`. */
44
+ readonly baseline?: string;
45
+ /** effect-only: more entry files, as paths from cwd, where effects at the edge are allowed. */
46
+ readonly entries?: ReadonlyArray<string>;
47
+ /** max-lines: lines of code allowed in a file (250). */
48
+ readonly max?: number;
49
+ }
50
+ export interface Rule {
51
+ readonly meta: {
52
+ readonly schema: ReadonlyArray<unknown>;
53
+ readonly docs: {
54
+ readonly description: string;
55
+ };
56
+ };
57
+ readonly create: (context: Context) => Record<string, (node: Node) => void>;
58
+ }
59
+ export interface Plugin {
60
+ readonly meta: {
61
+ readonly name: "ortho";
62
+ };
63
+ readonly rules: Readonly<Record<string, Rule>>;
64
+ }
@@ -0,0 +1,3 @@
1
+ // The ortho lint rules: what the types can't see, as an oxlint JS plugin (`ortho/*`). Each rule gets what the
2
+ // project declares through one options object, which `ortho check` writes from the model (rules have no types).
3
+ export {};
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@orthograph/lint",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-next.1",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./plugin": {
12
+ "types": "./dist/main.d.ts",
13
+ "default": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "dependencies": {},
18
+ "imports": {
19
+ "#modules/*.js": "./dist/modules/*.js"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "tag": "next"
27
+ }
6
28
  }