@shivaedev/quality 0.41.1 → 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 +47 -0
- package/README.md +56 -8
- package/biome/declarations.json +5 -0
- package/biome/plugins/ambient-runtime.grit +3 -1
- package/biome/plugins/effect-test-bodies.grit +1 -1
- package/biome/preset.json +2 -2
- package/dist/appTestConfig.js +1 -1
- package/dist/appTestConfig.js.map +1 -1
- package/dist/biome/withoutEntryPointImports.d.ts +4 -0
- package/dist/biome/withoutEntryPointImports.d.ts.map +1 -0
- package/dist/biome/withoutEntryPointImports.js +46 -0
- package/dist/biome/withoutEntryPointImports.js.map +1 -0
- package/dist/imports/pnpmWorkspacePatterns.d.ts +1 -0
- package/dist/imports/pnpmWorkspacePatterns.d.ts.map +1 -1
- package/dist/imports/pnpmWorkspacePatterns.js +28 -22
- package/dist/imports/pnpmWorkspacePatterns.js.map +1 -1
- package/dist/imports/runtime.d.ts +6 -0
- package/dist/imports/runtime.d.ts.map +1 -1
- package/dist/imports/runtime.js +54 -8
- package/dist/imports/runtime.js.map +1 -1
- package/dist/manifests/entryPoints.d.ts +15 -0
- package/dist/manifests/entryPoints.d.ts.map +1 -0
- package/dist/manifests/entryPoints.js +60 -0
- package/dist/manifests/entryPoints.js.map +1 -0
- package/dist/rules/biome.d.ts.map +1 -1
- package/dist/rules/biome.js +4 -2
- package/dist/rules/biome.js.map +1 -1
- package/dist/rules/builtIn.d.ts +2 -2
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +8 -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/imports/fences.d.ts +1 -1
- package/dist/rules/imports/manifest.d.ts.map +1 -1
- package/dist/rules/imports/manifest.js +27 -14
- package/dist/rules/imports/manifest.js.map +1 -1
- package/dist/rules/imports/runtime.d.ts.map +1 -1
- package/dist/rules/imports/runtime.js +10 -4
- package/dist/rules/imports/runtime.js.map +1 -1
- package/dist/rules/manifestsApplication.d.ts +2 -0
- package/dist/rules/manifestsApplication.d.ts.map +1 -0
- package/dist/rules/manifestsApplication.js +99 -0
- package/dist/rules/manifestsApplication.js.map +1 -0
- package/dist/rules/manifestsExportsShape.d.ts.map +1 -1
- package/dist/rules/manifestsExportsShape.js +5 -2
- package/dist/rules/manifestsExportsShape.js.map +1 -1
- 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 +3 -2
- 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/appTestConfig.ts +1 -1
- package/src/biome/withoutEntryPointImports.ts +52 -0
- package/src/imports/pnpmWorkspacePatterns.ts +29 -22
- package/src/imports/runtime.ts +69 -9
- package/src/manifests/entryPoints.ts +87 -0
- package/src/rules/biome.ts +4 -2
- package/src/rules/builtIn.ts +8 -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/imports/manifest.ts +42 -14
- package/src/rules/imports/runtime.ts +10 -4
- package/src/rules/manifestsApplication.ts +117 -0
- package/src/rules/manifestsExportsShape.ts +6 -2
- package/src/rules/react/jsxConditionals.ts +59 -0
- package/src/rules/stories/engineOf.ts +3 -2
- package/src/rules/stories/namedValues.ts +4 -4
- package/tsconfig/package.json +2 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import type { Finding } from "#rule.ts";
|
|
4
|
+
import { layerConstructor } from "#rules/effect/layerConstructor.ts";
|
|
5
|
+
import { publicFunctions } from "#rules/effect/publicFunctions.ts";
|
|
6
|
+
import type { serviceTypes } from "#rules/effect/serviceTypes.ts";
|
|
7
|
+
|
|
8
|
+
function publicDeclaration(declaration: ts.Declaration, local: ReadonlySet<ts.SourceFile>): boolean {
|
|
9
|
+
if (!local.has(declaration.getSourceFile()) || ts.getCombinedModifierFlags(declaration) & (ts.ModifierFlags.Private | ts.ModifierFlags.Protected)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return !((ts.isMethodDeclaration(declaration) || ts.isPropertyDeclaration(declaration)) && ts.isPrivateIdentifier(declaration.name));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function serviceFindings(
|
|
16
|
+
root: string,
|
|
17
|
+
sources: readonly ts.SourceFile[],
|
|
18
|
+
checker: ts.TypeChecker,
|
|
19
|
+
services: ReturnType<typeof serviceTypes>,
|
|
20
|
+
): readonly Finding[] {
|
|
21
|
+
const findings = new Map<ts.ParameterDeclaration, Finding>();
|
|
22
|
+
const visited = new Set<ts.Type>();
|
|
23
|
+
const activeSignatures = new Set<NonNullable<ts.Signature["declaration"]>>();
|
|
24
|
+
const local = new Set(sources);
|
|
25
|
+
function parameterFinding(symbol: ts.Symbol): void {
|
|
26
|
+
if (!services.carries(checker.getTypeOfSymbol(symbol))) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (const parameter of symbol.declarations ?? []) {
|
|
30
|
+
if (!(ts.isParameter(parameter) && local.has(parameter.getSourceFile()))) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const source = parameter.getSourceFile();
|
|
34
|
+
const file = relative(root, source.fileName).replaceAll("\\", "/");
|
|
35
|
+
findings.set(parameter, {
|
|
36
|
+
file,
|
|
37
|
+
line: source.getLineAndCharacterOfPosition(parameter.getStart(source)).line + 1,
|
|
38
|
+
message: `Parameter ${parameter.name.getText(source)} carries a service. Read services from Effect's environment instead of passing them; return an Effect or Stream with requirements. Service implementation methods and Layer constructors are accepted; only test-support/ folders are exempt, not adapters/.`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function signatureFinding(signature: ts.Signature): void {
|
|
43
|
+
const declaration = signature.declaration;
|
|
44
|
+
if (declaration === undefined || !local.has(declaration.getSourceFile()) || layerConstructor(checker, declaration)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const result = signature.getReturnType();
|
|
48
|
+
if (result.getProperty("~effect/Layer") !== undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (const parameter of signature.parameters) {
|
|
52
|
+
parameterFinding(parameter);
|
|
53
|
+
}
|
|
54
|
+
if (activeSignatures.has(declaration)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
activeSignatures.add(declaration);
|
|
58
|
+
surface(result);
|
|
59
|
+
activeSignatures.delete(declaration);
|
|
60
|
+
}
|
|
61
|
+
function members(type: ts.Type): void {
|
|
62
|
+
if (type.isUnionOrIntersection()) {
|
|
63
|
+
for (const part of type.types) {
|
|
64
|
+
surface(part);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const index of checker.getIndexInfosOfType(type)) {
|
|
68
|
+
surface(index.type);
|
|
69
|
+
}
|
|
70
|
+
for (const signature of type.getConstructSignatures()) {
|
|
71
|
+
surface(signature.getReturnType());
|
|
72
|
+
}
|
|
73
|
+
for (const property of type
|
|
74
|
+
.getProperties()
|
|
75
|
+
.filter((candidate) => (candidate.declarations ?? []).some((declaration) => publicDeclaration(declaration, local)))) {
|
|
76
|
+
surface(checker.getTypeOfSymbol(property));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function surface(type: ts.Type): void {
|
|
80
|
+
if (visited.has(type) || !(type.flags & (ts.TypeFlags.Object | ts.TypeFlags.Intersection | ts.TypeFlags.Union))) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
visited.add(type);
|
|
84
|
+
const signatures = type.getCallSignatures();
|
|
85
|
+
const constructsLayer = signatures.some((signature) => signature.declaration !== undefined && layerConstructor(checker, signature.declaration));
|
|
86
|
+
if (services.computation(type) || (!constructsLayer && services.implementation(type))) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
members(type);
|
|
90
|
+
for (const signature of signatures) {
|
|
91
|
+
signatureFinding(signature);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
publicFunctions(sources, checker, surface);
|
|
95
|
+
return [...findings.values()];
|
|
96
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { returnValues } from "#rules/stories/returnValues.ts";
|
|
3
|
+
|
|
4
|
+
const SERVICE_NAMES = new Set(["Service", "ServiceClass", "Key", "Reference", "Tag", "TagClass", "GenericTag"]);
|
|
5
|
+
|
|
6
|
+
function annotation(declaration: ts.Declaration): ts.TypeNode | undefined {
|
|
7
|
+
if (
|
|
8
|
+
ts.isVariableDeclaration(declaration)
|
|
9
|
+
|| ts.isParameter(declaration)
|
|
10
|
+
|| ts.isTypeAliasDeclaration(declaration)
|
|
11
|
+
|| ts.isFunctionLike(declaration)
|
|
12
|
+
) {
|
|
13
|
+
return declaration.type;
|
|
14
|
+
}
|
|
15
|
+
return ts.isTypeParameterDeclaration(declaration) ? declaration.constraint : undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function declarationOrigin(checker: ts.TypeChecker, declaration: ts.Declaration, seen: Set<ts.Symbol>): boolean {
|
|
19
|
+
const type = annotation(declaration);
|
|
20
|
+
if (type !== undefined && serviceOrigin(checker, type, seen)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
|
|
24
|
+
return serviceOrigin(checker, declaration.initializer, seen);
|
|
25
|
+
}
|
|
26
|
+
if (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) {
|
|
27
|
+
return declaration.heritageClauses?.some((clause) => clause.types.some((base) => serviceOrigin(checker, base.expression, seen))) ?? false;
|
|
28
|
+
}
|
|
29
|
+
return ts.isFunctionLike(declaration) && returnValues(declaration).some((value) => value !== undefined && serviceOrigin(checker, value, seen));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function symbolOrigin(checker: ts.TypeChecker, symbol: ts.Symbol, seen: Set<ts.Symbol>): boolean {
|
|
33
|
+
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
34
|
+
if (seen.has(target)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
seen.add(target);
|
|
38
|
+
return (target.declarations ?? []).some((declaration) => {
|
|
39
|
+
const file = declaration.getSourceFile().fileName.replaceAll("\\", "/");
|
|
40
|
+
if (
|
|
41
|
+
/\/effect\/(?:src|dist)\/(?:Context|Effect)(?:\.d)?\.ts$/u.test(file)
|
|
42
|
+
&& SERVICE_NAMES.has(target.name)
|
|
43
|
+
&& (ts.isVariableDeclaration(declaration)
|
|
44
|
+
|| ts.isFunctionDeclaration(declaration)
|
|
45
|
+
|| ts.isClassDeclaration(declaration)
|
|
46
|
+
|| ts.isInterfaceDeclaration(declaration)
|
|
47
|
+
|| ts.isTypeAliasDeclaration(declaration))
|
|
48
|
+
) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (file.endsWith("/service/src/defineService.ts") && target.name === "defineService") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return declarationOrigin(checker, declaration, seen);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function reference(node: ts.Node): ts.Node | undefined {
|
|
59
|
+
if (ts.isCallExpression(node)) {
|
|
60
|
+
return node.expression;
|
|
61
|
+
}
|
|
62
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
63
|
+
return node.typeName;
|
|
64
|
+
}
|
|
65
|
+
if (ts.isTypeQueryNode(node)) {
|
|
66
|
+
return node.exprName;
|
|
67
|
+
}
|
|
68
|
+
return ts.isParenthesizedTypeNode(node) ? node.type : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function serviceOrigin(checker: ts.TypeChecker, node: ts.Node | ts.Symbol, seen = new Set<ts.Symbol>()): boolean {
|
|
72
|
+
if (!("kind" in node)) {
|
|
73
|
+
return symbolOrigin(checker, node, seen);
|
|
74
|
+
}
|
|
75
|
+
const referred = reference(node);
|
|
76
|
+
if (referred !== undefined) {
|
|
77
|
+
return serviceOrigin(checker, referred, seen);
|
|
78
|
+
}
|
|
79
|
+
if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node)) {
|
|
80
|
+
return node.types.some((part) => serviceOrigin(checker, part, seen));
|
|
81
|
+
}
|
|
82
|
+
if (ts.isFunctionExpression(node) || ts.isArrowFunction(node)) {
|
|
83
|
+
return returnValues(node).some((value) => value !== undefined && serviceOrigin(checker, value, seen));
|
|
84
|
+
}
|
|
85
|
+
if (ts.isPropertyAccessExpression(node) && !SERVICE_NAMES.has(node.name.text)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const location = ts.isQualifiedName(node) ? node.right : node;
|
|
89
|
+
if (!(ts.isIdentifier(location) || ts.isPropertyAccessExpression(location))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(location) ? location.name : location);
|
|
93
|
+
return symbol !== undefined && symbolOrigin(checker, symbol, seen);
|
|
94
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
3
|
+
import { effectProgram } from "#rules/effect/program.ts";
|
|
4
|
+
import { serviceCatalog } from "#rules/effect/serviceCatalog.ts";
|
|
5
|
+
import { serviceFindings } from "#rules/effect/serviceFindings.ts";
|
|
6
|
+
|
|
7
|
+
export const serviceParameters = defineRule({
|
|
8
|
+
check: (inputs) => {
|
|
9
|
+
const groups = new Map<string, RuleInputs["sources"][number][]>();
|
|
10
|
+
for (const source of inputs.sources) {
|
|
11
|
+
if (/(?:^|\/)test-support\//u.test(source.path)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const group = /^(?:packages|examples)\/[^/]+/u.exec(source.path)?.[0] ?? ".";
|
|
15
|
+
const files = groups.get(group) ?? [];
|
|
16
|
+
files.push(source);
|
|
17
|
+
groups.set(group, files);
|
|
18
|
+
}
|
|
19
|
+
return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }));
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
"Exported functions and public methods take services from Effect's environment, including aliases, constraints, inferred/destructured parameters and factory returns. Service keys/classes, non-empty Contexts and implementation shapes are services; Effect/Stream requirements are computations. Service implementation methods and Layer constructors are accepted. Only test-support/ folders are exempt. The fixed adapters/ convention bridges outside libraries to Effect values; adapters still follow this rule and ambient runtime bans. No config exceptions or inline suppressions; baseline existing debt.",
|
|
23
|
+
id: "effect/service-parameters",
|
|
24
|
+
registrable: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function checkServices(inputs: RuleInputs): readonly Finding[] {
|
|
28
|
+
const program = effectProgram(inputs);
|
|
29
|
+
const checker = program.getTypeChecker();
|
|
30
|
+
const sources = inputs.sources.flatMap((file) => {
|
|
31
|
+
const source = program.getSourceFile(join(inputs.root, file.path));
|
|
32
|
+
return source === undefined ? [] : [source];
|
|
33
|
+
});
|
|
34
|
+
return serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker));
|
|
35
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
const SERVICE = "~effect/Context/Service";
|
|
4
|
+
const CONTEXT = "~effect/Context";
|
|
5
|
+
|
|
6
|
+
export function serviceTypes(checker: ts.TypeChecker) {
|
|
7
|
+
const shapes = new Set<ts.Type>();
|
|
8
|
+
const carried = new Map<ts.Type, boolean>();
|
|
9
|
+
function propertyType(type: ts.Type, name: string): ts.Type | undefined {
|
|
10
|
+
const property = type.getProperty(name);
|
|
11
|
+
return property === undefined ? undefined : checker.getTypeOfSymbol(property);
|
|
12
|
+
}
|
|
13
|
+
function remember(type: ts.Type): void {
|
|
14
|
+
if (type.getProperty(SERVICE) === undefined) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const shape = propertyType(type, "Service");
|
|
18
|
+
if (
|
|
19
|
+
shape !== undefined
|
|
20
|
+
&& shape.flags & ts.TypeFlags.Object
|
|
21
|
+
&& (shape.getProperties().length > 0 || shape.getCallSignatures().length > 0)
|
|
22
|
+
&& checker.getIndexInfosOfType(shape).length === 0
|
|
23
|
+
&& (shape.getCallSignatures().length === 0 || type.getProperty("~effect/Context/Reference") === undefined)
|
|
24
|
+
) {
|
|
25
|
+
shapes.add(shape);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function computation(type: ts.Type): boolean {
|
|
29
|
+
return ["~effect/Effect", "~effect/Stream"].some((brand) => type.getProperty(brand) !== undefined);
|
|
30
|
+
}
|
|
31
|
+
function implementation(type: ts.Type): boolean {
|
|
32
|
+
if (shapes.has(type)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const declaration = type.getSymbol()?.valueDeclaration;
|
|
36
|
+
const contextual = declaration !== undefined && ts.isObjectLiteralExpression(declaration) ? checker.getContextualType(declaration) : undefined;
|
|
37
|
+
return contextual !== undefined && shapes.has(contextual);
|
|
38
|
+
}
|
|
39
|
+
function nonEmptyContext(context: ts.Type): boolean {
|
|
40
|
+
const variance = propertyType(context, "_Services");
|
|
41
|
+
const parameter = variance?.getCallSignatures()[0]?.parameters[0];
|
|
42
|
+
if (parameter === undefined) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const required = checker.getTypeOfSymbol(parameter);
|
|
46
|
+
return !((checker.getBaseConstraintOfType(required) ?? required).flags & ts.TypeFlags.Never);
|
|
47
|
+
}
|
|
48
|
+
function carries(type: ts.Type, seen = new Set<ts.Type>()): boolean {
|
|
49
|
+
if (
|
|
50
|
+
seen.has(type)
|
|
51
|
+
|| type.flags
|
|
52
|
+
& (ts.TypeFlags.Any
|
|
53
|
+
| ts.TypeFlags.Unknown
|
|
54
|
+
| ts.TypeFlags.Never
|
|
55
|
+
| ts.TypeFlags.StringLike
|
|
56
|
+
| ts.TypeFlags.NumberLike
|
|
57
|
+
| ts.TypeFlags.BooleanLike
|
|
58
|
+
| ts.TypeFlags.ESSymbolLike
|
|
59
|
+
| ts.TypeFlags.BigIntLike)
|
|
60
|
+
) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
seen.add(type);
|
|
64
|
+
if (type.isUnionOrIntersection()) {
|
|
65
|
+
return type.types.some((part) => carries(part, seen));
|
|
66
|
+
}
|
|
67
|
+
if (type.getProperty(SERVICE) !== undefined) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
const context = propertyType(type, CONTEXT);
|
|
71
|
+
if (context !== undefined) {
|
|
72
|
+
return nonEmptyContext(context);
|
|
73
|
+
}
|
|
74
|
+
if (computation(type)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const constraint = checker.getBaseConstraintOfType(type);
|
|
78
|
+
if (constraint !== undefined && carries(constraint, seen)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return (
|
|
82
|
+
implementation(type)
|
|
83
|
+
|| checker.getIndexInfosOfType(type).some((index) => carries(index.type, seen))
|
|
84
|
+
|| type.getProperties().some((property) => !(property.flags & ts.SymbolFlags.Method) && carries(checker.getTypeOfSymbol(property), seen))
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
carries: (type: ts.Type) => {
|
|
89
|
+
const known = carried.get(type);
|
|
90
|
+
if (known !== undefined) {
|
|
91
|
+
return known;
|
|
92
|
+
}
|
|
93
|
+
const result = carries(type);
|
|
94
|
+
carried.set(type, result);
|
|
95
|
+
return result;
|
|
96
|
+
},
|
|
97
|
+
computation,
|
|
98
|
+
implementation,
|
|
99
|
+
remember,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -3,6 +3,7 @@ import { type ImportGraph, importGraph } from "#imports/graph.ts";
|
|
|
3
3
|
import { isTooling } from "#imports/isTooling.ts";
|
|
4
4
|
import { builtinName } from "#imports/resolve.ts";
|
|
5
5
|
import { packageOf, type WorkspacePackage } from "#imports/workspace.ts";
|
|
6
|
+
import { type EntryPoint, entryPointsOf, isApplication, provider, SHIPPED_FIELDS } from "#manifests/entryPoints.ts";
|
|
6
7
|
import { isTestCode } from "#naming/testName.ts";
|
|
7
8
|
import { defineRule, type RuleInputs } from "#rule.ts";
|
|
8
9
|
import { bundleInputs } from "./bundleInputs.ts";
|
|
@@ -21,7 +22,10 @@ function packageName(specifier: string): string {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
interface ManifestDependencies {
|
|
25
|
+
readonly application: boolean;
|
|
24
26
|
readonly development: ReadonlySet<string>;
|
|
27
|
+
readonly entryPoints: readonly EntryPoint[];
|
|
28
|
+
readonly private: boolean;
|
|
25
29
|
readonly privateFiles: ReadonlySet<string>;
|
|
26
30
|
readonly runtime: ReadonlySet<string>;
|
|
27
31
|
readonly shipped: ReadonlySet<string>;
|
|
@@ -38,7 +42,12 @@ function names(manifest: object, field: string): readonly string[] {
|
|
|
38
42
|
return Object.keys(value);
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
async function manifestDependencies(
|
|
45
|
+
async function manifestDependencies(
|
|
46
|
+
inputs: RuleInputs,
|
|
47
|
+
owner: WorkspacePackage,
|
|
48
|
+
graph: ImportGraph,
|
|
49
|
+
workspace: ReadonlyMap<string, string>,
|
|
50
|
+
): Promise<ManifestDependencies> {
|
|
42
51
|
const path = posix.join(owner.directory, "package.json");
|
|
43
52
|
try {
|
|
44
53
|
const text = await inputs.readText(path);
|
|
@@ -51,8 +60,11 @@ async function manifestDependencies(inputs: RuleInputs, owner: WorkspacePackage,
|
|
|
51
60
|
}
|
|
52
61
|
return {
|
|
53
62
|
...bundleInputs(graph, owner, manifest, (candidate) => developmentFile(owner, candidate)),
|
|
63
|
+
application: isApplication(manifest),
|
|
54
64
|
development: new Set(names(manifest, "devDependencies")),
|
|
55
|
-
|
|
65
|
+
entryPoints: await entryPointsOf(inputs, owner.directory, manifest, workspace),
|
|
66
|
+
private: Reflect.get(manifest, "private") === true,
|
|
67
|
+
shipped: new Set(SHIPPED_FIELDS.flatMap((field) => names(manifest, field))),
|
|
56
68
|
};
|
|
57
69
|
} catch (cause) {
|
|
58
70
|
throw new Error(`cannot read dependency policy at ${path}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
@@ -70,12 +82,35 @@ function developmentImport(policy: ManifestDependencies | undefined, owner: Work
|
|
|
70
82
|
return developmentFile(owner, path) || policy?.privateFiles.has(path);
|
|
71
83
|
}
|
|
72
84
|
|
|
85
|
+
function declares(policy: ManifestDependencies, target: string, development: boolean): boolean {
|
|
86
|
+
return (
|
|
87
|
+
policy.shipped.has(target)
|
|
88
|
+
|| (development && policy.development.has(target))
|
|
89
|
+
|| (policy.application && provider(policy.entryPoints, target, development, true) !== undefined)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function undeclared(owner: WorkspacePackage, policy: ManifestDependencies | undefined, target: string, development: boolean): string {
|
|
94
|
+
const missing = policy?.private === true ? provider(policy.entryPoints, target, development, false) : undefined;
|
|
95
|
+
const entryPoint =
|
|
96
|
+
missing === undefined
|
|
97
|
+
? ""
|
|
98
|
+
: ` An application can instead add "${missing.name}" to ${missing.testOnly ? "devDependencies" : "dependencies"}, which brings it.`;
|
|
99
|
+
const scope = development
|
|
100
|
+
? " Tooling, test code and export-blocked bundle inputs may also use devDependencies."
|
|
101
|
+
: " devDependencies are only available to tests, test support, tooling and export-blocked bundle inputs unreachable from runtime code.";
|
|
102
|
+
return `Imports workspace package "${target}" without declaring it in ${posix.join(owner.directory, "package.json")}. Add it to dependencies, peerDependencies or optionalDependencies, or remove the import.${entryPoint}${scope}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
73
105
|
export const importsManifest = defineRule({
|
|
74
106
|
check: async (inputs) => {
|
|
75
107
|
const graph = await importGraph(inputs);
|
|
76
108
|
const root: WorkspacePackage | undefined = (await inputs.readText("package.json")) === undefined ? undefined : { directory: ".", name: "." };
|
|
77
109
|
const owners = [...graph.packages, ...(root === undefined ? [] : [root])];
|
|
78
|
-
const
|
|
110
|
+
const workspace = new Map(graph.packages.map((owner) => [owner.name, owner.directory]));
|
|
111
|
+
const policies = new Map(
|
|
112
|
+
await Promise.all(owners.map(async (owner) => [owner, await manifestDependencies(inputs, owner, graph, workspace)] as const)),
|
|
113
|
+
);
|
|
79
114
|
const runtime = new Set([...policies.values()].flatMap((policy) => [...policy.runtime]));
|
|
80
115
|
const named = new Map(graph.packages.map((owner) => [owner.name, owner]));
|
|
81
116
|
const requests = [...graph.edges, ...graph.unresolved.filter((request) => request.missing === undefined)];
|
|
@@ -88,21 +123,14 @@ export const importsManifest = defineRule({
|
|
|
88
123
|
return [];
|
|
89
124
|
}
|
|
90
125
|
const policy = policies.get(owner);
|
|
91
|
-
const development = developmentImport(policy, owner, request.from, runtime);
|
|
92
|
-
if (policy
|
|
126
|
+
const development = developmentImport(policy, owner, request.from, runtime) === true;
|
|
127
|
+
if (policy !== undefined && declares(policy, target.name, development)) {
|
|
93
128
|
return [];
|
|
94
129
|
}
|
|
95
|
-
return [
|
|
96
|
-
{
|
|
97
|
-
file: request.from,
|
|
98
|
-
line: request.line,
|
|
99
|
-
message: `Imports workspace package "${target.name}" without declaring it in ${posix.join(owner.directory, "package.json")}. Add it to dependencies, peerDependencies or optionalDependencies, or remove the import.${development ? " Tooling, test code and export-blocked bundle inputs may also use devDependencies." : " devDependencies are only available to tests, test support, tooling and export-blocked bundle inputs unreachable from runtime code."}`,
|
|
100
|
-
subject: target.name,
|
|
101
|
-
},
|
|
102
|
-
];
|
|
130
|
+
return [{ file: request.from, line: request.line, message: undeclared(owner, policy, target.name, development), subject: target.name }];
|
|
103
131
|
});
|
|
104
132
|
},
|
|
105
133
|
description:
|
|
106
|
-
"Workspace imports follow the importing package's manifest; devDependencies are available only outside runtime code, including export-blocked bundle inputs.",
|
|
134
|
+
"Workspace imports follow the importing package's manifest; devDependencies are available only outside runtime code, including export-blocked bundle inputs, and an application also reaches the dependencies of the entry points it declares: @shivaedev/platform for any code and @shivaedev/test-story for test code.",
|
|
107
135
|
id: "imports/manifest",
|
|
108
136
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { importGraph } from "#imports/graph.ts";
|
|
2
2
|
import { builtinName } from "#imports/resolve.ts";
|
|
3
|
-
import { type Runtime, runtimeOf } from "#imports/runtime.ts";
|
|
3
|
+
import { type Runtime, runtimeDeclarationProblems, runtimeOf } from "#imports/runtime.ts";
|
|
4
4
|
import { isTestCode } from "#naming/testName.ts";
|
|
5
5
|
import { defineRule } from "#rule.ts";
|
|
6
6
|
|
|
@@ -34,14 +34,20 @@ export const importsRuntime = defineRule({
|
|
|
34
34
|
},
|
|
35
35
|
];
|
|
36
36
|
});
|
|
37
|
+
const declarations = runtimeDeclarationProblems(inputs, graph.packages).map(({ directory, message }) => ({
|
|
38
|
+
file: directory === "." ? "package.json" : `${directory}/package.json`,
|
|
39
|
+
line: 1,
|
|
40
|
+
message,
|
|
41
|
+
subject: "quality.runtime",
|
|
42
|
+
}));
|
|
37
43
|
const shared = inputs.sources.filter((file) => !isTestCode(file.path) && runtime(file.path) === "shared");
|
|
38
44
|
if (shared.length === 0) {
|
|
39
|
-
return imports;
|
|
45
|
+
return [...imports, ...declarations];
|
|
40
46
|
}
|
|
41
47
|
const { browserGlobals } = await import("#imports/browserGlobals.ts");
|
|
42
|
-
return [...imports, ...shared.flatMap(browserGlobals)];
|
|
48
|
+
return [...imports, ...declarations, ...shared.flatMap(browserGlobals)];
|
|
43
49
|
},
|
|
44
50
|
description:
|
|
45
|
-
"Runtime folders define client, server and shared code.
|
|
51
|
+
"Runtime folders define client, server and shared code. A manifest's quality.runtime declares a single-runtime package whole; executable packages without runtime folders and package-root tooling are server code.",
|
|
46
52
|
id: "imports/runtime",
|
|
47
53
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { dirname, posix, relative, resolve, sep } from "node:path";
|
|
2
|
+
import { pnpmWorkspaceList } from "#imports/pnpmWorkspacePatterns.ts";
|
|
3
|
+
import { workspacePackages } from "#imports/workspace.ts";
|
|
4
|
+
import { DEPENDENCY_FIELDS, dependencyNames, entryPointsOf, isApplication, PLATFORM } from "#manifests/entryPoints.ts";
|
|
5
|
+
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
6
|
+
|
|
7
|
+
const HOISTED = "@shivaedev/*";
|
|
8
|
+
|
|
9
|
+
const HOIST_KEY = "publicHoistPattern";
|
|
10
|
+
|
|
11
|
+
const HOIST_LINE = `${HOIST_KEY}: ["${HOISTED}"]`;
|
|
12
|
+
|
|
13
|
+
const PROBE = "@shivaedev/probe";
|
|
14
|
+
|
|
15
|
+
function hoists(pattern: string): boolean {
|
|
16
|
+
const source = pattern.replaceAll(/[.+?^${}()|[\]\\]/gu, "\\$&").replaceAll("*", ".*");
|
|
17
|
+
return new RegExp(`^${source}$`, "u").test(PROBE);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parsed(text: string | undefined): unknown {
|
|
21
|
+
if (text === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(text);
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ancestors(root: string, directory: string): readonly string[] {
|
|
32
|
+
const start = resolve(root, directory);
|
|
33
|
+
const parent = dirname(start);
|
|
34
|
+
return parent === start ? [start] : [start, ...ancestors(root, relative(root, parent))];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function nearestWorkspace(inputs: Pick<RuleInputs, "readText" | "root">, directory: string) {
|
|
38
|
+
for (const candidate of ancestors(inputs.root, directory)) {
|
|
39
|
+
const path = posix.join(relative(inputs.root, candidate).split(sep).join("/") || ".", "pnpm-workspace.yaml");
|
|
40
|
+
const text = await inputs.readText(path);
|
|
41
|
+
if (text !== undefined) {
|
|
42
|
+
return { path, text };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function hoistFindings(inputs: Pick<RuleInputs, "readText" | "root">, manifestPath: string, directory: string): Promise<readonly Finding[]> {
|
|
49
|
+
const workspace = await nearestWorkspace(inputs, directory);
|
|
50
|
+
const target = workspace?.path ?? posix.join(directory, "pnpm-workspace.yaml");
|
|
51
|
+
const repair = `Add \`${HOIST_LINE}\` to ${target} so the pieces platform brings resolve by their own names.`;
|
|
52
|
+
if (workspace === undefined) {
|
|
53
|
+
return [{ file: manifestPath, message: `Depends on "${PLATFORM}" without a pnpm-workspace.yaml. ${repair}`, subject: HOIST_KEY }];
|
|
54
|
+
}
|
|
55
|
+
let patterns: readonly string[];
|
|
56
|
+
try {
|
|
57
|
+
patterns = pnpmWorkspaceList(workspace.text, HOIST_KEY);
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
return [{ file: workspace.path, message: `${cause instanceof Error ? cause.message : String(cause)}. Write ${HOIST_LINE}.`, subject: HOIST_KEY }];
|
|
60
|
+
}
|
|
61
|
+
const included = patterns.some((pattern) => !pattern.startsWith("!") && hoists(pattern));
|
|
62
|
+
const excluded = patterns.some((pattern) => pattern.startsWith("!") && hoists(pattern.slice(1)));
|
|
63
|
+
if (included && !excluded) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
{ file: manifestPath, message: `Depends on "${PLATFORM}", but ${workspace.path} does not hoist ${HOISTED}. ${repair}`, subject: HOIST_KEY },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function duplicateFindings(
|
|
72
|
+
inputs: Pick<RuleInputs, "readText">,
|
|
73
|
+
manifestPath: string,
|
|
74
|
+
directory: string,
|
|
75
|
+
manifest: unknown,
|
|
76
|
+
workspace: ReadonlyMap<string, string>,
|
|
77
|
+
): Promise<readonly Finding[]> {
|
|
78
|
+
const entryPoints = (await entryPointsOf(inputs, directory, manifest, workspace)).filter((entry) => entry.declared !== undefined);
|
|
79
|
+
return DEPENDENCY_FIELDS.flatMap((field) =>
|
|
80
|
+
dependencyNames(manifest, field).flatMap((name) => {
|
|
81
|
+
const entry = entryPoints.find((candidate) => candidate.provides.has(name));
|
|
82
|
+
return entry === undefined
|
|
83
|
+
? []
|
|
84
|
+
: [
|
|
85
|
+
{
|
|
86
|
+
file: manifestPath,
|
|
87
|
+
message: `Lists "${name}" in ${field} beside "${entry.name}", which already brings it. Remove "${name}" from ${field} and keep importing it by its own name.`,
|
|
88
|
+
subject: name,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const manifestsApplication = defineRule({
|
|
96
|
+
check: async (inputs) => {
|
|
97
|
+
const packages = await workspacePackages(inputs);
|
|
98
|
+
const workspace = new Map(packages.map((owner) => [owner.name, owner.directory]));
|
|
99
|
+
const directories = [".", ...packages.map((owner) => owner.directory)];
|
|
100
|
+
const findings = await Promise.all(
|
|
101
|
+
directories.map(async (directory) => {
|
|
102
|
+
const manifestPath = posix.join(directory, "package.json");
|
|
103
|
+
const manifest = parsed(await inputs.readText(manifestPath));
|
|
104
|
+
if (!isApplication(manifest)) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return [
|
|
108
|
+
...(await hoistFindings(inputs, manifestPath, directory)),
|
|
109
|
+
...(await duplicateFindings(inputs, manifestPath, directory, manifest, workspace)),
|
|
110
|
+
];
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
return findings.flat();
|
|
114
|
+
},
|
|
115
|
+
description: `An application, a package that depends on ${PLATFORM}, hoists ${HOISTED} in its nearest pnpm-workspace.yaml and lists no package beside the entry point that already brings it.`,
|
|
116
|
+
id: "manifests/application",
|
|
117
|
+
});
|
|
@@ -45,8 +45,11 @@ function findingsIn(file: string, exports: unknown): readonly Finding[] {
|
|
|
45
45
|
}
|
|
46
46
|
const entries = Object.entries(exports);
|
|
47
47
|
const patterns = entries.filter(([key, value]) => key.includes("*") && value !== null);
|
|
48
|
+
const exportsModules = entries.some(([key, value]) => value !== null && !exactAsset(key, value));
|
|
48
49
|
const count =
|
|
49
|
-
patterns.length === 1
|
|
50
|
+
patterns.length === 1 || (patterns.length === 0 && !exportsModules)
|
|
51
|
+
? []
|
|
52
|
+
: [finding(file, "exports", `The exports field needs exactly one non-null wildcard; found ${patterns.length}.`)];
|
|
50
53
|
return [
|
|
51
54
|
...count,
|
|
52
55
|
...entries.flatMap(([key, value]) =>
|
|
@@ -73,7 +76,8 @@ export const manifestsExportsShape = defineRule({
|
|
|
73
76
|
);
|
|
74
77
|
return findings.flat();
|
|
75
78
|
},
|
|
76
|
-
description:
|
|
79
|
+
description:
|
|
80
|
+
"Workspace packages export modules through one file-preserving wildcard, with optional root, exact non-code assets and null blocks; a package without modules exports only exact assets.",
|
|
77
81
|
id: "manifests/exports-shape",
|
|
78
82
|
registrable: false,
|
|
79
83
|
});
|
|
@@ -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
|
+
});
|