@shivaedev/quality 0.48.2 → 0.50.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.
Files changed (148) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +18 -10
  3. package/biome/plugins/ambient-runtime.grit +67 -1
  4. package/biome/plugins/type-re-exports.grit +33 -4
  5. package/dist/adapters/biome/run.js +4 -4
  6. package/dist/adapters/biome/run.js.map +1 -1
  7. package/dist/adapters/knip/configuration.d.ts +5 -2
  8. package/dist/adapters/knip/configuration.d.ts.map +1 -1
  9. package/dist/adapters/knip/configuration.js +12 -5
  10. package/dist/adapters/knip/configuration.js.map +1 -1
  11. package/dist/adapters/knip/run.d.ts +2 -3
  12. package/dist/adapters/knip/run.d.ts.map +1 -1
  13. package/dist/adapters/knip/run.js +25 -7
  14. package/dist/adapters/knip/run.js.map +1 -1
  15. package/dist/adapters/knip/sourceConfig.d.ts.map +1 -1
  16. package/dist/adapters/knip/sourceConfig.js +3 -0
  17. package/dist/adapters/knip/sourceConfig.js.map +1 -1
  18. package/dist/baseline/looseStagedEntries.d.ts +4 -0
  19. package/dist/baseline/looseStagedEntries.d.ts.map +1 -0
  20. package/dist/baseline/looseStagedEntries.js +31 -0
  21. package/dist/baseline/looseStagedEntries.js.map +1 -0
  22. package/dist/baseline/update.d.ts +1 -1
  23. package/dist/baseline/update.d.ts.map +1 -1
  24. package/dist/baseline/update.js +3 -3
  25. package/dist/baseline/update.js.map +1 -1
  26. package/dist/cli/args.d.ts +2 -1
  27. package/dist/cli/args.d.ts.map +1 -1
  28. package/dist/cli/args.js +9 -35
  29. package/dist/cli/args.js.map +1 -1
  30. package/dist/cli/baseline.d.ts +1 -1
  31. package/dist/cli/baseline.d.ts.map +1 -1
  32. package/dist/cli/baseline.js +25 -2
  33. package/dist/cli/baseline.js.map +1 -1
  34. package/dist/cli/lint.d.ts +1 -1
  35. package/dist/cli/lint.d.ts.map +1 -1
  36. package/dist/cli/lint.js +11 -2
  37. package/dist/cli/lint.js.map +1 -1
  38. package/dist/cli/messages.d.ts +1 -1
  39. package/dist/cli/messages.d.ts.map +1 -1
  40. package/dist/cli/messages.js +4 -3
  41. package/dist/cli/messages.js.map +1 -1
  42. package/dist/cli/options.d.ts +45 -0
  43. package/dist/cli/options.d.ts.map +1 -0
  44. package/dist/cli/options.js +35 -0
  45. package/dist/cli/options.js.map +1 -0
  46. package/dist/cli/program.d.ts.map +1 -1
  47. package/dist/cli/program.js +3 -2
  48. package/dist/cli/program.js.map +1 -1
  49. package/dist/hooks/preCommit.js +1 -1
  50. package/dist/hooks/preCommit.js.map +1 -1
  51. package/dist/imports/classifyRuntime.d.ts.map +1 -1
  52. package/dist/imports/classifyRuntime.js +4 -1
  53. package/dist/imports/classifyRuntime.js.map +1 -1
  54. package/dist/imports/runtime.d.ts +6 -3
  55. package/dist/imports/runtime.d.ts.map +1 -1
  56. package/dist/imports/runtime.js +15 -21
  57. package/dist/imports/runtime.js.map +1 -1
  58. package/dist/inventory/collect.js +3 -3
  59. package/dist/inventory/collect.js.map +1 -1
  60. package/dist/inventory/shadcnFiles.d.ts +4 -0
  61. package/dist/inventory/shadcnFiles.d.ts.map +1 -0
  62. package/dist/inventory/shadcnFiles.js +83 -0
  63. package/dist/inventory/shadcnFiles.js.map +1 -0
  64. package/dist/naming/migrationFile.d.ts.map +1 -1
  65. package/dist/naming/migrationFile.js +3 -1
  66. package/dist/naming/migrationFile.js.map +1 -1
  67. package/dist/naming/moduleRoot.d.ts +2 -0
  68. package/dist/naming/moduleRoot.d.ts.map +1 -0
  69. package/dist/naming/moduleRoot.js +13 -0
  70. package/dist/naming/moduleRoot.js.map +1 -0
  71. package/dist/report/render.d.ts.map +1 -1
  72. package/dist/report/render.js +3 -10
  73. package/dist/report/render.js.map +1 -1
  74. package/dist/report/staleSections.js +1 -1
  75. package/dist/report/staleSections.js.map +1 -1
  76. package/dist/rules/builtIn.d.ts +2 -2
  77. package/dist/rules/effect/boundary.d.ts.map +1 -1
  78. package/dist/rules/effect/boundary.js +30 -6
  79. package/dist/rules/effect/boundary.js.map +1 -1
  80. package/dist/rules/effect/boundaryCalls.d.ts +3 -0
  81. package/dist/rules/effect/boundaryCalls.d.ts.map +1 -0
  82. package/dist/rules/effect/boundaryCalls.js +121 -0
  83. package/dist/rules/effect/boundaryCalls.js.map +1 -0
  84. package/dist/rules/effect/boundaryReference.d.ts +4 -0
  85. package/dist/rules/effect/boundaryReference.d.ts.map +1 -0
  86. package/dist/rules/effect/boundaryReference.js +80 -0
  87. package/dist/rules/effect/boundaryReference.js.map +1 -0
  88. package/dist/rules/effect/program.d.ts +1 -1
  89. package/dist/rules/effect/program.d.ts.map +1 -1
  90. package/dist/rules/effect/program.js +4 -1
  91. package/dist/rules/effect/program.js.map +1 -1
  92. package/dist/rules/effect/promiseParameter.d.ts +3 -0
  93. package/dist/rules/effect/promiseParameter.d.ts.map +1 -0
  94. package/dist/rules/effect/promiseParameter.js +24 -0
  95. package/dist/rules/effect/promiseParameter.js.map +1 -0
  96. package/dist/rules/importOrigins.d.ts +4 -0
  97. package/dist/rules/importOrigins.d.ts.map +1 -0
  98. package/dist/rules/importOrigins.js +36 -0
  99. package/dist/rules/importOrigins.js.map +1 -0
  100. package/dist/rules/imports/runtime.d.ts +1 -1
  101. package/dist/rules/imports/runtime.d.ts.map +1 -1
  102. package/dist/rules/noBarrel.d.ts.map +1 -1
  103. package/dist/rules/noBarrel.js +19 -7
  104. package/dist/rules/noBarrel.js.map +1 -1
  105. package/dist/rules/secondNames.d.ts +7 -0
  106. package/dist/rules/secondNames.d.ts.map +1 -0
  107. package/dist/rules/secondNames.js +98 -0
  108. package/dist/rules/secondNames.js.map +1 -0
  109. package/dist/rules/stories/groupedOutcomes.js +1 -1
  110. package/dist/rules/stories/groupedOutcomes.js.map +1 -1
  111. package/dist/rules/stories/importBindings.d.ts.map +1 -1
  112. package/dist/rules/stories/importBindings.js +3 -0
  113. package/dist/rules/stories/importBindings.js.map +1 -1
  114. package/dist/rules/unusedCode.d.ts +1 -1
  115. package/dist/rules/unusedCode.d.ts.map +1 -1
  116. package/docs/debt-and-hooks.md +7 -5
  117. package/package.json +3 -3
  118. package/src/adapters/biome/run.ts +4 -4
  119. package/src/adapters/knip/configuration.ts +12 -5
  120. package/src/adapters/knip/run.ts +27 -7
  121. package/src/adapters/knip/sourceConfig.ts +3 -0
  122. package/src/baseline/looseStagedEntries.ts +32 -0
  123. package/src/baseline/update.ts +5 -2
  124. package/src/cli/args.ts +16 -45
  125. package/src/cli/baseline.ts +26 -1
  126. package/src/cli/lint.ts +11 -1
  127. package/src/cli/messages.ts +4 -3
  128. package/src/cli/options.ts +43 -0
  129. package/src/cli/program.ts +3 -2
  130. package/src/hooks/preCommit.ts +1 -1
  131. package/src/imports/classifyRuntime.ts +4 -1
  132. package/src/imports/runtime.ts +19 -21
  133. package/src/inventory/collect.ts +3 -3
  134. package/src/inventory/shadcnFiles.ts +87 -0
  135. package/src/naming/migrationFile.ts +3 -1
  136. package/src/naming/moduleRoot.ts +13 -0
  137. package/src/report/render.ts +3 -10
  138. package/src/report/staleSections.ts +1 -1
  139. package/src/rules/effect/boundary.ts +48 -24
  140. package/src/rules/effect/boundaryCalls.ts +130 -0
  141. package/src/rules/effect/boundaryReference.ts +85 -0
  142. package/src/rules/effect/program.ts +4 -1
  143. package/src/rules/effect/promiseParameter.ts +26 -0
  144. package/src/rules/importOrigins.ts +38 -0
  145. package/src/rules/noBarrel.ts +21 -8
  146. package/src/rules/secondNames.ts +121 -0
  147. package/src/rules/stories/groupedOutcomes.ts +1 -1
  148. package/src/rules/stories/importBindings.ts +3 -0
