@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.
- package/README.md +81 -8
- package/dist/configs/recommended-rules.d.ts +36 -0
- package/dist/configs/recommended-rules.js +57 -0
- package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
- package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
- package/dist/effect/rules/no-decode-unknown-option.js +1 -1
- package/dist/effect/rules/no-direct-browser-storage.js +3 -3
- package/dist/effect/rules/no-direct-fetch.js +1 -1
- package/dist/effect/rules/no-manual-field-guards.js +1 -1
- package/dist/effect/rules/no-nested-layer-provide.js +1 -1
- package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
- package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
- package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
- package/dist/effect/rules/no-silent-error-swallow.js +1 -1
- package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
- package/dist/effect/rules/no-try-catch.js +1 -1
- package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
- package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
- package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
- package/dist/effect/rules/prefer-effect-match.js +2 -2
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
- package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
- package/dist/effect/rules/prefer-option-pipeline.js +13 -12
- package/dist/effect/rules/prefer-ordering-match.js +1 -1
- package/dist/effect/rules/prefer-tagged-enum.js +1 -1
- package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
- package/dist/effect/rules/require-schema-type-derivation.js +14 -4
- package/dist/index.js +8 -0
- package/dist/react/rules/require-dot-notation-exports.js +1 -1
- package/dist/react/rules/require-guarded-context-hook.js +1 -1
- package/dist/react/rules/require-tripartite-context.js +1 -1
- package/dist/react/rules/use-encapsulation.js +1 -1
- package/dist/rules/no-adapter-in-values.d.ts +12 -0
- package/dist/rules/no-adapter-in-values.js +110 -0
- package/dist/rules/no-builtin-throws.js +1 -1
- package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
- package/dist/rules/no-duplicated-literal-union.js +5 -1
- package/dist/rules/no-generic-export-names.js +1 -1
- package/dist/rules/no-multiple-function-params.js +26 -12
- package/dist/rules/no-mutable-environment-capture.js +2 -2
- package/dist/rules/no-nondeterministic-core.js +1 -1
- package/dist/rules/no-nullable-value-field.d.ts +16 -0
- package/dist/rules/no-nullable-value-field.js +117 -0
- package/dist/rules/no-optional-function-parameters.js +1 -1
- package/dist/rules/no-row-coercion.d.ts +13 -0
- package/dist/rules/no-row-coercion.js +135 -0
- package/dist/rules/no-single-use-private-functions.js +1 -1
- package/dist/rules/no-sql-string-interpolation.js +2 -2
- package/dist/rules/no-stray-inline-comments.js +1 -1
- package/dist/rules/no-string-instant.d.ts +15 -0
- package/dist/rules/no-string-instant.js +108 -0
- package/dist/rules/no-swappable-primitive-params.js +1 -1
- package/dist/rules/no-tag-ladder-assertions.js +1 -1
- package/dist/rules/no-vague-test-filenames.js +1 -1
- package/dist/rules/prefer-property-tests.d.ts +5 -0
- package/dist/rules/prefer-property-tests.js +7 -0
- package/dist/rules/require-jsdoc-on-exported.js +1 -1
- package/dist/shared/ancestors.d.ts +1 -1
- package/dist/shared/ancestors.js +1 -1
- package/dist/shared/values-path.d.ts +12 -0
- package/dist/shared/values-path.js +56 -0
- package/dist/testing/testable-rule.d.ts +6 -5
- package/dist/testing/testable-rule.js +20 -6
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.js +18 -0
- package/dist/ui/manifest.d.ts +49 -0
- package/dist/ui/manifest.js +90 -0
- package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
- package/dist/ui/rules/no-deprecated-parts.js +172 -0
- package/package.json +28 -19
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { firstOptionRecord } from "../../shared/rule-options.js";
|
|
3
|
+
import { decodeUiManifest, manifestAt, } from "../manifest.js";
|
|
4
|
+
/*
|
|
5
|
+
* A deprecated part is a promise, and an import is the place the promise is checked.
|
|
6
|
+
*
|
|
7
|
+
* Cutlist records `status: deprecated` and `useInstead` in the manifest; this rule reads
|
|
8
|
+
* that record and reports the call sites that have not migrated. It is the lint-shaped
|
|
9
|
+
* half of the same idea as a design system's "preferred instance": the catalog says what
|
|
10
|
+
* replaced the old thing, and the rule makes the old path visible instead of merely
|
|
11
|
+
* documented.
|
|
12
|
+
*
|
|
13
|
+
* The rule fails open. A missing or malformed manifest means no findings, because a lint
|
|
14
|
+
* rule that invents a migration from a file it could not read is worse than one that is
|
|
15
|
+
* briefly quiet; `cutlist build --check` is the gate that makes the manifest current.
|
|
16
|
+
*/
|
|
17
|
+
const RULE_ID = "plumb-ui/no-deprecated-parts";
|
|
18
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
19
|
+
const CACHE = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Whether a value is a plain object.
|
|
22
|
+
*
|
|
23
|
+
* @param {unknown} value - The value to test.
|
|
24
|
+
* @returns {boolean} True when the value is a non-null, non-array object.
|
|
25
|
+
*/
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decode a configured manifest, by inline value or by path.
|
|
31
|
+
*
|
|
32
|
+
* An inline manifest is what a rule test uses; a path is what a config uses. Both decode
|
|
33
|
+
* through the same reader, so a test cannot pass a shape the real rule rejects. A path is
|
|
34
|
+
* read once and remembered, because one program visits many files against one manifest.
|
|
35
|
+
*
|
|
36
|
+
* @param {unknown} value - The rule option: an inline manifest or a manifest path.
|
|
37
|
+
* @returns {UiManifest | undefined} The manifest, or `undefined` when it cannot be read.
|
|
38
|
+
*/
|
|
39
|
+
function manifestFrom(value) {
|
|
40
|
+
if (isRecord(value) && Array.isArray(value.components))
|
|
41
|
+
return decodeUiManifest(value);
|
|
42
|
+
if (typeof value !== "string")
|
|
43
|
+
return undefined;
|
|
44
|
+
if (!CACHE.has(value))
|
|
45
|
+
CACHE.set(value, manifestAt(value));
|
|
46
|
+
return CACHE.get(value);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A module path without its source extension or trailing `/index`.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} path - The manifest part path.
|
|
52
|
+
* @returns {string} The importable module path.
|
|
53
|
+
*/
|
|
54
|
+
function moduleOf(path) {
|
|
55
|
+
return path.replace(/\.(?:tsx?|jsx?)$/u, "").replace(/\/index$/u, "");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether an import specifier names a manifest part.
|
|
59
|
+
*
|
|
60
|
+
* The specifier is resolved by suffix rather than by the repository's alias table: the
|
|
61
|
+
* rule has no tsconfig reader, and every alias in use (`@/`, `~/`, relative) leaves the
|
|
62
|
+
* tail of the path intact. A named import must also match an exported name when the
|
|
63
|
+
* manifest carries one; a default or namespace import matches by path alone.
|
|
64
|
+
*
|
|
65
|
+
* @param {ImportRef} ref - The import's specifier and imported binding.
|
|
66
|
+
* @param {UiPart} part - The manifest part to test against.
|
|
67
|
+
* @returns {boolean} True when the import names the part.
|
|
68
|
+
*/
|
|
69
|
+
function namesPart(ref, part) {
|
|
70
|
+
const clean = ref.source.replace(/^[.@~]+/u, "").replace(/^\/+/u, "").replace(/\.(?:tsx?|jsx?)$/u, "");
|
|
71
|
+
const target = moduleOf(part.path);
|
|
72
|
+
const pathMatches = target === clean || target.endsWith("/" + clean);
|
|
73
|
+
if (ref.imported === "default" || ref.imported === "*")
|
|
74
|
+
return pathMatches;
|
|
75
|
+
return pathMatches || (part.exports?.includes(ref.imported) ?? false);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The imported binding name, or `*` for a namespace import.
|
|
79
|
+
*
|
|
80
|
+
* @param {ESTree.ImportDeclaration["specifiers"][number]} specifier - The import specifier.
|
|
81
|
+
* @returns {string} The imported name, `default`, or `*`.
|
|
82
|
+
*/
|
|
83
|
+
function importedOf(specifier) {
|
|
84
|
+
if (specifier.type === "ImportSpecifier") {
|
|
85
|
+
return specifier.imported.type === "Identifier"
|
|
86
|
+
? specifier.imported.name
|
|
87
|
+
: String(specifier.imported.value);
|
|
88
|
+
}
|
|
89
|
+
if (specifier.type === "ImportDefaultSpecifier")
|
|
90
|
+
return "default";
|
|
91
|
+
return "*";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The local binding name a specifier introduces.
|
|
95
|
+
*
|
|
96
|
+
* @param {ESTree.ImportDeclaration["specifiers"][number]} specifier - The import specifier.
|
|
97
|
+
* @returns {string} The name the file uses locally.
|
|
98
|
+
*/
|
|
99
|
+
function localOf(specifier) {
|
|
100
|
+
return specifier.local.name;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The deprecated part an import site reaches, if any.
|
|
104
|
+
*
|
|
105
|
+
* @param {UiManifest} manifest - The decoded manifest.
|
|
106
|
+
* @param {ImportRef} ref - The import's specifier and imported binding.
|
|
107
|
+
* @returns {UiPart | undefined} The deprecated part, or `undefined` when the import is clean.
|
|
108
|
+
*/
|
|
109
|
+
function deprecatedPartFor(manifest, ref) {
|
|
110
|
+
return manifest.components.find((part) => part.status === "deprecated" && namesPart(ref, part));
|
|
111
|
+
}
|
|
112
|
+
export const noDeprecatedPartsRule = defineRule({
|
|
113
|
+
meta: {
|
|
114
|
+
type: "problem",
|
|
115
|
+
docs: {
|
|
116
|
+
description: "Imports from a part whose catalog entry is deprecated must move to its recorded replacement.",
|
|
117
|
+
},
|
|
118
|
+
messages: {
|
|
119
|
+
deprecatedImport: "`{{name}}` comes from the deprecated part `{{part}}`; use {{useInstead}} instead.",
|
|
120
|
+
deprecatedWithoutTarget: "`{{name}}` comes from the deprecated part `{{part}}`, which records no replacement.",
|
|
121
|
+
},
|
|
122
|
+
schema: [
|
|
123
|
+
{
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
manifest: {
|
|
127
|
+
anyOf: [{ type: "string" }, { type: "object" }],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
defaultOptions: [{ manifest: "tools/ui-catalog/plumb-ui.config.json" }],
|
|
134
|
+
},
|
|
135
|
+
createOnce(context) {
|
|
136
|
+
const option = firstOptionRecord(context.options);
|
|
137
|
+
const manifest = manifestFrom(option.manifest);
|
|
138
|
+
if (manifest === undefined)
|
|
139
|
+
return {};
|
|
140
|
+
const deprecated = manifest.components.filter((part) => part.status === "deprecated");
|
|
141
|
+
if (deprecated.length === 0)
|
|
142
|
+
return {};
|
|
143
|
+
return {
|
|
144
|
+
before() {
|
|
145
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
146
|
+
return false;
|
|
147
|
+
},
|
|
148
|
+
ImportDeclaration(node) {
|
|
149
|
+
const source = node.source.value;
|
|
150
|
+
if (typeof source !== "string")
|
|
151
|
+
return;
|
|
152
|
+
for (const specifier of node.specifiers) {
|
|
153
|
+
const imported = importedOf(specifier);
|
|
154
|
+
const part = deprecatedPartFor(manifest, { source, imported });
|
|
155
|
+
if (part === undefined)
|
|
156
|
+
continue;
|
|
157
|
+
const useInstead = part.useInstead ?? [];
|
|
158
|
+
context.report({
|
|
159
|
+
node: specifier,
|
|
160
|
+
messageId: useInstead.length === 0 ? "deprecatedWithoutTarget" : "deprecatedImport",
|
|
161
|
+
data: {
|
|
162
|
+
name: localOf(specifier),
|
|
163
|
+
part: part.name,
|
|
164
|
+
useInstead: useInstead.map((name) => `\`${name}\``).join(" or "),
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
export { RULE_ID };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autotelic/plumb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Opinionated Oxlint rules that keep TypeScript true: generic and Effect-specific patterns, maintained as one source of truth for the autotelic repos.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/autotelic/tackle.git",
|
|
9
|
+
"directory": "packages/plumb"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"dist"
|
|
8
13
|
],
|
|
@@ -15,29 +20,33 @@
|
|
|
15
20
|
"./effect": "./dist/effect/index.js",
|
|
16
21
|
"./meta": "./dist/meta/index.js",
|
|
17
22
|
"./testing": "./dist/testing/index.js",
|
|
18
|
-
"./react": "./dist/react/index.js"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm check:rule-tests && pnpm check:config",
|
|
22
|
-
"build": "tsc -p tsconfig.build.json",
|
|
23
|
-
"lint": "oxlint src",
|
|
24
|
-
"typecheck": "tsc --noEmit",
|
|
25
|
-
"test": "vitest run --passWithNoTests",
|
|
26
|
-
"check:rule-tests": "node scripts/check-rule-tests.mjs",
|
|
27
|
-
"check:config": "node scripts/check-config.mjs"
|
|
23
|
+
"./react": "./dist/react/index.js",
|
|
24
|
+
"./ui": "./dist/ui/index.js",
|
|
25
|
+
"./configs": "./dist/configs/recommended-rules.js"
|
|
28
26
|
},
|
|
29
27
|
"dependencies": {
|
|
30
|
-
"@oxlint/plugins": "1.
|
|
28
|
+
"@oxlint/plugins": "1.89.0"
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
|
-
"@types/node": "24.13.
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
31
|
+
"@types/node": "24.13.5",
|
|
32
|
+
"@typescript-eslint/parser": "^8.71.0",
|
|
33
|
+
"eslint": "^10.11.0",
|
|
34
|
+
"fast-check": "4.10.2",
|
|
35
|
+
"oxlint": "1.89.0",
|
|
36
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
37
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
38
|
+
"vitest": "5.0.1"
|
|
38
39
|
},
|
|
39
40
|
"engines": {
|
|
40
41
|
"node": ">=20"
|
|
41
42
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
43
|
+
"scripts": {
|
|
44
|
+
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm check:rule-tests && pnpm check:config",
|
|
45
|
+
"build": "tsc -p tsconfig.build.json",
|
|
46
|
+
"lint": "oxlint src",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"test": "vitest run --passWithNoTests",
|
|
49
|
+
"check:rule-tests": "node scripts/check-rule-tests.mjs --strict",
|
|
50
|
+
"check:config": "node scripts/check-config.mjs"
|
|
51
|
+
}
|
|
52
|
+
}
|