@venizia/dev-configs 0.5.0-8 → 0.5.0-9
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/README.md +15 -11
- package/dist/checks/purity/manifest.js +11 -3
- package/dist/checks/purity/manifest.js.map +1 -1
- package/dist/checks/purity/probe.js +19 -2
- package/dist/checks/purity/probe.js.map +1 -1
- package/dist/checks/split-report.js +2 -1
- package/dist/checks/split-report.js.map +1 -1
- package/dist/checks/test-controls.d.ts +9 -1
- package/dist/checks/test-controls.js +9 -3
- package/dist/checks/test-controls.js.map +1 -1
- package/dist/checks/test-dead-code.d.ts +9 -1
- package/dist/checks/test-dead-code.js +13 -2
- package/dist/checks/test-dead-code.js.map +1 -1
- package/dist/checks/test-mutate.d.ts +9 -1
- package/dist/checks/test-mutate.js +12 -6
- package/dist/checks/test-mutate.js.map +1 -1
- package/dist/cli/check.d.ts +0 -1
- package/dist/cli/check.js +41 -67
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/clean.js +3 -2
- package/dist/cli/clean.js.map +1 -1
- package/dist/cli/codemod/any-aliases.js +13 -12
- package/dist/cli/codemod/any-aliases.js.map +1 -1
- package/dist/cli/codemod/async-style.d.ts +1 -1
- package/dist/cli/codemod/async-style.js +17 -16
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.js +14 -13
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +1 -1
- package/dist/cli/codemod/class-renames.js +30 -11
- package/dist/cli/codemod/class-renames.js.map +1 -1
- package/dist/cli/codemod/connector-imports.js +12 -11
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-classes.d.ts +1 -1
- package/dist/cli/codemod/const-classes.js +21 -20
- package/dist/cli/codemod/const-classes.js.map +1 -1
- package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
- package/dist/cli/codemod/drop-redundant-casts.js +27 -19
- package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
- package/dist/cli/codemod/env-get.d.ts +3 -3
- package/dist/cli/codemod/env-get.js +18 -17
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.js +2 -2
- package/dist/cli/codemod/files.js.map +1 -1
- package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
- package/dist/cli/codemod/function-to-arrow.js +357 -0
- package/dist/cli/codemod/function-to-arrow.js.map +1 -0
- package/dist/cli/codemod/index.js +19 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +13 -12
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +27 -0
- package/dist/cli/codemod/typed-route-context.js +570 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/common/cli-output.d.ts +16 -0
- package/dist/common/cli-output.js +49 -0
- package/dist/common/cli-output.js.map +1 -0
- package/dist/compilers/bun.js +1 -1
- package/dist/compilers/bun.js.map +1 -1
- package/dist/linters/eslint.js +1 -1
- package/dist/linters/eslint.js.map +1 -1
- package/dist/linters/house/browser-api-patterns.d.ts +1 -3
- package/dist/linters/house/browser-api-patterns.js +1 -3
- package/dist/linters/house/browser-api-patterns.js.map +1 -1
- package/dist/linters/house/common.d.ts +8 -2
- package/dist/linters/house/common.js +8 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +8 -6
- package/dist/linters/house/configs.js.map +1 -1
- package/dist/linters/house/const-class-values.rule.d.ts +2 -2
- package/dist/linters/house/const-class-values.rule.js +14 -5
- package/dist/linters/house/const-class-values.rule.js.map +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
- package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
- package/dist/linters/house/framework-api-patterns.d.ts +54 -0
- package/dist/linters/house/framework-api-patterns.js +62 -0
- package/dist/linters/house/framework-api-patterns.js.map +1 -0
- package/dist/linters/house/framework-exports.js +3 -3
- package/dist/linters/house/framework-exports.js.map +1 -1
- package/dist/linters/house/index.d.ts +3 -4
- package/dist/linters/house/index.js +4 -6
- package/dist/linters/house/index.js.map +1 -1
- package/dist/linters/house/max-params-own.rule.d.ts +2 -2
- package/dist/linters/house/max-params-own.rule.js +1 -1
- package/dist/linters/house/max-params-own.rule.js.map +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
- package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
- package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-new-chain.rule.js +1 -1
- package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
- package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-promise-chain.rule.js +1 -1
- package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
- package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
- package/dist/linters/house/no-inline-await.rule.js +1 -1
- package/dist/linters/house/no-inline-await.rule.js.map +1 -1
- package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
- package/dist/linters/house/no-leaked-render.rule.js +1 -1
- package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
- package/dist/linters/house/no-new-error.rule.d.ts +2 -2
- package/dist/linters/house/no-new-error.rule.js +2 -2
- package/dist/linters/house/no-new-error.rule.js.map +1 -1
- package/dist/linters/house/no-parent-import.rule.d.ts +5 -2
- package/dist/linters/house/no-parent-import.rule.js +5 -2
- package/dist/linters/house/no-parent-import.rule.js.map +1 -1
- package/dist/linters/house/no-return-await.rule.d.ts +2 -2
- package/dist/linters/house/no-return-await.rule.js +1 -1
- package/dist/linters/house/no-return-await.rule.js.map +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.d.ts +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
- package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
- package/dist/linters/house/no-silent-catch.rule.js +3 -3
- package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
- package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
- package/dist/linters/house/no-unbraced-case.rule.js +1 -1
- package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
- package/dist/linters/house/plugin.d.ts +1 -1
- package/dist/linters/house/plugin.js +6 -5
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +39 -7
- package/dist/linters/house/prefer-framework-api.rule.js +285 -12
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -1
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +2 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js +3 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -1
- package/dist/linters/house/prefer-tnullable.rule.d.ts +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -1
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +322 -0
- package/dist/linters/house/typed-route-context.rule.js.map +1 -0
- package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
- package/dist/linters/house/zod-schema-convention.rule.js +477 -0
- package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
- package/dist/linters/oxlint.js +11 -1
- package/dist/linters/oxlint.js.map +1 -1
- package/dist/linters/react-eslint.js.map +1 -1
- package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
- package/dist/linters/rules/naming-convention.rule.js +30 -1
- package/dist/linters/rules/naming-convention.rule.js.map +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
- package/dist/testing/spawn.utility.js +1 -1
- package/dist/testing/spawn.utility.js.map +1 -1
- package/package.json +5 -5
- package/dist/checks/use-when-baseline.d.ts +0 -25
- package/dist/checks/use-when-baseline.js +0 -38
- package/dist/checks/use-when-baseline.js.map +0 -1
- package/dist/linters/house/framework-rule-apis.d.ts +0 -24
- package/dist/linters/house/framework-rule-apis.js +0 -48
- package/dist/linters/house/framework-rule-apis.js.map +0 -1
- package/dist/linters/house/public-surface.d.ts +0 -57
- package/dist/linters/house/public-surface.js +0 -174
- package/dist/linters/house/public-surface.js.map +0 -1
- package/dist/linters/house/published-package-configs.d.ts +0 -23
- package/dist/linters/house/published-package-configs.js +0 -42
- package/dist/linters/house/published-package-configs.js.map +0 -1
- package/dist/linters/house/require-use-when.rule.d.ts +0 -42
- package/dist/linters/house/require-use-when.rule.js +0 -175
- package/dist/linters/house/require-use-when.rule.js.map +0 -1
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/** One export of a package's public entry points, and what its TSDoc says. */
|
|
2
|
-
export interface IPublicExport {
|
|
3
|
-
/** The exported name. */
|
|
4
|
-
name: string;
|
|
5
|
-
/** Whether it is a value (class, function, const, enum, namespace) or a type (interface, type alias). */
|
|
6
|
-
isValue: boolean;
|
|
7
|
-
/** Absolute path of the file that declares it (for `export * as X`, the file that holds the statement). */
|
|
8
|
-
file: string;
|
|
9
|
-
/** Character offsets of the declaring name. */
|
|
10
|
-
start: number;
|
|
11
|
-
end: number;
|
|
12
|
-
/** `@useWhen` is there and says something. */
|
|
13
|
-
hasUseWhen: boolean;
|
|
14
|
-
/** `@insteadOf` is there and says nothing. */
|
|
15
|
-
hasEmptyInsteadOf: boolean;
|
|
16
|
-
}
|
|
17
|
-
/** What one source file contributes to the public surface, with the text the offsets are valid for. */
|
|
18
|
-
export interface IPublicFile {
|
|
19
|
-
/** The text the scan read: the offsets below mean nothing for any other text of the same file. */
|
|
20
|
-
text: string;
|
|
21
|
-
exports: Array<IPublicExport>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The public surface of one package: what its entry points export, read with the TypeScript checker over the entry files
|
|
25
|
-
* only (own symbols; what a package re-exports from another is that package's to document). Built once per package and
|
|
26
|
-
* memoized for the run, so a lint run pays for one program per package.
|
|
27
|
-
*
|
|
28
|
-
* Entries are the `exports` of package.json mapped back to source (`./dist/esm/x.d.ts` is `src/x.ts`), or the `entries`
|
|
29
|
-
* the project names.
|
|
30
|
-
*/
|
|
31
|
-
export declare class PublicSurface {
|
|
32
|
-
static readonly USE_WHEN = "useWhen";
|
|
33
|
-
static readonly INSTEAD_OF = "insteadOf";
|
|
34
|
-
private static readonly surfaces;
|
|
35
|
-
/** The source file an `exports` declaration path stands for: `./dist/esm/a/index.d.ts` is `src/a/index.ts` (or `.tsx`). */
|
|
36
|
-
private static sourceOf;
|
|
37
|
-
/** The strings in an `exports` value that name a declaration or a source file. */
|
|
38
|
-
private static pathsIn;
|
|
39
|
-
/** The entry source files of the package at `directory`. */
|
|
40
|
-
private static entriesOf;
|
|
41
|
-
/** The compiler options of the nearest tsconfig.json, for `paths` aliases. */
|
|
42
|
-
private static optionsFor;
|
|
43
|
-
/** The tag texts of `name` on `symbol`, read through the checker and, for an `export * as X` statement, from the statement. */
|
|
44
|
-
private static tagsOf;
|
|
45
|
-
/** Every export of the entries of the package at `directory`, each once, that the package itself declares. */
|
|
46
|
-
private static scan;
|
|
47
|
-
/** The exports of the package at `directory`, by the file that declares them. */
|
|
48
|
-
static of(opts: {
|
|
49
|
-
directory: string;
|
|
50
|
-
entries?: ReadonlyArray<string>;
|
|
51
|
-
}): Map<string, IPublicFile>;
|
|
52
|
-
/** The package folder of `file`: where the nearest package.json is. */
|
|
53
|
-
static packageOf(opts: {
|
|
54
|
-
file: string;
|
|
55
|
-
}): string | undefined;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=public-surface.d.ts.map
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PublicSurface = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const common_1 = require("./common");
|
|
7
|
-
const framework_exports_1 = require("./framework-exports");
|
|
8
|
-
/**
|
|
9
|
-
* The public surface of one package: what its entry points export, read with the TypeScript checker over the entry files
|
|
10
|
-
* only (own symbols; what a package re-exports from another is that package's to document). Built once per package and
|
|
11
|
-
* memoized for the run, so a lint run pays for one program per package.
|
|
12
|
-
*
|
|
13
|
-
* Entries are the `exports` of package.json mapped back to source (`./dist/esm/x.d.ts` is `src/x.ts`), or the `entries`
|
|
14
|
-
* the project names.
|
|
15
|
-
*/
|
|
16
|
-
class PublicSurface {
|
|
17
|
-
static { this.USE_WHEN = 'useWhen'; }
|
|
18
|
-
static { this.INSTEAD_OF = 'insteadOf'; }
|
|
19
|
-
static { this.surfaces = new Map(); }
|
|
20
|
-
/** The source file an `exports` declaration path stands for: `./dist/esm/a/index.d.ts` is `src/a/index.ts` (or `.tsx`). */
|
|
21
|
-
static sourceOf(opts) {
|
|
22
|
-
const stripped = opts.declaration
|
|
23
|
-
.replace(/^\.\//, '')
|
|
24
|
-
.replace(/^dist\//, '')
|
|
25
|
-
.replace(/^(?:esm|cjs|types)\//, '')
|
|
26
|
-
.replace(/\.d\.[cm]?ts$/, '');
|
|
27
|
-
return [`${stripped}.ts`, `${stripped}.tsx`]
|
|
28
|
-
.map((file) => (0, node_path_1.join)(opts.directory, 'src', file))
|
|
29
|
-
.find((file) => (0, node_fs_1.existsSync)(file));
|
|
30
|
-
}
|
|
31
|
-
/** The strings in an `exports` value that name a declaration or a source file. */
|
|
32
|
-
static pathsIn(opts) {
|
|
33
|
-
const { value } = opts;
|
|
34
|
-
if (typeof value === 'string') {
|
|
35
|
-
return /\.(?:d\.[cm]?ts|tsx?)$/.test(value) ? [value] : [];
|
|
36
|
-
}
|
|
37
|
-
return typeof value === 'object' && value !== null
|
|
38
|
-
? Object.values(value).flatMap((entry) => PublicSurface.pathsIn({ value: entry }))
|
|
39
|
-
: [];
|
|
40
|
-
}
|
|
41
|
-
/** The entry source files of the package at `directory`. */
|
|
42
|
-
static entriesOf(opts) {
|
|
43
|
-
const { directory, entries } = opts;
|
|
44
|
-
if (entries) {
|
|
45
|
-
return entries.map((entry) => (0, node_path_1.resolve)(directory, entry)).filter((file) => (0, node_fs_1.existsSync)(file));
|
|
46
|
-
}
|
|
47
|
-
const text = (0, node_fs_1.existsSync)((0, node_path_1.join)(directory, 'package.json'))
|
|
48
|
-
? (0, node_fs_1.readFileSync)((0, node_path_1.join)(directory, 'package.json'), 'utf8')
|
|
49
|
-
: '{}';
|
|
50
|
-
let manifest;
|
|
51
|
-
try {
|
|
52
|
-
manifest = JSON.parse(text);
|
|
53
|
-
// eslint-disable-next-line venizia/no-silent-catch -- a package.json that does not parse has no entries to read
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
manifest = undefined;
|
|
57
|
-
}
|
|
58
|
-
// A package that ships its source names `.ts` files in `exports` (`./src/index.ts`); a built one names `.d.ts` files.
|
|
59
|
-
const files = PublicSurface.pathsIn({
|
|
60
|
-
value: common_1.AstNode.readField({ node: manifest, key: 'exports' }),
|
|
61
|
-
})
|
|
62
|
-
.map((path) => /\.d\.[cm]?ts$/.test(path)
|
|
63
|
-
? PublicSurface.sourceOf({ directory, declaration: path })
|
|
64
|
-
: [(0, node_path_1.resolve)(directory, path)].find((file) => (0, node_fs_1.existsSync)(file)))
|
|
65
|
-
.filter((file) => file !== undefined);
|
|
66
|
-
return [...new Set(files)];
|
|
67
|
-
}
|
|
68
|
-
/** The compiler options of the nearest tsconfig.json, for `paths` aliases. */
|
|
69
|
-
static optionsFor(opts) {
|
|
70
|
-
const { typescript, directory } = opts;
|
|
71
|
-
const configPath = typescript.findConfigFile(directory, typescript.sys.fileExists);
|
|
72
|
-
const parsed = configPath
|
|
73
|
-
? typescript.parseJsonConfigFileContent(typescript.readConfigFile(configPath, typescript.sys.readFile).config, typescript.sys, (0, node_path_1.dirname)(configPath)).options
|
|
74
|
-
: {};
|
|
75
|
-
return { ...parsed, noEmit: true, skipLibCheck: true, allowJs: false };
|
|
76
|
-
}
|
|
77
|
-
/** The tag texts of `name` on `symbol`, read through the checker and, for an `export * as X` statement, from the statement. */
|
|
78
|
-
static tagsOf(opts) {
|
|
79
|
-
const { typescript, checker, symbol, target } = opts;
|
|
80
|
-
const tags = new Map();
|
|
81
|
-
const collect = (list) => {
|
|
82
|
-
for (const tag of list) {
|
|
83
|
-
tags.set(tag.name, typescript.displayPartsToString(tag.text).trim());
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
collect(target.getJsDocTags(checker));
|
|
87
|
-
collect(symbol.getJsDocTags(checker));
|
|
88
|
-
for (const declaration of symbol.declarations ?? []) {
|
|
89
|
-
const statement = typescript.isNamespaceExport(declaration) ? declaration.parent : undefined;
|
|
90
|
-
if (statement) {
|
|
91
|
-
for (const tag of typescript.getJSDocTags(statement)) {
|
|
92
|
-
tags.set(tag.tagName.text, typescript.getTextOfJSDocComment(tag.comment)?.trim() ?? '');
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return tags;
|
|
97
|
-
}
|
|
98
|
-
/** Every export of the entries of the package at `directory`, each once, that the package itself declares. */
|
|
99
|
-
static scan(opts) {
|
|
100
|
-
const { directory, entries } = opts;
|
|
101
|
-
const byFile = new Map();
|
|
102
|
-
const typescript = framework_exports_1.FrameworkExports.loadTypeScript({ directory });
|
|
103
|
-
const roots = PublicSurface.entriesOf({ directory, entries });
|
|
104
|
-
if (!typescript || roots.length === 0) {
|
|
105
|
-
return byFile;
|
|
106
|
-
}
|
|
107
|
-
const program = typescript.createProgram(roots, PublicSurface.optionsFor({ typescript, directory }));
|
|
108
|
-
const checker = program.getTypeChecker();
|
|
109
|
-
const seen = new Set();
|
|
110
|
-
const inside = (file) => !file.endsWith('.d.ts') &&
|
|
111
|
-
!file.split(node_path_1.sep).includes('node_modules') &&
|
|
112
|
-
(0, node_path_1.relative)(directory, file).startsWith('..') === false;
|
|
113
|
-
const valueFlags = typescript.SymbolFlags.Class |
|
|
114
|
-
typescript.SymbolFlags.Function |
|
|
115
|
-
typescript.SymbolFlags.Variable |
|
|
116
|
-
typescript.SymbolFlags.Enum |
|
|
117
|
-
typescript.SymbolFlags.ValueModule |
|
|
118
|
-
typescript.SymbolFlags.NamespaceModule;
|
|
119
|
-
for (const root of roots) {
|
|
120
|
-
const source = program.getSourceFile(root);
|
|
121
|
-
const module = source ? checker.getSymbolAtLocation(source) : undefined;
|
|
122
|
-
if (!module) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
for (const symbol of checker.getExportsOfModule(module)) {
|
|
126
|
-
const isAlias = (symbol.flags & typescript.SymbolFlags.Alias) !== 0;
|
|
127
|
-
const target = isAlias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
128
|
-
const namespaceExport = (symbol.declarations ?? []).find((declaration) => typescript.isNamespaceExport(declaration));
|
|
129
|
-
const site = namespaceExport ?? target.declarations?.[0];
|
|
130
|
-
const file = site?.getSourceFile().fileName;
|
|
131
|
-
if (!site || !file || !inside(file)) {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
const name = symbol.getName();
|
|
135
|
-
const key = `${file}#${name}`;
|
|
136
|
-
if (seen.has(key)) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
seen.add(key);
|
|
140
|
-
const tags = PublicSurface.tagsOf({ typescript, checker, symbol, target });
|
|
141
|
-
const named = typescript.getNameOfDeclaration(site) ?? site;
|
|
142
|
-
const entry = byFile.get(file) ?? { text: site.getSourceFile().text, exports: [] };
|
|
143
|
-
entry.exports.push({
|
|
144
|
-
name,
|
|
145
|
-
isValue: namespaceExport !== undefined || (target.flags & valueFlags) !== 0,
|
|
146
|
-
file,
|
|
147
|
-
start: named.getStart(),
|
|
148
|
-
end: named.getEnd(),
|
|
149
|
-
hasUseWhen: (tags.get(PublicSurface.USE_WHEN) ?? '').length > 0,
|
|
150
|
-
hasEmptyInsteadOf: tags.get(PublicSurface.INSTEAD_OF) === '',
|
|
151
|
-
});
|
|
152
|
-
byFile.set(file, entry);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return byFile;
|
|
156
|
-
}
|
|
157
|
-
/** The exports of the package at `directory`, by the file that declares them. */
|
|
158
|
-
static of(opts) {
|
|
159
|
-
const key = `${opts.directory}|${(opts.entries ?? []).join(',')}`;
|
|
160
|
-
const cached = PublicSurface.surfaces.get(key);
|
|
161
|
-
if (cached) {
|
|
162
|
-
return cached;
|
|
163
|
-
}
|
|
164
|
-
const surface = PublicSurface.scan({ directory: opts.directory, entries: opts.entries });
|
|
165
|
-
PublicSurface.surfaces.set(key, surface);
|
|
166
|
-
return surface;
|
|
167
|
-
}
|
|
168
|
-
/** The package folder of `file`: where the nearest package.json is. */
|
|
169
|
-
static packageOf(opts) {
|
|
170
|
-
return framework_exports_1.FrameworkExports.manifestFor({ directory: (0, node_path_1.dirname)(opts.file) })?.directory;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.PublicSurface = PublicSurface;
|
|
174
|
-
//# sourceMappingURL=public-surface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public-surface.js","sourceRoot":"","sources":["../../../src/linters/house/public-surface.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAAkE;AAElE,qCAAmC;AACnC,2DAAuD;AA0BvD;;;;;;;GAOG;AACH,MAAa,aAAa;aACR,aAAQ,GAAG,SAAS,CAAC;aACrB,eAAU,GAAG,WAAW,CAAC;aAEjB,aAAQ,GAAG,IAAI,GAAG,EAAoC,CAAC;IAE/E,2HAA2H;IACnH,MAAM,CAAC,QAAQ,CAAC,IAAgD;QACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW;aAC9B,OAAO,CAAC,OAAO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C;oBAC/D,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE;iBAC7D,CAAC,CAAC;gBACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iFAAiF;IACjF,MAAM,CAAC,EAAE,CAAC,IAGT;QACC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACzF,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,uEAAuE;IACvE,MAAM,CAAC,SAAS,CAAC,IAAsB;QACrC,OAAO,oCAAgB,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,IAAA,mBAAO,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC;IACpF,CAAC;;AA9NH,sCA+NC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport type ts from 'typescript';\nimport { AstNode } from './common';\nimport { FrameworkExports } from './framework-exports';\n\n/** One export of a package's public entry points, and what its TSDoc says. */\nexport interface IPublicExport {\n /** The exported name. */\n name: string;\n /** Whether it is a value (class, function, const, enum, namespace) or a type (interface, type alias). */\n isValue: boolean;\n /** Absolute path of the file that declares it (for `export * as X`, the file that holds the statement). */\n file: string;\n /** Character offsets of the declaring name. */\n start: number;\n end: number;\n /** `@useWhen` is there and says something. */\n hasUseWhen: boolean;\n /** `@insteadOf` is there and says nothing. */\n hasEmptyInsteadOf: boolean;\n}\n\n/** What one source file contributes to the public surface, with the text the offsets are valid for. */\nexport interface IPublicFile {\n /** The text the scan read: the offsets below mean nothing for any other text of the same file. */\n text: string;\n exports: Array<IPublicExport>;\n}\n\n/**\n * The public surface of one package: what its entry points export, read with the TypeScript checker over the entry files\n * only (own symbols; what a package re-exports from another is that package's to document). Built once per package and\n * memoized for the run, so a lint run pays for one program per package.\n *\n * Entries are the `exports` of package.json mapped back to source (`./dist/esm/x.d.ts` is `src/x.ts`), or the `entries`\n * the project names.\n */\nexport class PublicSurface {\n static readonly USE_WHEN = 'useWhen';\n static readonly INSTEAD_OF = 'insteadOf';\n\n private static readonly surfaces = new Map<string, Map<string, IPublicFile>>();\n\n /** The source file an `exports` declaration path stands for: `./dist/esm/a/index.d.ts` is `src/a/index.ts` (or `.tsx`). */\n private static sourceOf(opts: { directory: string; declaration: string }): string | undefined {\n const stripped = opts.declaration\n .replace(/^\\.\\//, '')\n .replace(/^dist\\//, '')\n .replace(/^(?:esm|cjs|types)\\//, '')\n .replace(/\\.d\\.[cm]?ts$/, '');\n\n return [`${stripped}.ts`, `${stripped}.tsx`]\n .map((file) => join(opts.directory, 'src', file))\n .find((file) => existsSync(file));\n }\n\n /** The strings in an `exports` value that name a declaration or a source file. */\n private static pathsIn(opts: { value: unknown }): Array<string> {\n const { value } = opts;\n\n if (typeof value === 'string') {\n return /\\.(?:d\\.[cm]?ts|tsx?)$/.test(value) ? [value] : [];\n }\n\n return typeof value === 'object' && value !== null\n ? Object.values(value).flatMap((entry) => PublicSurface.pathsIn({ value: entry }))\n : [];\n }\n\n /** The entry source files of the package at `directory`. */\n private static entriesOf(opts: {\n directory: string;\n entries: ReadonlyArray<string> | undefined;\n }): Array<string> {\n const { directory, entries } = opts;\n\n if (entries) {\n return entries.map((entry) => resolve(directory, entry)).filter((file) => existsSync(file));\n }\n\n const text = existsSync(join(directory, 'package.json'))\n ? readFileSync(join(directory, 'package.json'), 'utf8')\n : '{}';\n let manifest: unknown;\n\n try {\n manifest = JSON.parse(text);\n // eslint-disable-next-line venizia/no-silent-catch -- a package.json that does not parse has no entries to read\n } catch {\n manifest = undefined;\n }\n\n // A package that ships its source names `.ts` files in `exports` (`./src/index.ts`); a built one names `.d.ts` files.\n const files = PublicSurface.pathsIn({\n value: AstNode.readField({ node: manifest, key: 'exports' }),\n })\n .map((path) =>\n /\\.d\\.[cm]?ts$/.test(path)\n ? PublicSurface.sourceOf({ directory, declaration: path })\n : [resolve(directory, path)].find((file) => existsSync(file)),\n )\n .filter((file): file is string => file !== undefined);\n\n return [...new Set(files)];\n }\n\n /** The compiler options of the nearest tsconfig.json, for `paths` aliases. */\n private static optionsFor(opts: {\n typescript: typeof ts;\n directory: string;\n }): ts.CompilerOptions {\n const { typescript, directory } = opts;\n const configPath = typescript.findConfigFile(directory, typescript.sys.fileExists);\n const parsed = configPath\n ? typescript.parseJsonConfigFileContent(\n typescript.readConfigFile(configPath, typescript.sys.readFile).config,\n typescript.sys,\n dirname(configPath),\n ).options\n : {};\n\n return { ...parsed, noEmit: true, skipLibCheck: true, allowJs: false };\n }\n\n /** The tag texts of `name` on `symbol`, read through the checker and, for an `export * as X` statement, from the statement. */\n private static tagsOf(opts: {\n typescript: typeof ts;\n checker: ts.TypeChecker;\n symbol: ts.Symbol;\n target: ts.Symbol;\n }): Map<string, string> {\n const { typescript, checker, symbol, target } = opts;\n const tags = new Map<string, string>();\n\n const collect = (list: ReadonlyArray<ts.JSDocTagInfo>) => {\n for (const tag of list) {\n tags.set(tag.name, typescript.displayPartsToString(tag.text).trim());\n }\n };\n\n collect(target.getJsDocTags(checker));\n collect(symbol.getJsDocTags(checker));\n\n for (const declaration of symbol.declarations ?? []) {\n const statement = typescript.isNamespaceExport(declaration) ? declaration.parent : undefined;\n\n if (statement) {\n for (const tag of typescript.getJSDocTags(statement)) {\n tags.set(tag.tagName.text, typescript.getTextOfJSDocComment(tag.comment)?.trim() ?? '');\n }\n }\n }\n\n return tags;\n }\n\n /** Every export of the entries of the package at `directory`, each once, that the package itself declares. */\n private static scan(opts: {\n directory: string;\n entries: ReadonlyArray<string> | undefined;\n }): Map<string, IPublicFile> {\n const { directory, entries } = opts;\n const byFile = new Map<string, IPublicFile>();\n const typescript = FrameworkExports.loadTypeScript({ directory });\n const roots = PublicSurface.entriesOf({ directory, entries });\n\n if (!typescript || roots.length === 0) {\n return byFile;\n }\n\n const program = typescript.createProgram(\n roots,\n PublicSurface.optionsFor({ typescript, directory }),\n );\n const checker = program.getTypeChecker();\n const seen = new Set<string>();\n const inside = (file: string) =>\n !file.endsWith('.d.ts') &&\n !file.split(sep).includes('node_modules') &&\n relative(directory, file).startsWith('..') === false;\n const valueFlags =\n typescript.SymbolFlags.Class |\n typescript.SymbolFlags.Function |\n typescript.SymbolFlags.Variable |\n typescript.SymbolFlags.Enum |\n typescript.SymbolFlags.ValueModule |\n typescript.SymbolFlags.NamespaceModule;\n\n for (const root of roots) {\n const source = program.getSourceFile(root);\n const module = source ? checker.getSymbolAtLocation(source) : undefined;\n\n if (!module) {\n continue;\n }\n\n for (const symbol of checker.getExportsOfModule(module)) {\n const isAlias = (symbol.flags & typescript.SymbolFlags.Alias) !== 0;\n const target = isAlias ? checker.getAliasedSymbol(symbol) : symbol;\n const namespaceExport = (symbol.declarations ?? []).find((declaration) =>\n typescript.isNamespaceExport(declaration),\n );\n const site = namespaceExport ?? target.declarations?.[0];\n const file = site?.getSourceFile().fileName;\n\n if (!site || !file || !inside(file)) {\n continue;\n }\n\n const name = symbol.getName();\n const key = `${file}#${name}`;\n\n if (seen.has(key)) {\n continue;\n }\n\n seen.add(key);\n\n const tags = PublicSurface.tagsOf({ typescript, checker, symbol, target });\n const named = typescript.getNameOfDeclaration(site) ?? site;\n const entry = byFile.get(file) ?? { text: site.getSourceFile().text, exports: [] };\n\n entry.exports.push({\n name,\n isValue: namespaceExport !== undefined || (target.flags & valueFlags) !== 0,\n file,\n start: named.getStart(),\n end: named.getEnd(),\n hasUseWhen: (tags.get(PublicSurface.USE_WHEN) ?? '').length > 0,\n hasEmptyInsteadOf: tags.get(PublicSurface.INSTEAD_OF) === '',\n });\n byFile.set(file, entry);\n }\n }\n\n return byFile;\n }\n\n /** The exports of the package at `directory`, by the file that declares them. */\n static of(opts: {\n directory: string;\n entries?: ReadonlyArray<string>;\n }): Map<string, IPublicFile> {\n const key = `${opts.directory}|${(opts.entries ?? []).join(',')}`;\n const cached = PublicSurface.surfaces.get(key);\n\n if (cached) {\n return cached;\n }\n\n const surface = PublicSurface.scan({ directory: opts.directory, entries: opts.entries });\n PublicSurface.surfaces.set(key, surface);\n\n return surface;\n }\n\n /** The package folder of `file`: where the nearest package.json is. */\n static packageOf(opts: { file: string }): string | undefined {\n return FrameworkExports.manifestFor({ directory: dirname(opts.file) })?.directory;\n }\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Linter } from 'eslint';
|
|
2
|
-
/**
|
|
3
|
-
* The lint configs of a package other projects install: its public exports say when to use them (`@useWhen`). Not part of
|
|
4
|
-
* `houseConfigs`: an app extending the house rules has no public surface to document.
|
|
5
|
-
*
|
|
6
|
-
* ```js
|
|
7
|
-
* // .configs/lints/eslint.config.mjs
|
|
8
|
-
* import { houseConfigs, PublishedPackageConfigs } from '@venizia/dev-configs/linters';
|
|
9
|
-
*
|
|
10
|
-
* export default [...houseConfigs, ...PublishedPackageConfigs.build({ baseline: '.configs/use-when-baseline.json' })];
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export declare class PublishedPackageConfigs {
|
|
14
|
-
/** `require-use-when` (error) and `pending-use-when` (warning) over source files, tests exempt. */
|
|
15
|
-
static build(opts?: {
|
|
16
|
-
baseline?: string;
|
|
17
|
-
entries?: ReadonlyArray<string>;
|
|
18
|
-
types?: ReadonlyArray<string>;
|
|
19
|
-
}): Linter.Config[];
|
|
20
|
-
}
|
|
21
|
-
/** `PublishedPackageConfigs.build()` with no baseline: every gap is an error. */
|
|
22
|
-
export declare const publishedPackageConfigs: Linter.Config[];
|
|
23
|
-
//# sourceMappingURL=published-package-configs.d.ts.map
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publishedPackageConfigs = exports.PublishedPackageConfigs = void 0;
|
|
4
|
-
const common_1 = require("./common");
|
|
5
|
-
const plugin_1 = require("./plugin");
|
|
6
|
-
const require_use_when_rule_1 = require("./require-use-when.rule");
|
|
7
|
-
const SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];
|
|
8
|
-
const TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];
|
|
9
|
-
/**
|
|
10
|
-
* The lint configs of a package other projects install: its public exports say when to use them (`@useWhen`). Not part of
|
|
11
|
-
* `houseConfigs`: an app extending the house rules has no public surface to document.
|
|
12
|
-
*
|
|
13
|
-
* ```js
|
|
14
|
-
* // .configs/lints/eslint.config.mjs
|
|
15
|
-
* import { houseConfigs, PublishedPackageConfigs } from '@venizia/dev-configs/linters';
|
|
16
|
-
*
|
|
17
|
-
* export default [...houseConfigs, ...PublishedPackageConfigs.build({ baseline: '.configs/use-when-baseline.json' })];
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
class PublishedPackageConfigs {
|
|
21
|
-
/** `require-use-when` (error) and `pending-use-when` (warning) over source files, tests exempt. */
|
|
22
|
-
static build(opts = {}) {
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
files: SOURCE_FILES,
|
|
26
|
-
ignores: TEST_FILES,
|
|
27
|
-
plugins: { [common_1.HOUSE_PLUGIN_NAMESPACE]: plugin_1.houseEslintPlugin },
|
|
28
|
-
rules: {
|
|
29
|
-
[require_use_when_rule_1.RequireUseWhenRule.NAME]: require_use_when_rule_1.RequireUseWhenRule.build(opts),
|
|
30
|
-
[require_use_when_rule_1.RequireUseWhenRule.PENDING_NAME]: require_use_when_rule_1.RequireUseWhenRule.build({
|
|
31
|
-
...opts,
|
|
32
|
-
severity: 'warn',
|
|
33
|
-
}),
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.PublishedPackageConfigs = PublishedPackageConfigs;
|
|
40
|
-
/** `PublishedPackageConfigs.build()` with no baseline: every gap is an error. */
|
|
41
|
-
exports.publishedPackageConfigs = PublishedPackageConfigs.build();
|
|
42
|
-
//# sourceMappingURL=published-package-configs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"published-package-configs.js","sourceRoot":"","sources":["../../../src/linters/house/published-package-configs.ts"],"names":[],"mappings":";;;AACA,qCAAkD;AAClD,qCAA6C;AAC7C,mEAA6D;AAE7D,MAAM,YAAY,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAC/C,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAEnF;;;;;;;;;;GAUG;AACH,MAAa,uBAAuB;IAClC,mGAAmG;IACnG,MAAM,CAAC,KAAK,CACV,OAII,EAAE;QAEN,OAAO;YACL;gBACE,KAAK,EAAE,YAAY;gBACnB,OAAO,EAAE,UAAU;gBACnB,OAAO,EAAE,EAAE,CAAC,+BAAsB,CAAC,EAAE,0BAAiB,EAAE;gBACxD,KAAK,EAAE;oBACL,CAAC,0CAAkB,CAAC,IAAI,CAAC,EAAE,0CAAkB,CAAC,KAAK,CAAC,IAAI,CAAC;oBACzD,CAAC,0CAAkB,CAAC,YAAY,CAAC,EAAE,0CAAkB,CAAC,KAAK,CAAC;wBAC1D,GAAG,IAAI;wBACP,QAAQ,EAAE,MAAM;qBACjB,CAAC;iBACH;aACF;SACF,CAAC;IACJ,CAAC;CACF;AAxBD,0DAwBC;AAED,iFAAiF;AACpE,QAAA,uBAAuB,GAAoB,uBAAuB,CAAC,KAAK,EAAE,CAAC","sourcesContent":["import type { Linter } from 'eslint';\nimport { HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { houseEslintPlugin } from './plugin';\nimport { RequireUseWhenRule } from './require-use-when.rule';\n\nconst SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];\nconst TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];\n\n/**\n * The lint configs of a package other projects install: its public exports say when to use them (`@useWhen`). Not part of\n * `houseConfigs`: an app extending the house rules has no public surface to document.\n *\n * ```js\n * // .configs/lints/eslint.config.mjs\n * import { houseConfigs, PublishedPackageConfigs } from '@venizia/dev-configs/linters';\n *\n * export default [...houseConfigs, ...PublishedPackageConfigs.build({ baseline: '.configs/use-when-baseline.json' })];\n * ```\n */\nexport class PublishedPackageConfigs {\n /** `require-use-when` (error) and `pending-use-when` (warning) over source files, tests exempt. */\n static build(\n opts: {\n baseline?: string;\n entries?: ReadonlyArray<string>;\n types?: ReadonlyArray<string>;\n } = {},\n ): Linter.Config[] {\n return [\n {\n files: SOURCE_FILES,\n ignores: TEST_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [RequireUseWhenRule.NAME]: RequireUseWhenRule.build(opts),\n [RequireUseWhenRule.PENDING_NAME]: RequireUseWhenRule.build({\n ...opts,\n severity: 'warn',\n }),\n },\n },\n ];\n }\n}\n\n/** `PublishedPackageConfigs.build()` with no baseline: every gap is an error. */\nexport const publishedPackageConfigs: Linter.Config[] = PublishedPackageConfigs.build();\n"]}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Linter, Rule } from 'eslint';
|
|
2
|
-
import type { TRuleSeverity } from '../rules/common';
|
|
3
|
-
import type { IPublicExport } from './public-surface';
|
|
4
|
-
/**
|
|
5
|
-
* `venizia/require-use-when` and `venizia/pending-use-when`. Every export of a package's public entry points that is a
|
|
6
|
-
* value (a class, function, const, enum or namespace), and the framework types apps copy (`TNullable`, `ValueOrPromise`,
|
|
7
|
-
* `TConstValue`...), carries a non-empty `@useWhen` in its TSDoc: plain words saying when to reach for it, so an author or an
|
|
8
|
-
* agent who has never seen the API finds it. `@insteadOf`, when present, names what it replaces and is not empty. Other
|
|
9
|
-
* types are optional: they point to their owner with `@see`.
|
|
10
|
-
*
|
|
11
|
-
* `baseline` is a JSON file (`{ "entries": ["src/a.ts#Name", ...] }`, paths from the package folder) listing the exports not
|
|
12
|
-
* yet swept, so a package adopts the rule one folder at a time. Not in the baseline, a missing tag is an error
|
|
13
|
-
* (`require-use-when`). In the baseline it is only a warning (`pending-use-when`), and a baseline entry that now has its tag
|
|
14
|
-
* is an error: the file can only shrink. When the sweep ends the file is deleted and the option dropped.
|
|
15
|
-
*
|
|
16
|
-
* The entries are the package's `exports` mapped to source, or the `entries` option. An `export * as X from` statement
|
|
17
|
-
* carries its tag on the statement.
|
|
18
|
-
*/
|
|
19
|
-
export declare class RequireUseWhenRule {
|
|
20
|
-
static readonly NAME = "venizia/require-use-when";
|
|
21
|
-
static readonly PENDING_NAME = "venizia/pending-use-when";
|
|
22
|
-
/** The framework types apps shadow, which need the tag although they are types. */
|
|
23
|
-
static readonly DEFAULT_TYPES: ReadonlyArray<string>;
|
|
24
|
-
/** Whether an export must carry `@useWhen`: a value, or one of the framework types. */
|
|
25
|
-
static isRequired(opts: {
|
|
26
|
-
item: IPublicExport;
|
|
27
|
-
types?: ReadonlyArray<string>;
|
|
28
|
-
}): boolean;
|
|
29
|
-
private static readBaseline;
|
|
30
|
-
private static strings;
|
|
31
|
-
private static readonly SCHEMA;
|
|
32
|
-
private static create;
|
|
33
|
-
static readonly RULE: Rule.RuleModule;
|
|
34
|
-
static readonly PENDING_RULE: Rule.RuleModule;
|
|
35
|
-
static build(opts?: {
|
|
36
|
-
severity?: TRuleSeverity;
|
|
37
|
-
baseline?: string;
|
|
38
|
-
entries?: ReadonlyArray<string>;
|
|
39
|
-
types?: ReadonlyArray<string>;
|
|
40
|
-
}): Linter.RuleEntry;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=require-use-when.rule.d.ts.map
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequireUseWhenRule = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const common_1 = require("./common");
|
|
7
|
-
const public_surface_1 = require("./public-surface");
|
|
8
|
-
/**
|
|
9
|
-
* `venizia/require-use-when` and `venizia/pending-use-when`. Every export of a package's public entry points that is a
|
|
10
|
-
* value (a class, function, const, enum or namespace), and the framework types apps copy (`TNullable`, `ValueOrPromise`,
|
|
11
|
-
* `TConstValue`...), carries a non-empty `@useWhen` in its TSDoc: plain words saying when to reach for it, so an author or an
|
|
12
|
-
* agent who has never seen the API finds it. `@insteadOf`, when present, names what it replaces and is not empty. Other
|
|
13
|
-
* types are optional: they point to their owner with `@see`.
|
|
14
|
-
*
|
|
15
|
-
* `baseline` is a JSON file (`{ "entries": ["src/a.ts#Name", ...] }`, paths from the package folder) listing the exports not
|
|
16
|
-
* yet swept, so a package adopts the rule one folder at a time. Not in the baseline, a missing tag is an error
|
|
17
|
-
* (`require-use-when`). In the baseline it is only a warning (`pending-use-when`), and a baseline entry that now has its tag
|
|
18
|
-
* is an error: the file can only shrink. When the sweep ends the file is deleted and the option dropped.
|
|
19
|
-
*
|
|
20
|
-
* The entries are the package's `exports` mapped to source, or the `entries` option. An `export * as X from` statement
|
|
21
|
-
* carries its tag on the statement.
|
|
22
|
-
*/
|
|
23
|
-
class RequireUseWhenRule {
|
|
24
|
-
static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/require-use-when`; }
|
|
25
|
-
static { this.PENDING_NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/pending-use-when`; }
|
|
26
|
-
/** The framework types apps shadow, which need the tag although they are types. */
|
|
27
|
-
static { this.DEFAULT_TYPES = [
|
|
28
|
-
'TNullable',
|
|
29
|
-
'ValueOrPromise',
|
|
30
|
-
'ValueOf',
|
|
31
|
-
'TConstValue',
|
|
32
|
-
'TClass',
|
|
33
|
-
'TConstructor',
|
|
34
|
-
'TAbstractConstructor',
|
|
35
|
-
]; }
|
|
36
|
-
/** Whether an export must carry `@useWhen`: a value, or one of the framework types. */
|
|
37
|
-
static isRequired(opts) {
|
|
38
|
-
const { item, types = RequireUseWhenRule.DEFAULT_TYPES } = opts;
|
|
39
|
-
return item.isValue || types.includes(item.name);
|
|
40
|
-
}
|
|
41
|
-
static readBaseline(opts) {
|
|
42
|
-
const { directory, baseline } = opts;
|
|
43
|
-
const file = typeof baseline === 'string' ? (0, node_path_1.resolve)(directory, baseline) : undefined;
|
|
44
|
-
if (!file || !(0, node_fs_1.existsSync)(file)) {
|
|
45
|
-
return new Set();
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
const parsed = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
|
|
49
|
-
const entries = common_1.AstNode.readField({ node: parsed, key: 'entries' });
|
|
50
|
-
return new Set(Array.isArray(entries) ? entries.filter((entry) => typeof entry === 'string') : []);
|
|
51
|
-
// eslint-disable-next-line venizia/no-silent-catch -- a baseline that does not parse exempts nothing: every gap is reported
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return new Set();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
static strings(opts) {
|
|
58
|
-
return Array.isArray(opts.value)
|
|
59
|
-
? opts.value.filter((entry) => typeof entry === 'string')
|
|
60
|
-
: undefined;
|
|
61
|
-
}
|
|
62
|
-
static { this.SCHEMA = [
|
|
63
|
-
{
|
|
64
|
-
type: 'object',
|
|
65
|
-
properties: {
|
|
66
|
-
baseline: { type: 'string' },
|
|
67
|
-
entries: { type: 'array', items: { type: 'string' } },
|
|
68
|
-
types: { type: 'array', items: { type: 'string' } },
|
|
69
|
-
},
|
|
70
|
-
additionalProperties: false,
|
|
71
|
-
},
|
|
72
|
-
]; }
|
|
73
|
-
static create(opts) {
|
|
74
|
-
const { mode } = opts;
|
|
75
|
-
return (context) => ({
|
|
76
|
-
[common_1.AstNodeTypes.PROGRAM]: () => {
|
|
77
|
-
const directory = public_surface_1.PublicSurface.packageOf({ file: context.filename });
|
|
78
|
-
if (directory === undefined) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const options = context.options[0];
|
|
82
|
-
const entries = RequireUseWhenRule.strings({
|
|
83
|
-
value: common_1.AstNode.readField({ node: options, key: 'entries' }),
|
|
84
|
-
});
|
|
85
|
-
const types = RequireUseWhenRule.strings({
|
|
86
|
-
value: common_1.AstNode.readField({ node: options, key: 'types' }),
|
|
87
|
-
}) ?? RequireUseWhenRule.DEFAULT_TYPES;
|
|
88
|
-
const baselined = RequireUseWhenRule.readBaseline({
|
|
89
|
-
directory,
|
|
90
|
-
baseline: common_1.AstNode.readField({ node: options, key: 'baseline' }),
|
|
91
|
-
});
|
|
92
|
-
const surface = public_surface_1.PublicSurface.of({ directory, entries });
|
|
93
|
-
const current = surface.get((0, node_path_1.resolve)(context.filename));
|
|
94
|
-
// The offsets belong to the text the scan read: an editor buffer that differs, or a file a fix has just changed, is
|
|
95
|
-
// left alone until it is saved and read again.
|
|
96
|
-
if (current && current.text !== context.sourceCode.text) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const own = (0, node_path_1.relative)(directory, (0, node_path_1.resolve)(context.filename)).split(node_path_1.sep).join('/');
|
|
100
|
-
// A baseline entry of this file whose export is gone exempts nothing: a future export of that name must not slip in.
|
|
101
|
-
if (mode === 'require' && surface.size > 0) {
|
|
102
|
-
const present = new Set((current?.exports ?? []).map((item) => item.name));
|
|
103
|
-
for (const entry of baselined) {
|
|
104
|
-
const [file, name] = entry.split('#');
|
|
105
|
-
if (file === own && name !== undefined && !present.has(name)) {
|
|
106
|
-
context.report({
|
|
107
|
-
loc: { line: 1, column: 0 },
|
|
108
|
-
messageId: 'staleEntry',
|
|
109
|
-
data: { name },
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
for (const item of current?.exports ?? []) {
|
|
115
|
-
const key = `${own}#${item.name}`;
|
|
116
|
-
const isPending = baselined.has(key);
|
|
117
|
-
const loc = {
|
|
118
|
-
start: context.sourceCode.getLocFromIndex(item.start),
|
|
119
|
-
end: context.sourceCode.getLocFromIndex(item.end),
|
|
120
|
-
};
|
|
121
|
-
const isRequired = RequireUseWhenRule.isRequired({ item, types });
|
|
122
|
-
if (mode === 'pending') {
|
|
123
|
-
if (isRequired && !item.hasUseWhen && isPending) {
|
|
124
|
-
context.report({ loc, messageId: 'pending', data: { name: item.name } });
|
|
125
|
-
}
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (item.hasEmptyInsteadOf) {
|
|
129
|
-
context.report({ loc, messageId: 'emptyInsteadOf', data: { name: item.name } });
|
|
130
|
-
}
|
|
131
|
-
if (isRequired && !item.hasUseWhen && !isPending) {
|
|
132
|
-
context.report({ loc, messageId: 'missing', data: { name: item.name } });
|
|
133
|
-
}
|
|
134
|
-
if (isRequired && item.hasUseWhen && isPending) {
|
|
135
|
-
context.report({ loc, messageId: 'stale', data: { name: item.name } });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
static { this.RULE = {
|
|
142
|
-
meta: {
|
|
143
|
-
type: 'suggestion',
|
|
144
|
-
schema: RequireUseWhenRule.SCHEMA,
|
|
145
|
-
messages: {
|
|
146
|
-
missing: '`{{name}}` is public: add a `@useWhen` to its TSDoc, plain words for when to reach for it (and `@insteadOf` for what it replaces).',
|
|
147
|
-
emptyInsteadOf: '`@insteadOf` on `{{name}}` is empty: name what it replaces, or remove the tag.',
|
|
148
|
-
stale: '`{{name}}` has its `@useWhen`: remove it from the baseline file, which may only shrink.',
|
|
149
|
-
staleEntry: 'The baseline lists `{{name}}`, which this file no longer exports: remove the entry, so a future export of that name is not exempt.',
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
create: RequireUseWhenRule.create({ mode: 'require' }),
|
|
153
|
-
}; }
|
|
154
|
-
static { this.PENDING_RULE = {
|
|
155
|
-
meta: {
|
|
156
|
-
type: 'suggestion',
|
|
157
|
-
schema: RequireUseWhenRule.SCHEMA,
|
|
158
|
-
messages: {
|
|
159
|
-
pending: '`{{name}}` has no `@useWhen` yet: it is in the baseline of exports still to sweep.',
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
create: RequireUseWhenRule.create({ mode: 'pending' }),
|
|
163
|
-
}; }
|
|
164
|
-
static build(opts = {}) {
|
|
165
|
-
const { severity = 'error', baseline, entries, types } = opts;
|
|
166
|
-
const options = {
|
|
167
|
-
...(baseline === undefined ? {} : { baseline }),
|
|
168
|
-
...(entries === undefined ? {} : { entries: [...entries] }),
|
|
169
|
-
...(types === undefined ? {} : { types: [...types] }),
|
|
170
|
-
};
|
|
171
|
-
return Object.keys(options).length === 0 ? [severity] : [severity, options];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
exports.RequireUseWhenRule = RequireUseWhenRule;
|
|
175
|
-
//# sourceMappingURL=require-use-when.rule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"require-use-when.rule.js","sourceRoot":"","sources":["../../../src/linters/house/require-use-when.rule.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAAmD;AAGnD,qCAAyE;AAEzE,qDAAiD;AAKjD;;;;;;;;;;;;;;GAcG;AACH,MAAa,kBAAkB;aACb,SAAI,GAAG,GAAG,+BAAsB,mBAAmB,CAAC;aACp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,MAAM,EAAE,kBAAkB,CAAC,MAAM;YACjC,QAAQ,EAAE;gBACR,OAAO,EACL,oFAAoF;aACvF;SACF;QACD,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACvD,CAAC;IAEF,MAAM,CAAC,KAAK,CACV,OAKI,EAAE;QAEN,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAC9D,MAAM,OAAO,GAAG;YACd,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;YAC/C,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;YAC3D,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;SACtD,CAAC;QAEF,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;;AA/LH,gDAgMC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { relative, resolve, sep } from 'node:path';\nimport type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport type { IPublicExport } from './public-surface';\nimport { PublicSurface } from './public-surface';\n\n/** Which of the two rules a rule module is: they read the same surface and the same baseline. */\ntype TUseWhenMode = 'require' | 'pending';\n\n/**\n * `venizia/require-use-when` and `venizia/pending-use-when`. Every export of a package's public entry points that is a\n * value (a class, function, const, enum or namespace), and the framework types apps copy (`TNullable`, `ValueOrPromise`,\n * `TConstValue`...), carries a non-empty `@useWhen` in its TSDoc: plain words saying when to reach for it, so an author or an\n * agent who has never seen the API finds it. `@insteadOf`, when present, names what it replaces and is not empty. Other\n * types are optional: they point to their owner with `@see`.\n *\n * `baseline` is a JSON file (`{ \"entries\": [\"src/a.ts#Name\", ...] }`, paths from the package folder) listing the exports not\n * yet swept, so a package adopts the rule one folder at a time. Not in the baseline, a missing tag is an error\n * (`require-use-when`). In the baseline it is only a warning (`pending-use-when`), and a baseline entry that now has its tag\n * is an error: the file can only shrink. When the sweep ends the file is deleted and the option dropped.\n *\n * The entries are the package's `exports` mapped to source, or the `entries` option. An `export * as X from` statement\n * carries its tag on the statement.\n */\nexport class RequireUseWhenRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/require-use-when`;\n static readonly PENDING_NAME = `${HOUSE_PLUGIN_NAMESPACE}/pending-use-when`;\n\n /** The framework types apps shadow, which need the tag although they are types. */\n static readonly DEFAULT_TYPES: ReadonlyArray<string> = [\n 'TNullable',\n 'ValueOrPromise',\n 'ValueOf',\n 'TConstValue',\n 'TClass',\n 'TConstructor',\n 'TAbstractConstructor',\n ];\n\n /** Whether an export must carry `@useWhen`: a value, or one of the framework types. */\n static isRequired(opts: { item: IPublicExport; types?: ReadonlyArray<string> }): boolean {\n const { item, types = RequireUseWhenRule.DEFAULT_TYPES } = opts;\n\n return item.isValue || types.includes(item.name);\n }\n\n private static readBaseline(opts: { directory: string; baseline: unknown }): Set<string> {\n const { directory, baseline } = opts;\n const file = typeof baseline === 'string' ? resolve(directory, baseline) : undefined;\n\n if (!file || !existsSync(file)) {\n return new Set();\n }\n\n try {\n const parsed: unknown = JSON.parse(readFileSync(file, 'utf8'));\n const entries = AstNode.readField({ node: parsed, key: 'entries' });\n\n return new Set(\n Array.isArray(entries) ? entries.filter((entry) => typeof entry === 'string') : [],\n );\n // eslint-disable-next-line venizia/no-silent-catch -- a baseline that does not parse exempts nothing: every gap is reported\n } catch {\n return new Set();\n }\n }\n\n private static strings(opts: { value: unknown }): Array<string> | undefined {\n return Array.isArray(opts.value)\n ? opts.value.filter((entry): entry is string => typeof entry === 'string')\n : undefined;\n }\n\n private static readonly SCHEMA = [\n {\n type: 'object',\n properties: {\n baseline: { type: 'string' },\n entries: { type: 'array', items: { type: 'string' } },\n types: { type: 'array', items: { type: 'string' } },\n },\n additionalProperties: false,\n },\n ];\n\n private static create(opts: { mode: TUseWhenMode }) {\n const { mode } = opts;\n\n return (context: Rule.RuleContext): Rule.RuleListener => ({\n [AstNodeTypes.PROGRAM]: () => {\n const directory = PublicSurface.packageOf({ file: context.filename });\n\n if (directory === undefined) {\n return;\n }\n\n const options: unknown = context.options[0];\n const entries = RequireUseWhenRule.strings({\n value: AstNode.readField({ node: options, key: 'entries' }),\n });\n const types =\n RequireUseWhenRule.strings({\n value: AstNode.readField({ node: options, key: 'types' }),\n }) ?? RequireUseWhenRule.DEFAULT_TYPES;\n const baselined = RequireUseWhenRule.readBaseline({\n directory,\n baseline: AstNode.readField({ node: options, key: 'baseline' }),\n });\n const surface = PublicSurface.of({ directory, entries });\n const current = surface.get(resolve(context.filename));\n\n // The offsets belong to the text the scan read: an editor buffer that differs, or a file a fix has just changed, is\n // left alone until it is saved and read again.\n if (current && current.text !== context.sourceCode.text) {\n return;\n }\n\n const own = relative(directory, resolve(context.filename)).split(sep).join('/');\n\n // A baseline entry of this file whose export is gone exempts nothing: a future export of that name must not slip in.\n if (mode === 'require' && surface.size > 0) {\n const present = new Set((current?.exports ?? []).map((item) => item.name));\n\n for (const entry of baselined) {\n const [file, name] = entry.split('#');\n\n if (file === own && name !== undefined && !present.has(name)) {\n context.report({\n loc: { line: 1, column: 0 },\n messageId: 'staleEntry',\n data: { name },\n });\n }\n }\n }\n\n for (const item of current?.exports ?? []) {\n const key = `${own}#${item.name}`;\n const isPending = baselined.has(key);\n const loc = {\n start: context.sourceCode.getLocFromIndex(item.start),\n end: context.sourceCode.getLocFromIndex(item.end),\n };\n const isRequired = RequireUseWhenRule.isRequired({ item, types });\n\n if (mode === 'pending') {\n if (isRequired && !item.hasUseWhen && isPending) {\n context.report({ loc, messageId: 'pending', data: { name: item.name } });\n }\n\n continue;\n }\n\n if (item.hasEmptyInsteadOf) {\n context.report({ loc, messageId: 'emptyInsteadOf', data: { name: item.name } });\n }\n\n if (isRequired && !item.hasUseWhen && !isPending) {\n context.report({ loc, messageId: 'missing', data: { name: item.name } });\n }\n\n if (isRequired && item.hasUseWhen && isPending) {\n context.report({ loc, messageId: 'stale', data: { name: item.name } });\n }\n }\n },\n });\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: RequireUseWhenRule.SCHEMA,\n messages: {\n missing:\n '`{{name}}` is public: add a `@useWhen` to its TSDoc, plain words for when to reach for it (and `@insteadOf` for what it replaces).',\n emptyInsteadOf:\n '`@insteadOf` on `{{name}}` is empty: name what it replaces, or remove the tag.',\n stale:\n '`{{name}}` has its `@useWhen`: remove it from the baseline file, which may only shrink.',\n staleEntry:\n 'The baseline lists `{{name}}`, which this file no longer exports: remove the entry, so a future export of that name is not exempt.',\n },\n },\n create: RequireUseWhenRule.create({ mode: 'require' }),\n };\n\n static readonly PENDING_RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: RequireUseWhenRule.SCHEMA,\n messages: {\n pending:\n '`{{name}}` has no `@useWhen` yet: it is in the baseline of exports still to sweep.',\n },\n },\n create: RequireUseWhenRule.create({ mode: 'pending' }),\n };\n\n static build(\n opts: {\n severity?: TRuleSeverity;\n baseline?: string;\n entries?: ReadonlyArray<string>;\n types?: ReadonlyArray<string>;\n } = {},\n ): Linter.RuleEntry {\n const { severity = 'error', baseline, entries, types } = opts;\n const options = {\n ...(baseline === undefined ? {} : { baseline }),\n ...(entries === undefined ? {} : { entries: [...entries] }),\n ...(types === undefined ? {} : { types: [...types] }),\n };\n\n return Object.keys(options).length === 0 ? [severity] : [severity, options];\n }\n}\n"]}
|