@shivaedev/quality 0.53.1 → 0.54.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 +22 -0
- package/README.md +8 -5
- package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
- package/dist/adapters/knip/entryPointFindings.js +14 -8
- package/dist/adapters/knip/entryPointFindings.js.map +1 -1
- package/dist/biome/recognizeDiagnostics.d.ts.map +1 -1
- package/dist/biome/recognizeDiagnostics.js +4 -5
- package/dist/biome/recognizeDiagnostics.js.map +1 -1
- package/dist/cli/changedRanges.d.ts +2 -0
- package/dist/cli/changedRanges.d.ts.map +1 -0
- package/dist/cli/changedRanges.js +23 -0
- package/dist/cli/changedRanges.js.map +1 -0
- package/dist/cli/fix.d.ts.map +1 -1
- package/dist/cli/fix.js +12 -12
- package/dist/cli/fix.js.map +1 -1
- package/dist/imports/adminBindings.d.ts +8 -0
- package/dist/imports/adminBindings.d.ts.map +1 -0
- package/dist/imports/adminBindings.js +36 -0
- package/dist/imports/adminBindings.js.map +1 -0
- package/dist/imports/adminEvidence.d.ts +6 -0
- package/dist/imports/adminEvidence.d.ts.map +1 -0
- package/dist/imports/adminEvidence.js +46 -0
- package/dist/imports/adminEvidence.js.map +1 -0
- package/dist/imports/adminFindings.d.ts +4 -0
- package/dist/imports/adminFindings.d.ts.map +1 -0
- package/dist/imports/adminFindings.js +55 -0
- package/dist/imports/adminFindings.js.map +1 -0
- package/dist/imports/nodePlatformBarrels.d.ts +3 -0
- package/dist/imports/nodePlatformBarrels.d.ts.map +1 -0
- package/dist/imports/nodePlatformBarrels.js +46 -0
- package/dist/imports/nodePlatformBarrels.js.map +1 -0
- package/dist/naming/ownExports.d.ts +1 -0
- package/dist/naming/ownExports.d.ts.map +1 -1
- package/dist/naming/ownExports.js +4 -1
- package/dist/naming/ownExports.js.map +1 -1
- package/dist/rules/builtIn.d.ts +1 -1
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +2 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/files/namedAfterExport.d.ts.map +1 -1
- package/dist/rules/files/namedAfterExport.js +6 -2
- package/dist/rules/files/namedAfterExport.js.map +1 -1
- package/dist/rules/imports/adminPaths.d.ts +2 -0
- package/dist/rules/imports/adminPaths.d.ts.map +1 -0
- package/dist/rules/imports/adminPaths.js +11 -0
- package/dist/rules/imports/adminPaths.js.map +1 -0
- package/dist/rules/imports/runtime.d.ts.map +1 -1
- package/dist/rules/imports/runtime.js +3 -2
- package/dist/rules/imports/runtime.js.map +1 -1
- package/dist/rules/stories/httpStatus.d.ts.map +1 -1
- package/dist/rules/stories/httpStatus.js +11 -2
- package/dist/rules/stories/httpStatus.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/knip/entryPointFindings.ts +15 -8
- package/src/biome/recognizeDiagnostics.ts +6 -7
- package/src/cli/changedRanges.ts +24 -0
- package/src/cli/fix.ts +13 -14
- package/src/imports/adminBindings.ts +45 -0
- package/src/imports/adminEvidence.ts +52 -0
- package/src/imports/adminFindings.ts +65 -0
- package/src/imports/nodePlatformBarrels.ts +51 -0
- package/src/naming/ownExports.ts +5 -1
- package/src/rules/builtIn.ts +2 -0
- package/src/rules/files/namedAfterExport.ts +6 -2
- package/src/rules/imports/adminPaths.ts +12 -0
- package/src/rules/imports/runtime.ts +3 -2
- package/src/rules/stories/httpStatus.ts +13 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { isTestCode } from "#naming/testName.ts";
|
|
3
|
+
import type { Finding, SourceFile } from "#rule.ts";
|
|
4
|
+
import { parse } from "#rules/parse.ts";
|
|
5
|
+
import { specifierSites } from "./specifiers.ts";
|
|
6
|
+
|
|
7
|
+
const BARREL = "@effect/platform-node";
|
|
8
|
+
|
|
9
|
+
function subpaths(source: ts.SourceFile, start: number): readonly string[] | undefined {
|
|
10
|
+
const statement = source.statements.find((node) => node.pos <= start && node.end > start);
|
|
11
|
+
const bindings = statement !== undefined && ts.isImportDeclaration(statement) ? statement.importClause?.namedBindings : undefined;
|
|
12
|
+
if (bindings !== undefined && ts.isNamedImports(bindings)) {
|
|
13
|
+
const values = bindings.elements.filter((element) => !element.isTypeOnly);
|
|
14
|
+
return values.length === 0 && bindings.elements.length > 0
|
|
15
|
+
? undefined
|
|
16
|
+
: values.map((element) => `${BARREL}/${(element.propertyName ?? element.name).text}`);
|
|
17
|
+
}
|
|
18
|
+
if (
|
|
19
|
+
statement !== undefined
|
|
20
|
+
&& ts.isExportDeclaration(statement)
|
|
21
|
+
&& statement.exportClause !== undefined
|
|
22
|
+
&& ts.isNamedExports(statement.exportClause)
|
|
23
|
+
&& statement.exportClause.elements.every((element) => element.isTypeOnly)
|
|
24
|
+
) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function nodePlatformBarrels(file: SourceFile): readonly Finding[] {
|
|
31
|
+
const source = isTestCode(file.path) ? undefined : parse(file);
|
|
32
|
+
if (source === undefined || source.isDeclarationFile) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return specifierSites(source)
|
|
36
|
+
.filter((site) => site.specifier === BARREL && !site.type)
|
|
37
|
+
.flatMap((site) => {
|
|
38
|
+
const paths = subpaths(source, site.start);
|
|
39
|
+
if (paths === undefined) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
file: file.path,
|
|
45
|
+
line: site.line,
|
|
46
|
+
message: `The ${BARREL} barrel loads optional integrations such as redis. Import module subpaths instead: ${paths.length > 0 ? paths.map((path) => `\`import * as ${path.slice(path.lastIndexOf("/") + 1)} from "${path}"\``).join("; ") : `\`import * as NodeServices from "${BARREL}/NodeServices"\` (choose the module you use)`}.`,
|
|
47
|
+
subject: BARREL,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
});
|
|
51
|
+
}
|
package/src/naming/ownExports.ts
CHANGED
|
@@ -61,8 +61,12 @@ function declared(statement: ts.Statement): readonly OwnExport[] {
|
|
|
61
61
|
return named !== undefined && ts.isIdentifier(named) ? [{ constant: false, kind: "value", name: named.text }] : [];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
export function ownDeclarations(source: ts.SourceFile): readonly OwnExport[] {
|
|
65
|
+
return source.statements.flatMap(declared);
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
function locals(source: ts.SourceFile): ReadonlyMap<string, OwnExport> {
|
|
65
|
-
const all = source
|
|
69
|
+
const all = ownDeclarations(source);
|
|
66
70
|
return new Map(all.map((local) => [local.name, local]));
|
|
67
71
|
}
|
|
68
72
|
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { distinctCase } from "#rules/files/distinctCase.ts";
|
|
|
14
14
|
import { folderNames } from "#rules/files/folderNames.ts";
|
|
15
15
|
import { namedAfterExport } from "#rules/files/namedAfterExport.ts";
|
|
16
16
|
import { otherNames } from "#rules/files/otherNames.ts";
|
|
17
|
+
import { adminPaths } from "#rules/imports/adminPaths.ts";
|
|
17
18
|
import { importsAliased } from "#rules/imports/aliased.ts";
|
|
18
19
|
import { importCycles } from "#rules/imports/cycles.ts";
|
|
19
20
|
import { importFences } from "#rules/imports/fences.ts";
|
|
@@ -83,6 +84,7 @@ export const builtInRules = [
|
|
|
83
84
|
importsResolvable,
|
|
84
85
|
importsManifest,
|
|
85
86
|
importsAliased,
|
|
87
|
+
adminPaths,
|
|
86
88
|
noTestCode,
|
|
87
89
|
manifestsValid,
|
|
88
90
|
manifestsSorted,
|
|
@@ -6,7 +6,7 @@ import { exportFits } from "#naming/exportFits.ts";
|
|
|
6
6
|
import { mainExport } from "#naming/mainExport.ts";
|
|
7
7
|
import { isMigrationFile } from "#naming/migrationFile.ts";
|
|
8
8
|
import { moduleRoot } from "#naming/moduleRoot.ts";
|
|
9
|
-
import { ownExports } from "#naming/ownExports.ts";
|
|
9
|
+
import { ownDeclarations, ownExports } from "#naming/ownExports.ts";
|
|
10
10
|
import { type PackageLayout, packageLayout } from "#naming/packageLayout.ts";
|
|
11
11
|
import { CAMEL, KEBAB, sameWord, wordsOf } from "#naming/words.ts";
|
|
12
12
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
@@ -48,6 +48,10 @@ function repeated(stem: string, folders: readonly string[]): string | undefined
|
|
|
48
48
|
function nameFinding(file: SourceFile, stem: string, folders: readonly string[]): string | undefined {
|
|
49
49
|
const source = parse(file);
|
|
50
50
|
const exports = source === undefined ? [] : ownExports(source);
|
|
51
|
+
const constants = source === undefined ? [] : ownDeclarations(source).filter((entry) => entry.constant);
|
|
52
|
+
if (constants.some((entry) => exportFits(entry.name, stem, folders))) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
51
55
|
const [only] = exports;
|
|
52
56
|
if (only === undefined) {
|
|
53
57
|
return CAMEL.test(stem)
|
|
@@ -93,7 +97,7 @@ export const namedAfterExport = defineRule({
|
|
|
93
97
|
.flatMap((file) => findingsOf(file, layout));
|
|
94
98
|
},
|
|
95
99
|
description:
|
|
96
|
-
"A file is named after its main export, including a
|
|
100
|
+
"A file is named after its main export or a module-level constant, including a private constant, with its folders as the prefix; module client/admin and server/admin files may repeat names from above the admin folder. A file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
|
|
97
101
|
id: "files/named-after-export",
|
|
98
102
|
options: Schema.toStandardSchemaV1(NamedAfterExportOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
99
103
|
validate: validateGlobs,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { adminFindings } from "#imports/adminFindings.ts";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
4
|
+
import { defineRule } from "#rule.ts";
|
|
5
|
+
|
|
6
|
+
export const adminPaths = defineRule({
|
|
7
|
+
check: (inputs) => Effect.promise(() => importGraph(inputs)).pipe(Effect.map((graph) => adminFindings(graph, inputs.sources))),
|
|
8
|
+
description:
|
|
9
|
+
"Admin-only source files live under an admin/ segment; member code cannot reach admin/ implementations. Registration and module composition may import admin registrations and declarations. Move the file to the folder named by the finding.",
|
|
10
|
+
id: "imports/admin-paths",
|
|
11
|
+
registrable: false,
|
|
12
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { type ImportGraph, importGraph } from "#imports/graph.ts";
|
|
3
|
+
import { nodePlatformBarrels } from "#imports/nodePlatformBarrels.ts";
|
|
3
4
|
import { builtinName } from "#imports/packageName.ts";
|
|
4
5
|
import { type Runtime, runtimeDeclarationProblems, runtimeOf } from "#imports/runtime.ts";
|
|
5
6
|
import { isTestCode } from "#naming/testName.ts";
|
|
@@ -39,7 +40,7 @@ export const importsRuntime = defineRule({
|
|
|
39
40
|
Effect.gen(function* () {
|
|
40
41
|
const graph = yield* Effect.promise(() => importGraph(inputs));
|
|
41
42
|
const runtime = yield* runtimeOf(inputs, graph.packages);
|
|
42
|
-
const imports = runtimeFindings(graph, runtime);
|
|
43
|
+
const imports = [...runtimeFindings(graph, runtime), ...inputs.sources.flatMap(nodePlatformBarrels)];
|
|
43
44
|
const declarations = (yield* runtimeDeclarationProblems(inputs, graph.packages)).map(({ directory, message }) => ({
|
|
44
45
|
file: directory === "." ? "package.json" : `${directory}/package.json`,
|
|
45
46
|
line: 1,
|
|
@@ -54,6 +55,6 @@ export const importsRuntime = defineRule({
|
|
|
54
55
|
return [...imports, ...declarations, ...shared.flatMap(browserGlobals)];
|
|
55
56
|
}),
|
|
56
57
|
description:
|
|
57
|
-
"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.",
|
|
58
|
+
"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. Production imports use @effect/platform-node module subpaths so its barrel does not load optional integrations.",
|
|
58
59
|
id: "imports/runtime",
|
|
59
60
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { matchesGlob } from "node:path";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
+
import * as HttpStatus from "effect/http/HttpStatus";
|
|
3
4
|
import ts from "typescript";
|
|
4
5
|
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
5
6
|
import { defineRule } from "#rule.ts";
|
|
@@ -25,8 +26,18 @@ const COMPARISONS = new Set([
|
|
|
25
26
|
]);
|
|
26
27
|
|
|
27
28
|
function isErrorStatus(node: ts.Expression): boolean {
|
|
28
|
-
const
|
|
29
|
-
|
|
29
|
+
const value = unwrapped(node);
|
|
30
|
+
const literal =
|
|
31
|
+
ts.isCallExpression(value)
|
|
32
|
+
&& ts.isPropertyAccessExpression(value.expression)
|
|
33
|
+
&& ts.isIdentifier(value.expression.expression)
|
|
34
|
+
&& value.expression.expression.text === "HttpStatus"
|
|
35
|
+
&& value.expression.name.text === "fromLiteral"
|
|
36
|
+
? value.arguments[0]
|
|
37
|
+
: undefined;
|
|
38
|
+
const number: unknown =
|
|
39
|
+
literal !== undefined && ts.isStringLiteralLike(literal) ? Reflect.apply(HttpStatus.fromLiteral, undefined, [literal.text]) : numericValue(value);
|
|
40
|
+
return typeof number === "number" && number >= 400 && number <= 599;
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
function statusBranch(node: ts.Node): boolean {
|