@@ -1,16 +1,29 @@
1
1
  import { posix } from "node:path";
2
- import { defineRule } from "#rule.ts";
2
+ import { defineRule, type Finding } from "#rule.ts";
3
+ import { parse } from "./parse.ts";
4
+ import { secondNames } from "./secondNames.ts";
3
5
 
4
6
  const BARREL_FILE = /^index\.tsx?$/u;
5
7
 
6
8
  export const noBarrel = defineRule({
7
9
  check: ({ sources }) =>
8
- sources
9
- .filter((file) => BARREL_FILE.test(posix.basename(file.path)))
10
- .map((file) => ({
11
- file: file.path,
12
- message: "index.ts and index.tsx modules are banned. Name the module after its purpose and import it directly.",
13
- })),
14
- description: "Name TypeScript modules after their purpose instead of index.ts or index.tsx.",
10
+ sources.flatMap((file) => {
11
+ const findings: Finding[] = BARREL_FILE.test(posix.basename(file.path))
12
+ ? [{ file: file.path, message: "index.ts and index.tsx modules are banned. Name the module after its purpose and import it directly." }]
13
+ : [];
14
+ const source = parse(file);
15
+ if (source !== undefined) {
16
+ for (const { modules, node } of secondNames(source)) {
17
+ findings.push({
18
+ file: file.path,
19
+ line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
20
+ message: `An exported alias, facade or forwarding function gives an import a second name.\nHelp: Import directly from ${modules.map((module) => `"${module}"`).join(", ")} and remove the second name.`,
21
+ });
22
+ }
23
+ }
24
+ return findings;
25
+ }),
26
+ description:
27
+ "Name modules after their purpose; import values from their defining module instead of exporting aliases, facades or unchanged forwarding calls.",
15
28
  id: "structure/no-barrel",
16
29
  });
