@shivaedev/quality 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +45 -1
- package/biome/declarations.json +5 -0
- package/biome/plugins/ambient-runtime.grit +3 -1
- package/biome/preset.json +2 -2
- package/dist/rules/builtIn.d.ts +1 -1
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +6 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/effect/boundary.d.ts +2 -0
- package/dist/rules/effect/boundary.d.ts.map +1 -0
- package/dist/rules/effect/boundary.js +66 -0
- package/dist/rules/effect/boundary.js.map +1 -0
- package/dist/rules/effect/layerConstructor.d.ts +3 -0
- package/dist/rules/effect/layerConstructor.d.ts.map +1 -0
- package/dist/rules/effect/layerConstructor.js +35 -0
- package/dist/rules/effect/layerConstructor.js.map +1 -0
- package/dist/rules/effect/ownsParameters.d.ts +3 -0
- package/dist/rules/effect/ownsParameters.d.ts.map +1 -0
- package/dist/rules/effect/ownsParameters.js +45 -0
- package/dist/rules/effect/ownsParameters.js.map +1 -0
- package/dist/rules/effect/program.d.ts +4 -0
- package/dist/rules/effect/program.d.ts.map +1 -0
- package/dist/rules/effect/program.js +24 -0
- package/dist/rules/effect/program.js.map +1 -0
- package/dist/rules/effect/publicFunctions.d.ts +3 -0
- package/dist/rules/effect/publicFunctions.d.ts.map +1 -0
- package/dist/rules/effect/publicFunctions.js +68 -0
- package/dist/rules/effect/publicFunctions.js.map +1 -0
- package/dist/rules/effect/serviceCatalog.d.ts +8 -0
- package/dist/rules/effect/serviceCatalog.d.ts.map +1 -0
- package/dist/rules/effect/serviceCatalog.js +56 -0
- package/dist/rules/effect/serviceCatalog.js.map +1 -0
- package/dist/rules/effect/serviceFindings.d.ts +5 -0
- package/dist/rules/effect/serviceFindings.d.ts.map +1 -0
- package/dist/rules/effect/serviceFindings.js +88 -0
- package/dist/rules/effect/serviceFindings.js.map +1 -0
- package/dist/rules/effect/serviceOrigin.d.ts +3 -0
- package/dist/rules/effect/serviceOrigin.d.ts.map +1 -0
- package/dist/rules/effect/serviceOrigin.js +85 -0
- package/dist/rules/effect/serviceOrigin.js.map +1 -0
- package/dist/rules/effect/serviceParameters.d.ts +2 -0
- package/dist/rules/effect/serviceParameters.d.ts.map +1 -0
- package/dist/rules/effect/serviceParameters.js +33 -0
- package/dist/rules/effect/serviceParameters.js.map +1 -0
- package/dist/rules/effect/serviceTypes.d.ts +8 -0
- package/dist/rules/effect/serviceTypes.d.ts.map +1 -0
- package/dist/rules/effect/serviceTypes.js +94 -0
- package/dist/rules/effect/serviceTypes.js.map +1 -0
- package/dist/rules/react/jsxConditionals.d.ts +2 -0
- package/dist/rules/react/jsxConditionals.d.ts.map +1 -0
- package/dist/rules/react/jsxConditionals.js +54 -0
- package/dist/rules/react/jsxConditionals.js.map +1 -0
- package/dist/rules/stories/engineOf.d.ts.map +1 -1
- package/dist/rules/stories/engineOf.js +2 -1
- package/dist/rules/stories/engineOf.js.map +1 -1
- package/dist/rules/stories/namedValues.js +4 -4
- package/dist/rules/stories/namedValues.js.map +1 -1
- package/package.json +3 -3
- package/src/rules/builtIn.ts +6 -0
- package/src/rules/effect/boundary.ts +75 -0
- package/src/rules/effect/layerConstructor.ts +40 -0
- package/src/rules/effect/ownsParameters.ts +46 -0
- package/src/rules/effect/program.ts +26 -0
- package/src/rules/effect/publicFunctions.ts +70 -0
- package/src/rules/effect/serviceCatalog.ts +57 -0
- package/src/rules/effect/serviceFindings.ts +96 -0
- package/src/rules/effect/serviceOrigin.ts +94 -0
- package/src/rules/effect/serviceParameters.ts +35 -0
- package/src/rules/effect/serviceTypes.ts +101 -0
- package/src/rules/react/jsxConditionals.ts +59 -0
- package/src/rules/stories/engineOf.ts +2 -1
- package/src/rules/stories/namedValues.ts +4 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { defineRule, type Finding } from "#rule.ts";
|
|
3
|
+
import { parse } from "#rules/parse.ts";
|
|
4
|
+
|
|
5
|
+
const REPAIR =
|
|
6
|
+
"Decide before the JSX with an if and early return, or a variable computed above the return; or extract a component that receives the data and returns null when it has nothing to show.";
|
|
7
|
+
|
|
8
|
+
function mapCall(node: ts.Node): boolean {
|
|
9
|
+
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function childContext(node: ts.Node): { readonly mapped: boolean } | undefined {
|
|
13
|
+
let mapped = false;
|
|
14
|
+
let child = false;
|
|
15
|
+
for (let parent = node.parent; parent !== undefined; parent = parent.parent) {
|
|
16
|
+
if (!child && ts.isJsxSpreadAttribute(parent)) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (ts.isJsxExpression(parent)) {
|
|
20
|
+
if (!(child || ts.isJsxElement(parent.parent) || ts.isJsxFragment(parent.parent))) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
child = true;
|
|
24
|
+
}
|
|
25
|
+
if (ts.isVariableDeclaration(parent) || (ts.isStatement(parent) && !ts.isReturnStatement(parent) && !ts.isBlock(parent))) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
mapped ||= mapCall(parent);
|
|
29
|
+
}
|
|
30
|
+
return child ? { mapped } : undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const jsxConditionals = defineRule({
|
|
34
|
+
check: ({ sources }) =>
|
|
35
|
+
sources.flatMap((file) => {
|
|
36
|
+
const source = parse(file);
|
|
37
|
+
const findings: Finding[] = [];
|
|
38
|
+
function visit(node: ts.Node): void {
|
|
39
|
+
if (ts.isConditionalExpression(node) || (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)) {
|
|
40
|
+
const context = childContext(node);
|
|
41
|
+
if (context !== undefined && source !== undefined) {
|
|
42
|
+
findings.push({
|
|
43
|
+
file: file.path,
|
|
44
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
45
|
+
message: `Conditional rendering inside a JSX child. ${REPAIR}${context.mapped ? " Inside .map, extract the item into its own component that makes its own decision." : ""}`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
ts.forEachChild(node, visit);
|
|
50
|
+
}
|
|
51
|
+
if (source !== undefined) {
|
|
52
|
+
visit(source);
|
|
53
|
+
}
|
|
54
|
+
return findings;
|
|
55
|
+
}),
|
|
56
|
+
description: `Components decide what to render outside their JSX. ${REPAIR} Inside .map, extract an item component that makes its own decision. Attribute values are accepted.`,
|
|
57
|
+
id: "react/jsx-conditionals",
|
|
58
|
+
registrable: false,
|
|
59
|
+
});
|
|
@@ -58,7 +58,8 @@ function names(prefix: string, specifier: string): boolean {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export function engineOf(endpoint: Endpoint): string | undefined {
|
|
61
|
-
|
|
61
|
+
// HttpStatus only maps names to numbers; importing it acquires no network services.
|
|
62
|
+
if (endpoint.kind === "file" || endpoint.specifier === "effect/http/HttpStatus") {
|
|
62
63
|
return undefined;
|
|
63
64
|
}
|
|
64
65
|
return ENGINES.find(([, prefixes]) => prefixes.some((prefix) => names(prefix, endpoint.specifier) || names(prefix, endpoint.package)))?.[0];
|
|
@@ -3,7 +3,7 @@ import { defineRule } from "#rule.ts";
|
|
|
3
3
|
import { isSpec, memberName, nodesWhere, numericValue, syntaxFindings, unwrapped } from "./syntax.ts";
|
|
4
4
|
|
|
5
5
|
const MESSAGE =
|
|
6
|
-
|
|
6
|
+
'Passes a numeric literal or a matcher-only spec-local numeric const to toBe or toHaveLength. Assert the observed items, write the literal where accepted (zero or a process exitCode), or derive the value from the story\'s inputs. For HTTP statuses, import * as HttpStatus from "effect/http/HttpStatus" and use HttpStatus.fromLiteral("NotFound"), for example.';
|
|
7
7
|
|
|
8
8
|
function matcherCall(node: ts.Node): node is ts.CallExpression {
|
|
9
9
|
return ts.isCallExpression(node) && ["toBe", "toHaveLength"].includes(memberName(node.expression) ?? "");
|
|
@@ -52,7 +52,7 @@ function matcherAliases(source: ts.SourceFile): ReadonlySet<ts.Node> {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function
|
|
55
|
+
function exitCodeSubject(expression: ts.Expression): boolean {
|
|
56
56
|
const value = unwrapped(expression);
|
|
57
57
|
if (!(ts.isPropertyAccessExpression(value) || ts.isElementAccessExpression(value))) {
|
|
58
58
|
return false;
|
|
@@ -72,13 +72,13 @@ function codeSubject(expression: ts.Expression): boolean {
|
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
74
|
const subject = unwrapped(argument);
|
|
75
|
-
return
|
|
75
|
+
return (ts.isIdentifier(subject) ? subject.text : memberName(subject)) === "exitCode";
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
function numericAssertion(node: ts.Node): boolean {
|
|
79
79
|
return (
|
|
80
80
|
matcherCall(node)
|
|
81
|
-
&& !
|
|
81
|
+
&& !exitCodeSubject(node.expression)
|
|
82
82
|
&& node.arguments.some((argument) => {
|
|
83
83
|
const value = numericValue(argument);
|
|
84
84
|
return value !== undefined && value !== 0;
|