@autotelic/plumb 0.6.0 → 0.6.2

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 (71) hide show
  1. package/README.md +81 -8
  2. package/dist/configs/recommended-rules.d.ts +36 -0
  3. package/dist/configs/recommended-rules.js +57 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  5. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  6. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  7. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  8. package/dist/effect/rules/no-direct-fetch.js +1 -1
  9. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  10. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  11. package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
  12. package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
  13. package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
  14. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  15. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  16. package/dist/effect/rules/no-try-catch.js +1 -1
  17. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  18. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  19. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  20. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  21. package/dist/effect/rules/prefer-effect-match.js +2 -2
  22. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  23. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  24. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  25. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  26. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  27. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  28. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  29. package/dist/index.js +8 -0
  30. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  31. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  32. package/dist/react/rules/require-tripartite-context.js +1 -1
  33. package/dist/react/rules/use-encapsulation.js +1 -1
  34. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  35. package/dist/rules/no-adapter-in-values.js +110 -0
  36. package/dist/rules/no-builtin-throws.js +1 -1
  37. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  38. package/dist/rules/no-duplicated-literal-union.js +5 -1
  39. package/dist/rules/no-generic-export-names.js +1 -1
  40. package/dist/rules/no-multiple-function-params.js +26 -12
  41. package/dist/rules/no-mutable-environment-capture.js +2 -2
  42. package/dist/rules/no-nondeterministic-core.js +1 -1
  43. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  44. package/dist/rules/no-nullable-value-field.js +117 -0
  45. package/dist/rules/no-optional-function-parameters.js +1 -1
  46. package/dist/rules/no-row-coercion.d.ts +13 -0
  47. package/dist/rules/no-row-coercion.js +135 -0
  48. package/dist/rules/no-single-use-private-functions.js +1 -1
  49. package/dist/rules/no-sql-string-interpolation.js +2 -2
  50. package/dist/rules/no-stray-inline-comments.js +1 -1
  51. package/dist/rules/no-string-instant.d.ts +15 -0
  52. package/dist/rules/no-string-instant.js +108 -0
  53. package/dist/rules/no-swappable-primitive-params.js +1 -1
  54. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  55. package/dist/rules/no-vague-test-filenames.js +1 -1
  56. package/dist/rules/prefer-property-tests.d.ts +5 -0
  57. package/dist/rules/prefer-property-tests.js +7 -0
  58. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  59. package/dist/shared/ancestors.d.ts +1 -1
  60. package/dist/shared/ancestors.js +1 -1
  61. package/dist/shared/values-path.d.ts +12 -0
  62. package/dist/shared/values-path.js +56 -0
  63. package/dist/testing/testable-rule.d.ts +6 -5
  64. package/dist/testing/testable-rule.js +20 -6
  65. package/dist/ui/index.d.ts +12 -0
  66. package/dist/ui/index.js +18 -0
  67. package/dist/ui/manifest.d.ts +49 -0
  68. package/dist/ui/manifest.js +90 -0
  69. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  70. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  71. package/package.json +28 -19