@@ -0,0 +1,121 @@
1
+ import ts from "typescript";
2
+ import { importOrigins, originOf } from "./importOrigins.ts";
3
+
4
+ function returned(body: ts.ConciseBody): ts.Expression | undefined {
5
+ if (!ts.isBlock(body)) {
6
+ return body;
7
+ }
8
+ const statement = body.statements.length === 1 ? body.statements[0] : undefined;
9
+ return statement !== undefined && ts.isReturnStatement(statement) ? statement.expression : undefined;
10
+ }
11
+
12
+ function forwarding(node: ts.FunctionLikeDeclaration, origins: ReadonlyMap<string, string>): string | undefined {
13
+ if (
14
+ node.body === undefined
15
+ || node.asteriskToken !== undefined
16
+ || node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword)
17
+ ) {
18
+ return undefined;
19
+ }
20
+ const call = returned(node.body);
21
+ if (call === undefined || !ts.isCallExpression(call) || call.questionDotToken !== undefined || call.arguments.length !== node.parameters.length) {
22
+ return undefined;
23
+ }
24
+ const visible = new Map(origins);
25
+ for (const [index, parameter] of node.parameters.entries()) {
26
+ const argument = call.arguments[index];
27
+ if (!ts.isIdentifier(parameter.name) || parameter.initializer !== undefined || argument === undefined) {
28
+ return undefined;
29
+ }
30
+ const value = ts.isSpreadElement(argument) ? argument.expression : argument;
31
+ if (!ts.isIdentifier(value) || value.text !== parameter.name.text || Boolean(parameter.dotDotDotToken) !== ts.isSpreadElement(argument)) {
32
+ return undefined;
33
+ }
34
+ visible.delete(parameter.name.text);
35
+ }
36
+ return originOf(call.expression, visible);
37
+ }
38
+
39
+ function valueOrigins(node: ts.Expression, origins: ReadonlyMap<string, string>): readonly string[] {
40
+ if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node)) {
41
+ return valueOrigins(node.expression, origins);
42
+ }
43
+ const origin = originOf(node, origins);
44
+ if (origin !== undefined) {
45
+ return [origin];
46
+ }
47
+ if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
48
+ const module = forwarding(node, origins);
49
+ return module === undefined ? [] : [module];
50
+ }
51
+ if (ts.isObjectLiteralExpression(node)) {
52
+ const modules = node.properties.map((property) => {
53
+ if (ts.isShorthandPropertyAssignment(property)) {
54
+ return valueOrigins(property.name, origins);
55
+ }
56
+ if (ts.isPropertyAssignment(property)) {
57
+ return valueOrigins(property.initializer, origins);
58
+ }
59
+ if (ts.isSpreadAssignment(property)) {
60
+ return valueOrigins(property.expression, origins);
61
+ }
62
+ return [];
63
+ });
64
+ return modules.length > 0 && modules.every((module) => module.length > 0) ? modules.flat() : [];
65
+ }
66
+ return [];
67
+ }
68
+
69
+ export interface SecondName {
70
+ readonly modules: readonly string[];
71
+ readonly node: ts.Node;
72
+ }
73
+
74
+ function exportedNames(source: ts.SourceFile): ReadonlySet<string> {
75
+ return new Set(
76
+ source.statements.flatMap((statement) =>
77
+ ts.isExportDeclaration(statement)
78
+ && statement.moduleSpecifier === undefined
79
+ && statement.exportClause !== undefined
80
+ && ts.isNamedExports(statement.exportClause)
81
+ ? statement.exportClause.elements.map((element) => (element.propertyName ?? element.name).text)
82
+ : [],
83
+ ),
84
+ );
85
+ }
86
+
87
+ function declarations(statement: ts.Statement, exported: ReadonlySet<string>): readonly (ts.VariableDeclaration | ts.FunctionDeclaration)[] {
88
+ const publicStatement =
89
+ ts.canHaveModifiers(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
90
+ let nodes: readonly (ts.VariableDeclaration | ts.FunctionDeclaration)[] = [];
91
+ if (ts.isVariableStatement(statement)) {
92
+ nodes = statement.declarationList.declarations;
93
+ } else if (ts.isFunctionDeclaration(statement)) {
94
+ nodes = [statement];
95
+ }
96
+ return nodes.filter((node) => node.name !== undefined && ts.isIdentifier(node.name) && (publicStatement || exported.has(node.name.text)));
97
+ }
98
+
99
+ function declarationOrigins(
100
+ node: ts.VariableDeclaration | ts.FunctionDeclaration,
101
+ origins: ReadonlyMap<string, string>,
102
+ source: ts.SourceFile,
103
+ ): readonly string[] {
104
+ if (ts.isVariableDeclaration(node)) {
105
+ return node.initializer === undefined ? [] : valueOrigins(node.initializer, origins);
106
+ }
107
+ const overloaded = source.statements.some((other) => ts.isFunctionDeclaration(other) && other !== node && other.name?.text === node.name?.text);
108
+ const module = overloaded ? undefined : forwarding(node, origins);
109
+ return module === undefined ? [] : [module];
110
+ }
111
+
112
+ export function secondNames(source: ts.SourceFile): readonly SecondName[] {
113
+ const origins = importOrigins(source);
114
+ const exported = exportedNames(source);
115
+ return source.statements.flatMap((statement) =>
116
+ declarations(statement, exported).flatMap((node) => {
117
+ const modules = declarationOrigins(node, origins, source);
118
+ return modules.length === 0 ? [] : [{ modules: [...new Set(modules)], node }];
119
+ }),
120
+ );
121
+ }
@@ -6,7 +6,7 @@ import { storySources } from "./sources.ts";
6
6
  import { memberName, syntaxFindings, unwrapped } from "./syntax.ts";
7
7
 
8
8
  const MESSAGE =
9
- 'Checks several outcomes with consecutive expect(yield* …) lines. Let the story\'s words lead: yield* outcomes({ "label": [readout, expected], … }) from @shivaedev/test-story/server/outcomes.ts, one row per outcome. Keep a plain expect for a single outcome.';
9
+ 'Checks several outcomes with consecutive expect(yield* …) lines. Let the story\'s words lead: yield* outcomes([["label", () => readout(), expected], …]) from @shivaedev/test-story/server/outcomes.ts, one row per outcome. Keep a plain expect for a single outcome.';
10
10
 
11
11
  const EXPECT_MODULES = ["vitest", "@effect/vitest"];
12
12
 
@@ -15,6 +15,9 @@ export function importBindings(source: ts.SourceFile): ReadonlyMap<string, Impor
15
15
  }
16
16
  const module = statement.moduleSpecifier.text;
17
17
  const clause = statement.importClause;
18
+ if (clause?.name !== undefined) {
19
+ bindings.set(clause.name.text, { imported: "default", module });
20
+ }
18
21
  const named = clause?.namedBindings;
19
22
  if (named !== undefined && ts.isNamespaceImport(named)) {
20
23
  bindings.set(named.name.text, { imported: NAMESPACE, module });