@hailstails/hone 0.0.0-stage → 0.1.0-pre.3
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/ADOPTING.md +314 -0
- package/LICENSE +17 -0
- package/MIGRATING.md +238 -0
- package/README.md +219 -2
- package/THIRD-PARTY-NOTICES.md +354 -0
- package/chunks/chunk-233U4FBA.js +42 -0
- package/chunks/chunk-7ZJZZBSS.js +14909 -0
- package/chunks/chunk-HBY4ZWSP.js +79 -0
- package/chunks/chunk-HJA4CX7C.js +24 -0
- package/chunks/chunk-NZLE2WMY.js +35 -0
- package/chunks/chunk-QWA6OVLC.js +11 -0
- package/chunks/chunk-TRCB27ET.js +202 -0
- package/core/check/tool-command.js +2305 -0
- package/docs/adding-a-discipline-or-mechanism.md +195 -0
- package/docs/why-chain-contract.md +78 -0
- package/mechanisms/audit/CD-1/any-cast.js +81 -0
- package/mechanisms/audit/CD-1/piece.json +13 -0
- package/mechanisms/audit/CD-10/piece.json +13 -0
- package/mechanisms/audit/CD-10/throws-in-tests.js +49 -0
- package/mechanisms/audit/CD-14/class-syntax.js +70 -0
- package/mechanisms/audit/CD-14/piece.json +13 -0
- package/mechanisms/audit/CD-15/loops.js +40 -0
- package/mechanisms/audit/CD-15/piece.json +13 -0
- package/mechanisms/audit/CD-17/clock-sources.js +29 -0
- package/mechanisms/audit/CD-17/piece.json +13 -0
- package/mechanisms/audit/CD-19/import-boundaries.js +80 -0
- package/mechanisms/audit/CD-19/piece.json +13 -0
- package/mechanisms/audit/CD-2/cast-expressions.js +81 -0
- package/mechanisms/audit/CD-2/piece.json +13 -0
- package/mechanisms/audit/CD-23/export-test-sibling.js +56 -0
- package/mechanisms/audit/CD-23/piece.json +13 -0
- package/mechanisms/audit/CD-25/dependency-isolation.js +53 -0
- package/mechanisms/audit/CD-25/piece.json +13 -0
- package/mechanisms/audit/CD-26/module-mocking.js +51 -0
- package/mechanisms/audit/CD-26/piece.json +13 -0
- package/mechanisms/audit/CD-27/piece.json +13 -0
- package/mechanisms/audit/CD-27/test-body-logic.js +107 -0
- package/mechanisms/audit/CD-3/compiler-overrides.js +955 -0
- package/mechanisms/audit/CD-3/piece.json +49 -0
- package/mechanisms/audit/CD-43/boolean-signatures.js +55 -0
- package/mechanisms/audit/CD-43/piece.json +13 -0
- package/mechanisms/audit/CD-44/parameter-mutation.js +92 -0
- package/mechanisms/audit/CD-44/piece.json +13 -0
- package/mechanisms/audit/CD-47/hermetic-git-spawns.js +44 -0
- package/mechanisms/audit/CD-47/piece.json +13 -0
- package/mechanisms/audit/CD-5/comments-directives.js +73 -0
- package/mechanisms/audit/CD-5/piece.json +13 -0
- package/mechanisms/audit/CD-6/identifier-names.js +132 -0
- package/mechanisms/audit/CD-6/piece.json +13 -0
- package/mechanisms/audit/CD-7/categorical-paths.js +55 -0
- package/mechanisms/audit/CD-7/piece.json +13 -0
- package/mechanisms/audit/CD-7a/factory-return-types.js +42 -0
- package/mechanisms/audit/CD-7a/piece.json +13 -0
- package/mechanisms/audit/CD-8/piece.json +13 -0
- package/mechanisms/audit/CD-8/switch-defaults.js +43 -0
- package/mechanisms/audit/runner/README.md +38 -0
- package/mechanisms/audit/runner/runner.js +546 -0
- package/mechanisms/eslint/CD-1/README.md +12 -0
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +50 -0
- package/mechanisms/eslint/CD-1/piece.json +23 -0
- package/mechanisms/eslint/CD-10/README.md +9 -0
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +55 -0
- package/mechanisms/eslint/CD-10/piece.json +15 -0
- package/mechanisms/eslint/CD-14/README.md +11 -0
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +88 -0
- package/mechanisms/eslint/CD-14/piece.json +31 -0
- package/mechanisms/eslint/CD-27/README.md +12 -0
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +83 -0
- package/mechanisms/eslint/CD-27/piece.json +23 -0
- package/mechanisms/eslint/CD-40/README.md +7 -0
- package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-40/piece.json +21 -0
- package/mechanisms/eslint/CD-41/README.md +12 -0
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +228 -0
- package/mechanisms/eslint/CD-41/piece.json +23 -0
- package/mechanisms/eslint/CD-42/README.md +9 -0
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +75 -0
- package/mechanisms/eslint/CD-42/piece.json +15 -0
- package/mechanisms/eslint/CD-44/README.md +7 -0
- package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-44/piece.json +20 -0
- package/mechanisms/eslint/CD-6/README.md +9 -0
- package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +16 -0
- package/mechanisms/eslint/CD-6/piece.json +217 -0
- package/mechanisms/eslint/CD-7/README.md +9 -0
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +52 -0
- package/mechanisms/eslint/CD-7/piece.json +15 -0
- package/mechanisms/eslint/runner/README.md +43 -0
- package/mechanisms/eslint/runner/runner.js +4248 -0
- package/methods/README.md +18 -0
- package/methods/lenses/clean-architecture.md +167 -0
- package/methods/lenses/decomposition.md +159 -0
- package/methods/lenses/defended-on-intent.md +178 -0
- package/methods/lenses/di-discipline.md +156 -0
- package/methods/lenses/errors-as-data.md +88 -0
- package/methods/lenses/function-first.md +193 -0
- package/methods/lenses/naming.md +127 -0
- package/methods/lenses/test-discipline.md +166 -0
- package/methods/lenses/type-soundness.md +135 -0
- package/methods/lenses/zod-boundary.md +158 -0
- package/package.json +65 -4
- package/rules/CD-1/README.md +43 -0
- package/rules/CD-1/discipline.json +185 -0
- package/rules/CD-10/README.md +55 -0
- package/rules/CD-10/discipline.json +133 -0
- package/rules/CD-11/README.md +19 -0
- package/rules/CD-11/discipline.json +12 -0
- package/rules/CD-12/README.md +19 -0
- package/rules/CD-12/discipline.json +12 -0
- package/rules/CD-13/README.md +19 -0
- package/rules/CD-13/discipline.json +12 -0
- package/rules/CD-14/README.md +54 -0
- package/rules/CD-14/discipline.json +173 -0
- package/rules/CD-15/README.md +48 -0
- package/rules/CD-15/discipline.json +73 -0
- package/rules/CD-16/README.md +17 -0
- package/rules/CD-17/README.md +42 -0
- package/rules/CD-17/discipline.json +51 -0
- package/rules/CD-18/README.md +19 -0
- package/rules/CD-18/discipline.json +12 -0
- package/rules/CD-19/README.md +45 -0
- package/rules/CD-19/discipline.json +65 -0
- package/rules/CD-2/README.md +43 -0
- package/rules/CD-2/discipline.json +65 -0
- package/rules/CD-20/README.md +17 -0
- package/rules/CD-21/README.md +19 -0
- package/rules/CD-21/discipline.json +12 -0
- package/rules/CD-22/README.md +19 -0
- package/rules/CD-22/discipline.json +12 -0
- package/rules/CD-23/README.md +41 -0
- package/rules/CD-23/discipline.json +57 -0
- package/rules/CD-24/README.md +17 -0
- package/rules/CD-25/README.md +43 -0
- package/rules/CD-25/discipline.json +57 -0
- package/rules/CD-26/README.md +42 -0
- package/rules/CD-26/discipline.json +57 -0
- package/rules/CD-27/README.md +51 -0
- package/rules/CD-27/discipline.json +233 -0
- package/rules/CD-28/README.md +19 -0
- package/rules/CD-28/discipline.json +12 -0
- package/rules/CD-29/README.md +19 -0
- package/rules/CD-29/discipline.json +12 -0
- package/rules/CD-3/README.md +48 -0
- package/rules/CD-3/discipline.json +363 -0
- package/rules/CD-30/README.md +19 -0
- package/rules/CD-30/discipline.json +12 -0
- package/rules/CD-31/README.md +19 -0
- package/rules/CD-31/discipline.json +12 -0
- package/rules/CD-32/README.md +19 -0
- package/rules/CD-32/discipline.json +12 -0
- package/rules/CD-33/README.md +19 -0
- package/rules/CD-33/discipline.json +12 -0
- package/rules/CD-34/README.md +19 -0
- package/rules/CD-34/discipline.json +12 -0
- package/rules/CD-39/README.md +19 -0
- package/rules/CD-39/discipline.json +12 -0
- package/rules/CD-4/README.md +19 -0
- package/rules/CD-4/discipline.json +12 -0
- package/rules/CD-40/README.md +45 -0
- package/rules/CD-40/discipline.json +58 -0
- package/rules/CD-41/README.md +60 -0
- package/rules/CD-41/discipline.json +124 -0
- package/rules/CD-42/README.md +53 -0
- package/rules/CD-42/discipline.json +61 -0
- package/rules/CD-43/README.md +43 -0
- package/rules/CD-43/discipline.json +65 -0
- package/rules/CD-44/README.md +54 -0
- package/rules/CD-44/discipline.json +111 -0
- package/rules/CD-45/README.md +19 -0
- package/rules/CD-45/discipline.json +12 -0
- package/rules/CD-46/README.md +13 -0
- package/rules/CD-47/README.md +47 -0
- package/rules/CD-47/discipline.json +57 -0
- package/rules/CD-5/README.md +46 -0
- package/rules/CD-5/discipline.json +65 -0
- package/rules/CD-6/README.md +57 -0
- package/rules/CD-6/discipline.json +165 -0
- package/rules/CD-7/README.md +52 -0
- package/rules/CD-7/discipline.json +142 -0
- package/rules/CD-7a/README.md +44 -0
- package/rules/CD-7a/discipline.json +57 -0
- package/rules/CD-8/README.md +48 -0
- package/rules/CD-8/discipline.json +57 -0
- package/rules/CD-9/README.md +19 -0
- package/rules/CD-9/discipline.json +12 -0
- package/rules/README.md +52 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultNativeRuleSources,
|
|
3
|
+
typescriptEslintRules
|
|
4
|
+
} from "../../../../chunks/chunk-HJA4CX7C.js";
|
|
5
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
6
|
+
|
|
7
|
+
// mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.ts
|
|
8
|
+
var DECLARATION_FILE = /\.d\.[cm]?ts$/u;
|
|
9
|
+
var TYPESCRIPT_FILE = /\.[cm]?tsx?$/u;
|
|
10
|
+
var LOOP_HEADS = /* @__PURE__ */ new Set(["ForInStatement", "ForOfStatement"]);
|
|
11
|
+
var bindingDisposition = (request) => (request.binding.init ?? null) === null && !("typeAnnotation" in request.binding.id && request.binding.id.typeAnnotation) ? "implicit-any" : "typed-or-initialised";
|
|
12
|
+
var governedFile = (request) => TYPESCRIPT_FILE.test(request.filename) && !DECLARATION_FILE.test(request.filename) ? "governed" : "not-governed";
|
|
13
|
+
var loopHeadDisposition = (request) => request.node.parent !== null && LOOP_HEADS.has(request.node.parent.type) ? "loop-head" : "statement";
|
|
14
|
+
var implicitAnyLet = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: "problem",
|
|
17
|
+
docs: { description: "Disallow let and var declarations with neither a type nor an initialiser (CD-1)" },
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
implicitAny: "CD-1: give this variable a type annotation or an initialiser so it is not implicitly any."
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
create: (context) => ({
|
|
24
|
+
VariableDeclaration: (node) => {
|
|
25
|
+
if (node.kind === "const" || governedFile({ filename: context.filename }) === "not-governed") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (loopHeadDisposition({ node }) === "loop-head") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const implicit = node.declarations.find((binding) => bindingDisposition({ binding }) === "implicit-any");
|
|
32
|
+
if (implicit === void 0 || implicit.id.type !== "Identifier") {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
context.report({ node: implicit.id, messageId: "implicitAny" });
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
var createPlugin = (sources) => ({
|
|
40
|
+
meta: { name: "hone-cd1", version: "0.0.0-local" },
|
|
41
|
+
rules: {
|
|
42
|
+
...typescriptEslintRules({ names: ["no-explicit-any"], sources }),
|
|
43
|
+
"implicit-any-let": implicitAnyLet
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
var cd1_eslint_plugin_default = createPlugin(defaultNativeRuleSources);
|
|
47
|
+
export {
|
|
48
|
+
createPlugin,
|
|
49
|
+
cd1_eslint_plugin_default as default
|
|
50
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-1",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "explicit-any",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone-cd1",
|
|
10
|
+
"pluginModule": "cd1/cd1.eslint-plugin.js",
|
|
11
|
+
"rule": "no-explicit-any"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"clause": "implicit-any-let",
|
|
16
|
+
"settings": {
|
|
17
|
+
"pluginNamespace": "hone-cd1",
|
|
18
|
+
"pluginModule": "cd1/cd1.eslint-plugin.js",
|
|
19
|
+
"rule": "implicit-any-let"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# CD-10 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-10's `throw-only-error` clause through ESLint. It is one rule, `throw-only-error`, in the plugin `cd10/cd10.eslint-plugin.ts` under the namespace `hone-cd10`. The rule reports a `throw` of a literal, object literal, binary expression, template or `undefined`, and allows `new Error(...)`, identifiers, calls and member access.
|
|
4
|
+
|
|
5
|
+
`piece.json` names the clause, the namespace, the plugin module and the rule. It is the only file core reads to find the rule.
|
|
6
|
+
|
|
7
|
+
## Adopting the rule
|
|
8
|
+
|
|
9
|
+
The projection is the only supported way to adopt the rule. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling the rule some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
2
|
+
|
|
3
|
+
// mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.ts
|
|
4
|
+
var NON_ERROR_EXPRESSIONS = /* @__PURE__ */ new Set([
|
|
5
|
+
"Literal",
|
|
6
|
+
"ObjectExpression",
|
|
7
|
+
"BinaryExpression",
|
|
8
|
+
"TemplateLiteral",
|
|
9
|
+
"TaggedTemplateExpression"
|
|
10
|
+
]);
|
|
11
|
+
var eitherNonError = (request) => thrownDisposition({ expression: request.first }) === "non-error" || thrownDisposition({ expression: request.second }) === "non-error" ? "non-error" : "possibly-error";
|
|
12
|
+
var COMPOSITE_DISPOSITIONS = {
|
|
13
|
+
LogicalExpression: (expression) => eitherNonError({ first: expression.left, second: expression.right }),
|
|
14
|
+
ConditionalExpression: (expression) => eitherNonError({ first: expression.consequent, second: expression.alternate }),
|
|
15
|
+
AssignmentExpression: (expression) => thrownDisposition({ expression: expression.right }),
|
|
16
|
+
SequenceExpression: (expression) => thrownDisposition({ expression: expression.expressions?.at(-1) })
|
|
17
|
+
};
|
|
18
|
+
var thrownDisposition = (request) => {
|
|
19
|
+
if (request.expression === void 0) {
|
|
20
|
+
return "possibly-error";
|
|
21
|
+
}
|
|
22
|
+
if (NON_ERROR_EXPRESSIONS.has(request.expression.type)) {
|
|
23
|
+
return "non-error";
|
|
24
|
+
}
|
|
25
|
+
if (request.expression.type === "Identifier") {
|
|
26
|
+
return request.expression.name === "undefined" ? "non-error" : "possibly-error";
|
|
27
|
+
}
|
|
28
|
+
const composite = COMPOSITE_DISPOSITIONS[request.expression.type];
|
|
29
|
+
return composite === void 0 ? "possibly-error" : composite(request.expression);
|
|
30
|
+
};
|
|
31
|
+
var throwOnlyError = {
|
|
32
|
+
meta: {
|
|
33
|
+
type: "problem",
|
|
34
|
+
docs: { description: "Disallow throwing values that cannot be Error objects (CD-10)" },
|
|
35
|
+
schema: [],
|
|
36
|
+
messages: {
|
|
37
|
+
throwOnlyError: "CD-10: throw an Error, not a literal, object, template or undefined."
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
create: (context) => ({
|
|
41
|
+
ThrowStatement: (node) => {
|
|
42
|
+
if (thrownDisposition({ expression: node.argument }) === "possibly-error") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
context.report({ node, messageId: "throwOnlyError" });
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
var cd10_eslint_plugin_default = {
|
|
50
|
+
meta: { name: "hone-cd10", version: "0.0.0-local" },
|
|
51
|
+
rules: { "throw-only-error": throwOnlyError }
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
cd10_eslint_plugin_default as default
|
|
55
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-10",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "throw-only-error",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone-cd10",
|
|
10
|
+
"pluginModule": "cd10/cd10.eslint-plugin.js",
|
|
11
|
+
"rule": "throw-only-error"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# CD-14 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-14's `class-syntax` and `static-only-class` clauses through ESLint, in the plugin `cd14/cd14.eslint-plugin.ts` under the namespace `hone`. `class-syntax` is the rule `no-class-authoring`. It reports every class declaration and class expression that is not ambient, at its `class` keyword, so it flags the same lines as the audit piece for CD-14. A class with a `declare` modifier, a class inside a `declare` module, namespace or `global` block, and any class in a declaration file are allowed.
|
|
4
|
+
|
|
5
|
+
`static-only-class` is the rule `no-extraneous-class`, which re-exports typescript-eslint's rule with `allowConstructorOnly`, `allowEmpty` and `allowWithDecorator` true and `allowStaticOnly` false. It reports a class whose members are all static.
|
|
6
|
+
|
|
7
|
+
`piece.json` names each clause, the namespace, the plugin module, the rule and any `options`. It is the only file core reads to find the rules.
|
|
8
|
+
|
|
9
|
+
## Adopting the rule
|
|
10
|
+
|
|
11
|
+
The projection is the only supported way to adopt this rule. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling the rule some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultNativeRuleSources,
|
|
3
|
+
typescriptEslintRules
|
|
4
|
+
} from "../../../../chunks/chunk-HJA4CX7C.js";
|
|
5
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
6
|
+
|
|
7
|
+
// mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.ts
|
|
8
|
+
var classDisposition = (syntax) => {
|
|
9
|
+
if (syntax.kind === "expression") return "report";
|
|
10
|
+
if (/\.d\.[cm]?ts$/u.test(syntax.filename)) return "allow";
|
|
11
|
+
if (syntax.declaration === "ambient") return "allow";
|
|
12
|
+
if (syntax.container === "ambient") return "allow";
|
|
13
|
+
return "report";
|
|
14
|
+
};
|
|
15
|
+
var declarationMode = ({
|
|
16
|
+
node
|
|
17
|
+
}) => "declare" in node && node.declare === true ? "ambient" : "runtime";
|
|
18
|
+
var containerMode = ({
|
|
19
|
+
node
|
|
20
|
+
}) => {
|
|
21
|
+
if (node === void 0 || node === null) return "runtime";
|
|
22
|
+
if (node.type === "TSModuleDeclaration" && declarationMode({ node }) === "ambient")
|
|
23
|
+
return "ambient";
|
|
24
|
+
return containerMode({ node: node.parent });
|
|
25
|
+
};
|
|
26
|
+
var classKeywordToken = ({
|
|
27
|
+
context,
|
|
28
|
+
node
|
|
29
|
+
}) => context.sourceCode.getFirstToken(node, {
|
|
30
|
+
filter: (token) => token.type === "Keyword" && token.value === "class" && context.sourceCode.getNodeByRangeIndex(token.range[0]) === node
|
|
31
|
+
});
|
|
32
|
+
var reportAtClassKeyword = ({
|
|
33
|
+
context,
|
|
34
|
+
node
|
|
35
|
+
}) => {
|
|
36
|
+
const keyword = classKeywordToken({ context, node });
|
|
37
|
+
if (keyword === null) {
|
|
38
|
+
context.report({ node, messageId: "noClass" });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
context.report({ loc: keyword.loc, messageId: "noClass" });
|
|
42
|
+
};
|
|
43
|
+
var noClassAuthoring = {
|
|
44
|
+
meta: {
|
|
45
|
+
type: "problem",
|
|
46
|
+
docs: { description: "Disallow authored runtime classes (CD-14)" },
|
|
47
|
+
schema: [],
|
|
48
|
+
messages: {
|
|
49
|
+
noClass: "CD-14: use functions and closure-backed factories instead of authoring a class."
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
create(context) {
|
|
53
|
+
const reportClass = ({
|
|
54
|
+
node,
|
|
55
|
+
kind
|
|
56
|
+
}) => {
|
|
57
|
+
const disposition = classDisposition({
|
|
58
|
+
filename: context.filename,
|
|
59
|
+
kind,
|
|
60
|
+
declaration: declarationMode({ node }),
|
|
61
|
+
container: containerMode({ node: node.parent })
|
|
62
|
+
});
|
|
63
|
+
if (disposition === "allow") return;
|
|
64
|
+
reportAtClassKeyword({ context, node });
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
ClassDeclaration: (node) => reportClass({ node, kind: "declaration" }),
|
|
68
|
+
ClassExpression: (node) => reportClass({ node, kind: "expression" })
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var eslintPlugin = (plugin) => plugin;
|
|
73
|
+
var createPlugin = (sources) => eslintPlugin({
|
|
74
|
+
meta: { name: "hone", version: "0.0.0-local" },
|
|
75
|
+
rules: {
|
|
76
|
+
"no-class-authoring": noClassAuthoring,
|
|
77
|
+
...typescriptEslintRules({ names: ["no-extraneous-class"], sources })
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
var classAuthoringPlugin = createPlugin(defaultNativeRuleSources);
|
|
81
|
+
var cd14_eslint_plugin_default = classAuthoringPlugin;
|
|
82
|
+
export {
|
|
83
|
+
classAuthoringPlugin,
|
|
84
|
+
classDisposition,
|
|
85
|
+
containerMode,
|
|
86
|
+
createPlugin,
|
|
87
|
+
cd14_eslint_plugin_default as default
|
|
88
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-14",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "class-syntax",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone",
|
|
10
|
+
"pluginModule": "cd14/cd14.eslint-plugin.js",
|
|
11
|
+
"rule": "no-class-authoring"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"clause": "static-only-class",
|
|
16
|
+
"settings": {
|
|
17
|
+
"pluginNamespace": "hone",
|
|
18
|
+
"pluginModule": "cd14/cd14.eslint-plugin.js",
|
|
19
|
+
"rule": "no-extraneous-class",
|
|
20
|
+
"options": [
|
|
21
|
+
{
|
|
22
|
+
"allowConstructorOnly": true,
|
|
23
|
+
"allowEmpty": true,
|
|
24
|
+
"allowStaticOnly": false,
|
|
25
|
+
"allowWithDecorator": true
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# CD-27 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-27's `focused-tests` and `skipped-tests` clauses through ESLint, in the plugin `cd27/cd27.eslint-plugin.ts` under the namespace `hone-cd27`.
|
|
4
|
+
|
|
5
|
+
- `focused-tests` reports `.only` and the bare `fdescribe`, `fit`, `ftest` and `fsuite`, at the `only` token.
|
|
6
|
+
- `skipped-tests` reports `.skip`, `.fixme` and the bare `xdescribe`, `xit`, `xtest` and `xsuite`.
|
|
7
|
+
|
|
8
|
+
`piece.json` names each clause, the namespace, the plugin module and the rule. It is the only file core reads to find the rules.
|
|
9
|
+
|
|
10
|
+
## Adopting the rule
|
|
11
|
+
|
|
12
|
+
The projection is the only supported way to adopt these rules. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling these rules some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
2
|
+
|
|
3
|
+
// mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.ts
|
|
4
|
+
var TEST_ROOTS = /* @__PURE__ */ new Set(["describe", "it", "test", "suite"]);
|
|
5
|
+
var FOCUSED = {
|
|
6
|
+
bareNames: /* @__PURE__ */ new Set(["fdescribe", "fit", "ftest", "fsuite"]),
|
|
7
|
+
roots: TEST_ROOTS,
|
|
8
|
+
members: /* @__PURE__ */ new Set(["only"])
|
|
9
|
+
};
|
|
10
|
+
var SKIPPED = {
|
|
11
|
+
bareNames: /* @__PURE__ */ new Set(["xdescribe", "xit", "xtest", "xsuite"]),
|
|
12
|
+
roots: TEST_ROOTS,
|
|
13
|
+
members: /* @__PURE__ */ new Set(["skip", "fixme"])
|
|
14
|
+
};
|
|
15
|
+
var memberName = (request) => {
|
|
16
|
+
if (request.property?.type === "Identifier") {
|
|
17
|
+
return request.property.name;
|
|
18
|
+
}
|
|
19
|
+
return typeof request.property?.value === "string" ? request.property.value : void 0;
|
|
20
|
+
};
|
|
21
|
+
var calleeChainOf = (request) => {
|
|
22
|
+
if (request.callee.type === "Identifier" && request.callee.name !== void 0) {
|
|
23
|
+
return { root: { name: request.callee.name, node: request.callee }, members: request.members };
|
|
24
|
+
}
|
|
25
|
+
if (request.callee.type !== "MemberExpression" || request.callee.object === void 0) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
const name = memberName({ property: request.callee.property });
|
|
29
|
+
if (name === void 0 || request.callee.property === void 0) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
return calleeChainOf({
|
|
33
|
+
callee: request.callee.object,
|
|
34
|
+
members: [{ name, node: request.callee.property }, ...request.members]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var modifiedLink = (request) => {
|
|
38
|
+
const chain = calleeChainOf({ callee: request.callee, members: [] });
|
|
39
|
+
if (chain === void 0) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
if (chain.members.length === 0) {
|
|
43
|
+
return request.modifier.bareNames.has(chain.root.name) ? chain.root : void 0;
|
|
44
|
+
}
|
|
45
|
+
const links = [chain.root, ...chain.members];
|
|
46
|
+
const testFunction = links.findIndex((link) => request.modifier.roots.has(link.name));
|
|
47
|
+
return testFunction === -1 ? void 0 : links.slice(testFunction + 1).find((link) => request.modifier.members.has(link.name));
|
|
48
|
+
};
|
|
49
|
+
var modifierRule = (request) => ({
|
|
50
|
+
meta: {
|
|
51
|
+
type: "problem",
|
|
52
|
+
docs: { description: request.description },
|
|
53
|
+
schema: [],
|
|
54
|
+
messages: { modifiedTest: request.message }
|
|
55
|
+
},
|
|
56
|
+
create: (context) => ({
|
|
57
|
+
CallExpression: (node) => {
|
|
58
|
+
const loc = modifiedLink({ callee: node.callee, modifier: request.modifier })?.node.loc;
|
|
59
|
+
if (loc === void 0 || loc === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
context.report({ loc, messageId: "modifiedTest" });
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
var cd27_eslint_plugin_default = {
|
|
67
|
+
meta: { name: "hone-cd27", version: "0.0.0-local" },
|
|
68
|
+
rules: {
|
|
69
|
+
"focused-tests": modifierRule({
|
|
70
|
+
modifier: FOCUSED,
|
|
71
|
+
description: "Disallow focused tests (CD-27)",
|
|
72
|
+
message: "CD-27: remove the focus so every test runs."
|
|
73
|
+
}),
|
|
74
|
+
"skipped-tests": modifierRule({
|
|
75
|
+
modifier: SKIPPED,
|
|
76
|
+
description: "Disallow skipped tests (CD-27)",
|
|
77
|
+
message: "CD-27: remove the skip so the test runs, or delete the test."
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
cd27_eslint_plugin_default as default
|
|
83
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-27",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "focused-tests",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone-cd27",
|
|
10
|
+
"pluginModule": "cd27/cd27.eslint-plugin.js",
|
|
11
|
+
"rule": "focused-tests"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"clause": "skipped-tests",
|
|
16
|
+
"settings": {
|
|
17
|
+
"pluginNamespace": "hone-cd27",
|
|
18
|
+
"pluginModule": "cd27/cd27.eslint-plugin.js",
|
|
19
|
+
"rule": "skipped-tests"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# CD-40 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-40's `parameter-count` clause through ESLint. It is one rule, `max-params`, in the plugin `cd40/cd40.eslint-plugin.ts` under the namespace `hone-cd40`. It reuses typescript-eslint's `max-params` with the `options` `{ "max": 2, "countVoidThis": true }` carried in `piece.json`, so a function with more than two parameters is reported and a `this` parameter counts.
|
|
4
|
+
|
|
5
|
+
## Adopting the rule
|
|
6
|
+
|
|
7
|
+
The projection is the only supported way to adopt the rule. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling the rule some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultNativeRuleSources,
|
|
3
|
+
typescriptEslintRules
|
|
4
|
+
} from "../../../../chunks/chunk-HJA4CX7C.js";
|
|
5
|
+
import "../../../../chunks/chunk-NZLE2WMY.js";
|
|
6
|
+
|
|
7
|
+
// mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.ts
|
|
8
|
+
var createPlugin = (sources) => ({
|
|
9
|
+
meta: { name: "hone-cd40", version: "0.0.0-local" },
|
|
10
|
+
rules: typescriptEslintRules({ names: ["max-params"], sources })
|
|
11
|
+
});
|
|
12
|
+
var cd40_eslint_plugin_default = createPlugin(defaultNativeRuleSources);
|
|
13
|
+
export {
|
|
14
|
+
createPlugin,
|
|
15
|
+
cd40_eslint_plugin_default as default
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"discipline": "CD-40",
|
|
4
|
+
"mechanism": "eslint",
|
|
5
|
+
"clauses": [
|
|
6
|
+
{
|
|
7
|
+
"clause": "parameter-count",
|
|
8
|
+
"settings": {
|
|
9
|
+
"pluginNamespace": "hone-cd40",
|
|
10
|
+
"pluginModule": "cd40/cd40.eslint-plugin.js",
|
|
11
|
+
"rule": "max-params",
|
|
12
|
+
"options": [
|
|
13
|
+
{
|
|
14
|
+
"max": 2,
|
|
15
|
+
"countVoidThis": true
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# CD-41 ESLint piece
|
|
2
|
+
|
|
3
|
+
This piece enforces CD-41's `cognitive-complexity` and `function-length` clauses through ESLint, in the plugin `cd41/cd41.eslint-plugin.ts` under the namespace `hone-cd41`.
|
|
4
|
+
|
|
5
|
+
- `cognitive-complexity` reports a function whose cognitive complexity is above 15, at the function's name.
|
|
6
|
+
- `function-length` reports a function whose body spans more than 50 lines, at the function.
|
|
7
|
+
|
|
8
|
+
`piece.json` names each clause, the namespace, the plugin module and the rule. It is the only file core reads to find the rules.
|
|
9
|
+
|
|
10
|
+
## Adopting the rule
|
|
11
|
+
|
|
12
|
+
The projection is the only supported way to adopt these rules. Run core's project command for your repository; it writes `disciplines.eslint.mjs` at the repository root, which enables every selected rule and carries your recorded exceptions. Spread its default export last in your flat config. Core's governance run checks that the projection's effect is in force, so enabling these rules some other way is not supported and fails the run as `not-included` once any exception is recorded for it.
|