@@ -0,0 +1,15 @@
1
+ /** Whether a field name claims to be an instant.
2
+ *
3
+ * @param {string} name - The field's name.
4
+ * @returns {boolean} True when the name is a date or a time.
5
+ */
6
+ export declare function namesAnInstant(name: string): boolean;
7
+ /**
8
+ * An instant is a value with an identity, not the text of one.
9
+ *
10
+ * `"2026-10-22T00:00:00Z"` and `"2026-10-22 00:00:00+00"` agree until one of
11
+ * them crosses a timezone. A string field in the values stratum lets every
12
+ * reader parse it differently, so the format becomes folklore instead of a
13
+ * type. The wire type may be text; the value must not.
14
+ */
15
+ export declare const noStringInstantRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,108 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isString } from "../shared/structural.js";
3
+ import { inValuesPath } from "../shared/values-path.js";
4
+ /** The suffixes that name an instant rather than a piece of text. */
5
+ const INSTANT_SUFFIXES = ["At", "Date", "Timestamp", "_at", "_date"];
6
+ /** Whether a field name claims to be an instant.
7
+ *
8
+ * @param {string} name - The field's name.
9
+ * @returns {boolean} True when the name is a date or a time.
10
+ */
11
+ export function namesAnInstant(name) {
12
+ if (name.toLowerCase() === "timestamp")
13
+ return true;
14
+ return INSTANT_SUFFIXES.some((suffix) => name.endsWith(suffix));
15
+ }
16
+ /** Whether a schema chain bottoms out at `Schema.String`.
17
+ *
18
+ * @param {ESTree.Node} node - The field's value expression.
19
+ * @returns {boolean} True when the chain constructs a string.
20
+ */
21
+ function isSchemaString(node) {
22
+ if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
23
+ return node.property.name === "String";
24
+ }
25
+ if (node.type === "CallExpression") {
26
+ const first = node.arguments[0];
27
+ return first !== undefined && isSchemaString(first);
28
+ }
29
+ return node.type === "TSNonNullExpression" ? isSchemaString(node.expression) : false;
30
+ }
31
+ /** The key of an object property, when it is a plain name.
32
+ *
33
+ * @param {ESTree.ObjectProperty} property - The property to read.
34
+ * @returns {string | null} The key, or null for a computed or spread entry.
35
+ */
36
+ function propertyKey(property) {
37
+ if (property.key.type === "Identifier")
38
+ return property.key.name;
39
+ if (property.key.type === "Literal" && isString(property.key.value))
40
+ return property.key.value;
41
+ return null;
42
+ }
43
+ /**
44
+ * An instant is a value with an identity, not the text of one.
45
+ *
46
+ * `"2026-10-22T00:00:00Z"` and `"2026-10-22 00:00:00+00"` agree until one of
47
+ * them crosses a timezone. A string field in the values stratum lets every
48
+ * reader parse it differently, so the format becomes folklore instead of a
49
+ * type. The wire type may be text; the value must not.
50
+ */
51
+ export const noStringInstantRule = defineRule({
52
+ meta: {
53
+ type: "suggestion",
54
+ docs: {
55
+ description: "Disallow string-typed instant fields inside a declared values path; use a date type so the format has one implementation.",
56
+ },
57
+ messages: {
58
+ stringInstant: "`{{name}}` holds an instant as text. Text is transport: two formats that agree today disagree after a timezone. Parse it at the boundary and carry a date type here.",
59
+ },
60
+ schema: [
61
+ {
62
+ type: "object",
63
+ properties: {
64
+ paths: { type: "array", items: { type: "string" } },
65
+ },
66
+ additionalProperties: false,
67
+ },
68
+ ],
69
+ defaultOptions: [{}],
70
+ },
71
+ createOnce(context) {
72
+ function checkProperty(node) {
73
+ if (node.key.type !== "Identifier" || !namesAnInstant(node.key.name))
74
+ return;
75
+ if (node.typeAnnotation?.typeAnnotation.type !== "TSStringKeyword")
76
+ return;
77
+ context.report({ node, messageId: "stringInstant", data: { name: node.key.name } });
78
+ }
79
+ function checkStruct(node) {
80
+ const callee = node.callee;
81
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
82
+ return;
83
+ if (callee.property.name !== "Struct")
84
+ return;
85
+ const first = node.arguments[0];
86
+ if (first === undefined || first.type !== "ObjectExpression")
87
+ return;
88
+ for (const property of first.properties) {
89
+ if (property.type !== "Property")
90
+ continue;
91
+ const name = propertyKey(property);
92
+ if (name === null || !namesAnInstant(name))
93
+ continue;
94
+ if (!isSchemaString(property.value))
95
+ continue;
96
+ context.report({ node: property, messageId: "stringInstant", data: { name } });
97
+ }
98
+ }
99
+ return {
100
+ before() {
101
+ if (!inValuesPath(context.filename, context.options))
102
+ return false;
103
+ },
104
+ TSPropertySignature: checkProperty,
105
+ CallExpression: checkStruct,
106
+ };
107
+ },
108
+ });
@@ -1,5 +1,5 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
3
  /** Keyword node type -> spelled-out primitive for messages. */
4
4
  const PRIMITIVE_KEYWORDS = new Map([
5
5
  ["TSStringKeyword", "string"],
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { isRecordObject, isString } from "../shared/structural.js";
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
4
4
  /** Whether the if-consequent (or alternate) is a bare `throw new Error(...)` assertion.
5
5
  *
6
6
  * @param {ESTree.Statement | null | undefined} statement - The branch body to inspect.
@@ -1,5 +1,5 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
3
  /** Stems that name nothing; a test file must point back at the module it covers. */
4
4
  const VAGUE_STEMS = new Set([
5
5
  "index",
@@ -1,5 +1,10 @@
1
1
  /**
2
2
  * We default to property-based testing: a test suite without fast-check only
3
3
  * pins examples. Escape hatch is an explicit inline disable with a reason.
4
+ *
5
+ * The visitor resets its state in `before()`: `createOnce` state spans the whole
6
+ * run, so without the reset a file that imports fast-check marks every later file
7
+ * as having one, and the same tree reports a suite or does not depending on the
8
+ * order files are visited.
4
9
  */
5
10
  export declare const preferPropertyTestsRule: import("@oxlint/plugins").Rule;
@@ -3,6 +3,11 @@ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
3
  /**
4
4
  * We default to property-based testing: a test suite without fast-check only
5
5
  * pins examples. Escape hatch is an explicit inline disable with a reason.
6
+ *
7
+ * The visitor resets its state in `before()`: `createOnce` state spans the whole
8
+ * run, so without the reset a file that imports fast-check marks every later file
9
+ * as having one, and the same tree reports a suite or does not depending on the
10
+ * order files are visited.
6
11
  */
7
12
  export const preferPropertyTestsRule = defineRule({
8
13
  meta: {
@@ -19,6 +24,8 @@ export const preferPropertyTestsRule = defineRule({
19
24
  let sawFastCheck = false;
20
25
  return {
21
26
  before() {
27
+ program = null;
28
+ sawFastCheck = false;
22
29
  if (!TEST_FILE.test(context.filename.replaceAll("\\", "/")))
23
30
  return false;
24
31
  },
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { getAllComments } from "../shared/structural.js";
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
4
  /** Every exported function carries a complete JSDoc contract. */
5
5
  export const requireJsdocOnExportedRule = defineRule({
6
6
  meta: {
@@ -13,6 +13,6 @@ import type { ESTree, SourceCode } from "@oxlint/plugins";
13
13
  *
14
14
  * @param {SourceCode} sourceCode - The rule's source-code accessor.
15
15
  * @param {ESTree.Node} node - The node whose ancestor chain is requested.
16
- * @returns {ReadonlyArray<ESTree.Node>} Nearest-first ancestor chain.
16
+ * @returns {ReadonlyArray<ESTree.Node>} Outermost-first ancestor chain (Program at index 0, the immediate parent last; use `.at(-1)` for the parent).
17
17
  */
18
18
  export declare function ancestorsOf(sourceCode: SourceCode, node: ESTree.Node): ReadonlyArray<ESTree.Node>;
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * @param {SourceCode} sourceCode - The rule's source-code accessor.
14
14
  * @param {ESTree.Node} node - The node whose ancestor chain is requested.
15
- * @returns {ReadonlyArray<ESTree.Node>} Nearest-first ancestor chain.
15
+ * @returns {ReadonlyArray<ESTree.Node>} Outermost-first ancestor chain (Program at index 0, the immediate parent last; use `.at(-1)` for the parent).
16
16
  */
17
17
  export function ancestorsOf(sourceCode, node) {
18
18
  return sourceCode.getAncestors(node);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether a file belongs to the declared values path.
3
+ *
4
+ * A declared prefix matches the file itself or anything below it. With no
5
+ * option, a directory SEGMENT carries the name, so `src/domain/money.ts` and
6
+ * `packages/domain/src/hours.ts` are both values.
7
+ *
8
+ * @param {string} filename - The file being linted.
9
+ * @param {readonly unknown[] | undefined} options - The rule's raw options.
10
+ * @returns {boolean} True when the file is inside the values stratum.
11
+ */
12
+ export declare function inValuesPath(filename: string, options: readonly unknown[] | undefined): boolean;
@@ -0,0 +1,56 @@
1
+ import { firstOptionRecord } from "./rule-options.js";
2
+ import { isString } from "./structural.js";
3
+ /**
4
+ * The directories a repository declares as its values stratum.
5
+ *
6
+ * The default is a CONVENTION, not a fact: `domain`, `values` and `model` are
7
+ * the names repositories give the folder that holds `Money` and `Hours`. A
8
+ * repository whose values live somewhere else names the path in the rule's
9
+ * options (`{ "paths": ["src/domain"] }`), because a lint rule cannot infer
10
+ * where the pure layer is from one file.
11
+ */
12
+ const DEFAULT_SEGMENTS = new Set(["domain", "model", "value-objects", "values"]);
13
+ /**
14
+ * The declared path prefixes, or an empty list when the option is absent or malformed.
15
+ *
16
+ * @param {readonly unknown[] | undefined} options - The rule's raw options.
17
+ * @returns {ReadonlyArray<string>} The non-empty path prefixes, if any.
18
+ */
19
+ function declaredPaths(options) {
20
+ const record = firstOptionRecord(options);
21
+ const declared = record["paths"];
22
+ if (!Array.isArray(declared))
23
+ return [];
24
+ return declared.filter((entry) => isString(entry) && entry.length > 0);
25
+ }
26
+ /** Normalise a path prefix so `./src/domain/` and `src/domain` compare equally.
27
+ *
28
+ * @param {string} path - The path or prefix to normalise.
29
+ * @returns {string} A slash-only path with no leading `./` or trailing slash.
30
+ */
31
+ function normalise(path) {
32
+ return path.replaceAll("\\", "/").replace(/^\.\//u, "").replace(/\/+$/u, "");
33
+ }
34
+ /**
35
+ * Whether a file belongs to the declared values path.
36
+ *
37
+ * A declared prefix matches the file itself or anything below it. With no
38
+ * option, a directory SEGMENT carries the name, so `src/domain/money.ts` and
39
+ * `packages/domain/src/hours.ts` are both values.
40
+ *
41
+ * @param {string} filename - The file being linted.
42
+ * @param {readonly unknown[] | undefined} options - The rule's raw options.
43
+ * @returns {boolean} True when the file is inside the values stratum.
44
+ */
45
+ export function inValuesPath(filename, options) {
46
+ const file = normalise(filename);
47
+ const paths = declaredPaths(options);
48
+ if (paths.length > 0) {
49
+ return paths.some((prefix) => {
50
+ const normalised = normalise(prefix);
51
+ return file === normalised || file.startsWith(`${normalised}/`) || file.includes(`/${normalised}/`);
52
+ });
53
+ }
54
+ const directories = file.split("/").slice(0, -1);
55
+ return directories.some((segment) => DEFAULT_SEGMENTS.has(segment));
56
+ }
@@ -25,11 +25,12 @@ export declare function createTester(): RuleTester;
25
25
  * Adapt a `createOnce` rule for Oxlint's RuleTester.
26
26
  *
27
27
  * RuleTester drives rules through their ESLint-compatible `create` method and
28
- * does not understand `before`/`after` lifecycle hooks. The adapter invokes
29
- * `createOnce` once per linted file (fresh state per file, exactly like native
30
- * Oxlint), honours the skip contract (`before` returning `false` skips the
31
- * file), and chains the rule's own `Program:exit` visitor with the after hook
32
- * instead of clobbering it.
28
+ * does not understand `before`/`after` lifecycle hooks. Like native Oxlint, the
29
+ * adapter invokes `createOnce` once and reuses its visitors for every linted
30
+ * file, so state a rule forgets to reset in `before` leaks between test cases
31
+ * exactly as it would leak between files in a real run. It also honours the
32
+ * skip contract (`before` returning `false` skips the file), and chains the
33
+ * rule's own `Program:exit` visitor with the after hook instead of clobbering it.
33
34
  *
34
35
  * @param {CreateOnceRule | Rule} rule - The createOnce-style rule to adapt. A
35
36
  * rule already in ESLint-style passes through untouched.
@@ -31,11 +31,12 @@ export function createTester() {
31
31
  * Adapt a `createOnce` rule for Oxlint's RuleTester.
32
32
  *
33
33
  * RuleTester drives rules through their ESLint-compatible `create` method and
34
- * does not understand `before`/`after` lifecycle hooks. The adapter invokes
35
- * `createOnce` once per linted file (fresh state per file, exactly like native
36
- * Oxlint), honours the skip contract (`before` returning `false` skips the
37
- * file), and chains the rule's own `Program:exit` visitor with the after hook
38
- * instead of clobbering it.
34
+ * does not understand `before`/`after` lifecycle hooks. Like native Oxlint, the
35
+ * adapter invokes `createOnce` once and reuses its visitors for every linted
36
+ * file, so state a rule forgets to reset in `before` leaks between test cases
37
+ * exactly as it would leak between files in a real run. It also honours the
38
+ * skip contract (`before` returning `false` skips the file), and chains the
39
+ * rule's own `Program:exit` visitor with the after hook instead of clobbering it.
39
40
  *
40
41
  * @param {CreateOnceRule | Rule} rule - The createOnce-style rule to adapt. A
41
42
  * rule already in ESLint-style passes through untouched.
@@ -44,10 +45,23 @@ export function createTester() {
44
45
  export function testableRule(rule) {
45
46
  if (!isCreateOnceRule(rule))
46
47
  return rule;
48
+ let currentContext;
49
+ const sharedContext = new Proxy({}, {
50
+ get(_target, key) {
51
+ // SAFETY: the proxy stands in for the per-file context, so every key
52
+ // read is a key of that context.
53
+ const value = currentContext[key];
54
+ return value instanceof Function ? value.bind(currentContext) : value;
55
+ },
56
+ });
57
+ let hooks;
47
58
  const adapter = {
48
59
  meta: rule.meta,
49
60
  create(context) {
50
- const { after, before, ...visitor } = rule.createOnce(context);
61
+ currentContext = context;
62
+ // SAFETY: the proxy forwards every read to the current file's context.
63
+ hooks ??= rule.createOnce(sharedContext);
64
+ const { after, before, ...visitor } = hooks;
51
65
  // SAFETY: visitor fragments come from this plugin's own createOnce
52
66
  // contract; method keys map one-to-one onto the tester's call shape.
53
67
  const visitors = visitor;
@@ -0,0 +1,12 @@
1
+ import { noDeprecatedPartsRule } from "./rules/no-deprecated-parts.ts";
2
+ /**
3
+ * Rules that read the catalog's lint manifest.
4
+ *
5
+ * These are separate from `plumb-react` because they need a second input — the generated
6
+ * manifest — and a repository without a catalog should not enable them. A rule here is a
7
+ * lookup, never a second analysis: cutlist already decided which part is deprecated and
8
+ * what replaces it.
9
+ */
10
+ declare const plumbUiPlugin: import("@oxlint/plugins").Plugin;
11
+ export default plumbUiPlugin;
12
+ export { noDeprecatedPartsRule };
@@ -0,0 +1,18 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+ import { noDeprecatedPartsRule } from "./rules/no-deprecated-parts.js";
3
+ /**
4
+ * Rules that read the catalog's lint manifest.
5
+ *
6
+ * These are separate from `plumb-react` because they need a second input — the generated
7
+ * manifest — and a repository without a catalog should not enable them. A rule here is a
8
+ * lookup, never a second analysis: cutlist already decided which part is deprecated and
9
+ * what replaces it.
10
+ */
11
+ const plumbUiPlugin = eslintCompatPlugin({
12
+ meta: { name: "plumb-ui" },
13
+ rules: {
14
+ "no-deprecated-parts": noDeprecatedPartsRule,
15
+ },
16
+ });
17
+ export default plumbUiPlugin;
18
+ export { noDeprecatedPartsRule };
@@ -0,0 +1,49 @@
1
+ /** Where a part is in its life. */
2
+ export type UiPartStatus = "stable" | "beta" | "experimental" | "deprecated";
3
+ /** The subset of a manifest component the deprecation rule reads. */
4
+ export interface UiPart {
5
+ readonly path: string;
6
+ readonly name: string;
7
+ readonly exports?: ReadonlyArray<string>;
8
+ readonly status?: UiPartStatus;
9
+ readonly useInstead?: ReadonlyArray<string>;
10
+ }
11
+ /** A manifest, reduced to the parts the rule can act on. */
12
+ export interface UiManifest {
13
+ readonly components: ReadonlyArray<UiPart>;
14
+ }
15
+ /**
16
+ * Read one component, or `undefined` when it cannot be identified.
17
+ *
18
+ * `tier`, `owners`, `props` and `tags` are required by the manifest schema but not by
19
+ * this rule. Requiring them here would make a hand-written fixture verbose for no gain,
20
+ * and the rule's question is only "who is deprecated, and what replaces it".
21
+ * @param {unknown} value - The decoded JSON entry.
22
+ * @returns {UiPart | undefined} The part, or `undefined` when it cannot be identified.
23
+ */
24
+ export declare function decodeUiPart(value: unknown): UiPart | undefined;
25
+ /**
26
+ * Read a manifest, or `undefined` when it is not one.
27
+ *
28
+ * @param {unknown} value - The decoded JSON document.
29
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is malformed.
30
+ */
31
+ export declare function decodeUiManifest(value: unknown): UiManifest | undefined;
32
+ /**
33
+ * Read a manifest from disk, degrading to `undefined`.
34
+ *
35
+ * A missing or malformed manifest is not a lint error: the rule goes quiet, exactly as
36
+ * every other manifest reader in this workspace does. `cutlist build --check` is the
37
+ * gate that makes a stale manifest loud.
38
+ *
39
+ * @param {string} path - The manifest file to read.
40
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is absent or bad.
41
+ */
42
+ export declare function readUiManifest(path: string): UiManifest | undefined;
43
+ /**
44
+ * Resolve a configured path against the process working directory.
45
+ *
46
+ * @param {string} path - The manifest path, relative to the process cwd.
47
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is absent or bad.
48
+ */
49
+ export declare function manifestAt(path: string): UiManifest | undefined;
@@ -0,0 +1,90 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ const STATUSES = ["stable", "beta", "experimental", "deprecated"];
4
+ function isRecord(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ }
7
+ function str(value) {
8
+ return typeof value === "string" ? value : undefined;
9
+ }
10
+ function strings(value) {
11
+ if (!Array.isArray(value))
12
+ return undefined;
13
+ if (!value.every((entry) => typeof entry === "string"))
14
+ return undefined;
15
+ return value;
16
+ }
17
+ function status(value) {
18
+ return STATUSES.find((entry) => entry === value);
19
+ }
20
+ /**
21
+ * Read one component, or `undefined` when it cannot be identified.
22
+ *
23
+ * `tier`, `owners`, `props` and `tags` are required by the manifest schema but not by
24
+ * this rule. Requiring them here would make a hand-written fixture verbose for no gain,
25
+ * and the rule's question is only "who is deprecated, and what replaces it".
26
+ * @param {unknown} value - The decoded JSON entry.
27
+ * @returns {UiPart | undefined} The part, or `undefined` when it cannot be identified.
28
+ */
29
+ export function decodeUiPart(value) {
30
+ if (!isRecord(value))
31
+ return undefined;
32
+ const path = str(value.path);
33
+ const name = str(value.name);
34
+ if (path === undefined || name === undefined)
35
+ return undefined;
36
+ const exports = strings(value.exports);
37
+ const partStatus = status(value.status);
38
+ const useInstead = strings(value.useInstead);
39
+ return {
40
+ path,
41
+ name,
42
+ ...(exports === undefined ? {} : { exports }),
43
+ ...(partStatus === undefined ? {} : { status: partStatus }),
44
+ ...(useInstead === undefined ? {} : { useInstead }),
45
+ };
46
+ }
47
+ /**
48
+ * Read a manifest, or `undefined` when it is not one.
49
+ *
50
+ * @param {unknown} value - The decoded JSON document.
51
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is malformed.
52
+ */
53
+ export function decodeUiManifest(value) {
54
+ if (!isRecord(value) || !Array.isArray(value.components))
55
+ return undefined;
56
+ const components = [];
57
+ for (const entry of value.components) {
58
+ const part = decodeUiPart(entry);
59
+ if (part !== undefined)
60
+ components.push(part);
61
+ }
62
+ return { components };
63
+ }
64
+ /**
65
+ * Read a manifest from disk, degrading to `undefined`.
66
+ *
67
+ * A missing or malformed manifest is not a lint error: the rule goes quiet, exactly as
68
+ * every other manifest reader in this workspace does. `cutlist build --check` is the
69
+ * gate that makes a stale manifest loud.
70
+ *
71
+ * @param {string} path - The manifest file to read.
72
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is absent or bad.
73
+ */
74
+ export function readUiManifest(path) {
75
+ try {
76
+ return decodeUiManifest(JSON.parse(readFileSync(path, "utf8")));
77
+ }
78
+ catch {
79
+ return undefined;
80
+ }
81
+ }
82
+ /**
83
+ * Resolve a configured path against the process working directory.
84
+ *
85
+ * @param {string} path - The manifest path, relative to the process cwd.
86
+ * @returns {UiManifest | undefined} The manifest, or `undefined` when it is absent or bad.
87
+ */
88
+ export function manifestAt(path) {
89
+ return readUiManifest(resolve(process.cwd(), path));
90
+ }
@@ -0,0 +1,3 @@
1
+ declare const RULE_ID = "plumb-ui/no-deprecated-parts";
2
+ export declare const noDeprecatedPartsRule: import("@oxlint/plugins").Rule;
3
+ export { RULE_ID };