@codeperfect/eslint-plugin 3.7.0 → 3.9.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/README.md +11 -19
- package/dist/adapters/angular/angular-lifecycle-usage-adapter.d.ts +15 -0
- package/dist/adapters/angular/angular-lifecycle-usage-adapter.d.ts.map +1 -0
- package/dist/adapters/angular/angular-lifecycle-usage-adapter.js +87 -0
- package/dist/adapters/angular/angular-template-expression-utilities.js +2 -2
- package/dist/adapters/angular/angular-template-usage-context.d.ts +1 -1
- package/dist/adapters/angular/angular-template-usage-context.d.ts.map +1 -1
- package/dist/adapters/angular/angular-template-usage-context.js +2 -2
- package/dist/adapters/angular/no-unused-public-members-template-adapter.js +2 -2
- package/dist/adapters/angular/plugin.d.ts.map +1 -1
- package/dist/adapters/angular/plugin.js +7 -3
- package/dist/codeperfect-eslint-plugin-1.0.0.tgz +0 -0
- package/dist/domain/architecture/consistent-barrel-files/exports-only-rule-utilities.d.ts +39 -0
- package/dist/domain/architecture/consistent-barrel-files/exports-only-rule-utilities.d.ts.map +1 -0
- package/dist/domain/architecture/consistent-barrel-files/exports-only-rule-utilities.js +131 -0
- package/dist/domain/architecture/consistent-barrel-files/exports-only-rule.d.ts.map +1 -1
- package/dist/domain/architecture/consistent-barrel-files/exports-only-rule.js +12 -1
- package/dist/domain/architecture/index.d.ts +2 -0
- package/dist/domain/architecture/index.d.ts.map +1 -1
- package/dist/domain/architecture/index.js +3 -1
- package/dist/domain/architecture/no-directory-only-imports/index.d.ts +2 -0
- package/dist/domain/architecture/no-directory-only-imports/index.d.ts.map +1 -0
- package/dist/domain/architecture/no-directory-only-imports/index.js +2 -0
- package/dist/domain/architecture/no-directory-only-imports/no-directory-only-imports-rule.d.ts +5 -0
- package/dist/domain/architecture/no-directory-only-imports/no-directory-only-imports-rule.d.ts.map +1 -0
- package/dist/domain/architecture/no-directory-only-imports/no-directory-only-imports-rule.js +83 -0
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-identifier-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-identifier-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-identifier-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-symbol-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-symbol-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-symbol-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index-builder.d.ts +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index-builder.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index-builder.js +2 -2
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index.d.ts +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-exports/no-unused-exports-usage-index.js +2 -2
- package/dist/domain/architecture/no-unused-exports/rule.d.ts +14 -1
- package/dist/domain/architecture/no-unused-exports/rule.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-exports/rule.js +17 -4
- package/dist/domain/architecture/no-unused-public-members/member-api-reachability-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-reachability-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-reachability-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-api-relevance-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-relevance-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-relevance-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-api-type-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-type-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-api-type-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-contract-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-contract-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-contract-utilities.js +13 -2
- package/dist/domain/architecture/no-unused-public-members/member-declaration-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-declaration-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-declaration-utilities.js +9 -4
- package/dist/domain/architecture/no-unused-public-members/member-factory-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-factory-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-factory-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-function-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-function-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-function-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-host-utilities.d.ts +3 -3
- package/dist/domain/architecture/no-unused-public-members/member-host-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-host-utilities.js +40 -25
- package/dist/domain/architecture/no-unused-public-members/member-operation-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-operation-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-operation-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-parameter-flow-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-parameter-flow-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-parameter-flow-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-public-api-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-public-api-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-public-api-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-request-body-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-request-body-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-request-body-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-scope-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-scope-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-scope-utilities.js +39 -15
- package/dist/domain/architecture/no-unused-public-members/member-usage-call-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-call-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-call-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-expression-reference-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-expression-reference-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-expression-reference-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-handoff-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-handoff-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-handoff-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-index-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-index-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-index-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-local-flow-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-local-flow-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-local-flow-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-reference-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-reference-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-reference-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-serialization-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-serialization-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-serialization-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-type-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-type-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-type-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-utilities.js +13 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-value-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-value-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-value-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-usage-whole-object-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-whole-object-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-usage-whole-object-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/member-utilities.d.ts +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/member-utilities.js +2 -2
- package/dist/domain/architecture/no-unused-public-members/rule.d.ts +14 -1
- package/dist/domain/architecture/no-unused-public-members/rule.d.ts.map +1 -1
- package/dist/domain/architecture/no-unused-public-members/rule.js +16 -3
- package/dist/domain/architecture/package-subpath-imports/index.d.ts +2 -0
- package/dist/domain/architecture/package-subpath-imports/index.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/index.js +2 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-alias-utilities.d.ts +12 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-alias-utilities.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-alias-utilities.js +215 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-matching-utilities.d.ts +24 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-matching-utilities.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-matching-utilities.js +46 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-path-utilities.d.ts +36 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-path-utilities.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-path-utilities.js +103 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-types.d.ts +44 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-types.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-types.js +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-utilities.d.ts +13 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-utilities.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/package-subpath-import-utilities.js +194 -0
- package/dist/domain/architecture/package-subpath-imports/prefer-package-subpath-imports-rule.d.ts +5 -0
- package/dist/domain/architecture/package-subpath-imports/prefer-package-subpath-imports-rule.d.ts.map +1 -0
- package/dist/domain/architecture/package-subpath-imports/prefer-package-subpath-imports-rule.js +106 -0
- package/dist/domain/architecture/program-analysis/source-dependency-utilities.d.ts +1 -1
- package/dist/domain/architecture/program-analysis/source-dependency-utilities.d.ts.map +1 -1
- package/dist/domain/architecture/program-analysis/source-dependency-utilities.js +2 -2
- package/dist/domain/architecture/program-analysis/source-file-facts.d.ts +1 -1
- package/dist/domain/architecture/program-analysis/source-file-facts.d.ts.map +1 -1
- package/dist/domain/architecture/program-analysis/source-file-facts.js +2 -2
- package/dist/domain/docs/single-line-jsdoc/rule.js +2 -2
- package/dist/domain/index.d.ts +1 -1
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +2 -2
- package/dist/domain/testing/require-act-result-capture/rule.js +2 -2
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/infrastructure/codeperfect-plugin.d.ts +4 -0
- package/dist/infrastructure/codeperfect-plugin.d.ts.map +1 -1
- package/dist/infrastructure/codeperfect-plugin.js +4 -2
- package/dist/infrastructure/index.d.ts +0 -1
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +1 -2
- package/dist/infrastructure/presets.d.ts.map +1 -1
- package/dist/infrastructure/presets.js +5 -1
- package/docs/README.md +20 -0
- package/docs/api/index.md +19 -0
- package/docs/api/type-aliases/CodeperfectPreset.md +13 -0
- package/docs/api/variables/aaa.md +13 -0
- package/docs/api/variables/all.md +13 -0
- package/docs/api/variables/architecture.md +13 -0
- package/docs/api/variables/codeperfectPlugin.md +111 -0
- package/docs/api/variables/core.md +13 -0
- package/docs/api/variables/documentation.md +13 -0
- package/docs/api/variables/testing.md +13 -0
- package/docs/design/README.md +6 -0
- package/docs/design/architecture.md +218 -0
- package/docs/design/release.md +30 -0
- package/docs/rules/assert-actual-expected-names.md +163 -0
- package/docs/rules/barrel-files-exports-only.md +88 -0
- package/docs/rules/consistent-barrel-files.md +107 -0
- package/docs/rules/enforce-aaa-structure.md +220 -0
- package/docs/rules/no-directory-only-imports.md +72 -0
- package/docs/rules/no-import-export-aliases.md +54 -0
- package/docs/rules/no-import-export-extensions.md +63 -0
- package/docs/rules/no-interface-member-docs.md +101 -0
- package/docs/rules/no-multiple-declarators.md +105 -0
- package/docs/rules/no-reexports-outside-barrels.md +106 -0
- package/docs/rules/no-unused-exports.md +283 -0
- package/docs/rules/no-unused-public-members.md +389 -0
- package/docs/rules/no-useless-delegation.md +56 -0
- package/docs/rules/prefer-interface-types.md +138 -0
- package/docs/rules/prefer-package-subpath-imports.md +82 -0
- package/docs/rules/prefer-vi-mocked-import.md +129 -0
- package/docs/rules/require-act-result-capture.md +183 -0
- package/docs/rules/require-example-language.md +172 -0
- package/docs/rules/require-test-companion.md +125 -0
- package/docs/rules/single-act-statement.md +133 -0
- package/docs/rules/single-line-jsdoc.md +140 -0
- package/package.json +27 -26
- package/dist/application/custom-rules.d.ts +0 -70
- package/dist/application/custom-rules.d.ts.map +0 -1
- package/dist/application/custom-rules.js +0 -37
- package/dist/application/index.d.ts +0 -4
- package/dist/application/index.d.ts.map +0 -1
- package/dist/application/index.js +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `codeperfect/no-useless-delegation`
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Disallow named functions that only forward their parameters to another synchronous call.
|
|
6
|
+
|
|
7
|
+
## Enabled by
|
|
8
|
+
|
|
9
|
+
- `core`
|
|
10
|
+
- internal `codeperfect` plugin registry
|
|
11
|
+
|
|
12
|
+
## Why this rule exists
|
|
13
|
+
|
|
14
|
+
Direct forwarding functions add another name and call frame without changing behavior. Prefer importing or calling the target directly unless the wrapper genuinely adapts behavior.
|
|
15
|
+
|
|
16
|
+
## Invalid
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { runAllInOne as runAllInOneApplication } from "../application";
|
|
20
|
+
|
|
21
|
+
export function runAllInOne(options: Options): Promise<void> {
|
|
22
|
+
return runAllInOneApplication(options);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const run = (options: Options) => application.run(options);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const run = (...arguments_: unknown[]) => application.run(...arguments_);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Valid
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const run = (options: Options) => application.run(normalize(options));
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const run = async (options: Options) => await application.run(options);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
class Application {
|
|
46
|
+
run(options: Options): unknown {
|
|
47
|
+
return service.run(options);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Rule Behavior
|
|
53
|
+
|
|
54
|
+
The rule checks function declarations and variables initialized with arrow functions or function expressions. It requires an exact parameter-to-argument match, including matching rest/spread parameters.
|
|
55
|
+
|
|
56
|
+
It does not inspect object or class methods, asynchronous functions, self-recursion, method calls whose receiver is not a plain named reference (for example type assertions, literals, or call results), destructured or defaulted parameters, or wrappers that transform arguments or contain additional statements. The rule has no autofix because deleting a wrapper can change module and public API contracts.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# `codeperfect/prefer-interface-types`
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Prefer named interfaces or type aliases over inline object types in type positions.
|
|
6
|
+
|
|
7
|
+
## Enabled by
|
|
8
|
+
|
|
9
|
+
- `typescript`
|
|
10
|
+
- internal `codeperfect` plugin registry
|
|
11
|
+
|
|
12
|
+
## Why this rule exists
|
|
13
|
+
|
|
14
|
+
Named types improve readability, reuse, and documentation quality. Inline object shapes in signatures are harder to reference, extend, and evolve over time.
|
|
15
|
+
|
|
16
|
+
## Rule Details
|
|
17
|
+
|
|
18
|
+
- Inline object types are disallowed in:
|
|
19
|
+
- function parameters
|
|
20
|
+
- function return types
|
|
21
|
+
- variable type annotations
|
|
22
|
+
- Instead, define a named:
|
|
23
|
+
- `interface`, or
|
|
24
|
+
- `type` alias
|
|
25
|
+
|
|
26
|
+
### Allowed
|
|
27
|
+
|
|
28
|
+
- Named interfaces or type aliases
|
|
29
|
+
- Inline object types in:
|
|
30
|
+
- generic constraints
|
|
31
|
+
- mapped or utility types
|
|
32
|
+
|
|
33
|
+
### Exceptions
|
|
34
|
+
|
|
35
|
+
Inline object types are allowed when:
|
|
36
|
+
|
|
37
|
+
- used in generic constraints
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
function process<T extends { id: string }>(input: T): T {
|
|
41
|
+
return input;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- used with utility or mapped types
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
type PartialUser = Partial<{ id: string; name: string }>;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Autofix
|
|
52
|
+
|
|
53
|
+
The rule can replace every reported inline object type with a generated top-level interface. Generated interfaces are appended as one block at the end of the file, and each one is preceded by this review marker:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// TODO: Review this autogenerated type name
|
|
57
|
+
interface Input {
|
|
58
|
+
value: string;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Generated names use PascalCase without adding an `I` prefix or a `Type` suffix:
|
|
63
|
+
|
|
64
|
+
- Parameters use their identifier, such as `input` becoming `Input`.
|
|
65
|
+
- Destructured or otherwise unsupported parameters use `Parameter`.
|
|
66
|
+
- Variables and return types use the nearest declared variable, function, or method identifier.
|
|
67
|
+
- Anonymous contexts without an identifier use `Type`.
|
|
68
|
+
- Existing top-level import, value, and type names are reserved. Collisions receive numeric suffixes such as `Input1` and `Input2`.
|
|
69
|
+
- Equal object shapes generate separate interfaces; the fixer does not deduplicate them.
|
|
70
|
+
|
|
71
|
+
The rule keeps reporting without an autofix when moving a type to module scope could change its meaning. This includes types that depend on function, class, or namespace scope, contextual `this` types, and declarations inside namespaces or ambient modules. Names declared in inner scopes are also reserved so a local declaration cannot capture a generated type reference.
|
|
72
|
+
|
|
73
|
+
For union, intersection, and parenthesized wrappers, one inline literal is reported per lint pass. When reported literals are nested, each autofix pass extracts only the outermost literals to avoid overlapping edits. ESLint's normal iterative autofix processing fixes remaining literals, including nested callback parameters and returns in the generated interfaces, on subsequent passes.
|
|
74
|
+
|
|
75
|
+
## Invalid
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
function saveUser(user: { id: string; name: string }) {}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
function demo(input: { value: string }): { value: string } {
|
|
83
|
+
return input;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const handler: (input: { value: string }) => void = () => {};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Valid
|
|
92
|
+
|
|
93
|
+
### Using interfaces
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
interface UserInput {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function saveUser(user: UserInput) {}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface DemoInput {
|
|
106
|
+
value: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function demo(input: DemoInput): DemoInput {
|
|
110
|
+
return input;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Using type aliases
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
type DemoInput = { value: string };
|
|
118
|
+
|
|
119
|
+
const demo = (...values: DemoInput[]): DemoInput => values[0]!;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
type SaveUserInput = { id: string; name: string };
|
|
124
|
+
|
|
125
|
+
function saveUser(user: SaveUserInput): void {}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// generic constraint
|
|
130
|
+
function process<T extends { id: string }>(input: T): T {
|
|
131
|
+
return input;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// utility type
|
|
137
|
+
type PartialUser = Partial<{ id: string; name: string }>;
|
|
138
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# `codeperfect/prefer-package-subpath-imports`
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Prefer Node.js package.json `imports` aliases over relative module specifiers that resolve to the same package path.
|
|
6
|
+
|
|
7
|
+
## Enabled by
|
|
8
|
+
|
|
9
|
+
- `architecture`
|
|
10
|
+
- `all`
|
|
11
|
+
- internal `codeperfect` plugin registry
|
|
12
|
+
|
|
13
|
+
## Why this rule exists
|
|
14
|
+
|
|
15
|
+
Package `imports` aliases provide stable internal module names that do not depend on the importing file's directory depth. Using them keeps imports consistent across single-package repositories and monorepo workspaces.
|
|
16
|
+
|
|
17
|
+
## Rule Details
|
|
18
|
+
|
|
19
|
+
The rule reads the nearest `package.json` for each linted file and considers only entries in its `imports` field. A relative import, export-from specifier, or dynamic import literal is reported when its resolved package-relative path matches a declared alias target. Directory specifiers are resolved to their on-disk index files (for example `./domain` matching a `./src/domain/index.ts` target) before matching.
|
|
20
|
+
|
|
21
|
+
Supported alias forms include:
|
|
22
|
+
|
|
23
|
+
- exact aliases such as `"#config": "./src/config.json"`
|
|
24
|
+
- wildcard aliases such as `"#src/*": "./src/*"`
|
|
25
|
+
- conditional values only when every branch resolves to the same target
|
|
26
|
+
|
|
27
|
+
The rule does not report:
|
|
28
|
+
|
|
29
|
+
- bare package or `node:` specifiers
|
|
30
|
+
- specifiers that already start with `#`
|
|
31
|
+
- relative paths outside the owning package
|
|
32
|
+
- relative paths that do not match a declared alias target
|
|
33
|
+
- relative paths that stay inside the importing file's own directory when the file itself is covered by the matched alias target
|
|
34
|
+
- packages whose nearest `package.json` has no usable `imports` aliases
|
|
35
|
+
|
|
36
|
+
In monorepos, the nearest `package.json` defines the package boundary. Root aliases are not applied inside a workspace package unless that workspace's own `package.json` declares them.
|
|
37
|
+
|
|
38
|
+
## Autofix
|
|
39
|
+
|
|
40
|
+
The rule replaces reported specifiers with the preferred `#` alias and preserves the original quote style and query or fragment suffix.
|
|
41
|
+
|
|
42
|
+
## Invalid
|
|
43
|
+
|
|
44
|
+
With `"imports": { "#src/*": "./src/*" }` in `package.json`:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { value } from "../config";
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
export { helper } from "../utils/helper";
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const dynamic = import("../dynamic/value");
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Valid
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { value } from "#src/config";
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { readFileSync } from "node:fs";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { value } from "./config";
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { sibling } from "./sibling";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The `./config` example is valid only when `./config` does not resolve to a path covered by a declared `imports` target. The `./sibling` example is valid when `sibling.ts` lives next to the importing file inside the same alias-covered tree, because imports inside the alias's own directory stay relative.
|
|
77
|
+
|
|
78
|
+
## Notes
|
|
79
|
+
|
|
80
|
+
- The rule performs no package analysis when a file has no relative module specifiers.
|
|
81
|
+
- The rule reads `package.json` lazily and only for files with relative specifiers.
|
|
82
|
+
- Conditional aliases with `null` branches or multiple distinct targets are ignored because their resolution can vary by runtime condition.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# `codeperfect/prefer-vi-mocked-import`
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Prefer inline mock factories in `vi.mock` and use `vi.mocked(...)` for interacting with mocked imports.
|
|
6
|
+
|
|
7
|
+
## Enabled by
|
|
8
|
+
|
|
9
|
+
- `vitest`
|
|
10
|
+
- internal `codeperfect` plugin registry
|
|
11
|
+
|
|
12
|
+
## Why this rule exists
|
|
13
|
+
|
|
14
|
+
Vitest mocks are easier to understand when:
|
|
15
|
+
|
|
16
|
+
- mock implementations are defined inline within `vi.mock`
|
|
17
|
+
- interactions with mocked imports use `vi.mocked(...)` for clarity and type safety
|
|
18
|
+
|
|
19
|
+
Separating mock declarations from their factory or interacting with mocks directly can make tests harder to follow and less consistent.
|
|
20
|
+
|
|
21
|
+
## Rule Details
|
|
22
|
+
|
|
23
|
+
This rule enforces two behaviors:
|
|
24
|
+
|
|
25
|
+
### 1. Inline mock factories
|
|
26
|
+
|
|
27
|
+
- Disallow defining mocks outside `vi.mock` and passing them into the factory
|
|
28
|
+
- Require mocks to be created inline inside the `vi.mock` factory
|
|
29
|
+
|
|
30
|
+
### 2. Prefer `vi.mocked(...)`
|
|
31
|
+
|
|
32
|
+
- When interacting with a mocked import, require wrapping it with `vi.mocked(...)`
|
|
33
|
+
- Direct usage of mock methods on imported values is disallowed
|
|
34
|
+
|
|
35
|
+
### Exceptions
|
|
36
|
+
|
|
37
|
+
- If a mock variable is used outside the `vi.mock` factory, it is allowed to remain external
|
|
38
|
+
- Local mocks not tied to module mocking are not affected
|
|
39
|
+
|
|
40
|
+
## Invalid
|
|
41
|
+
|
|
42
|
+
### External mock passed into factory
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const mockedClient = vi.fn();
|
|
46
|
+
vi.mock("./client", () => ({ client: mockedClient }));
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const installDevelopmentDependencies = vi.fn();
|
|
51
|
+
vi.mock(import("./dependencies"), () => ({ installDevelopmentDependencies }));
|
|
52
|
+
installDevelopmentDependencies.mockResolvedValue(void 0); // ❌ not using vi.mocked
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Direct interaction without `vi.mocked`
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { installDevelopmentDependencies } from "./dependencies";
|
|
59
|
+
|
|
60
|
+
vi.mock(import("./dependencies"), () => ({
|
|
61
|
+
installDevelopmentDependencies: vi.fn(),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
installDevelopmentDependencies.mockResolvedValue(void 0); // ❌ should use vi.mocked
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Autofix
|
|
68
|
+
|
|
69
|
+
- Inlines mock factories inside `vi.mock`
|
|
70
|
+
- Rewrites mock interactions to use `vi.mocked(...)`
|
|
71
|
+
- Adds missing imports when required
|
|
72
|
+
|
|
73
|
+
### Before
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const installDevelopmentDependencies = vi.fn();
|
|
77
|
+
vi.mock(import("./dependencies"), () => ({ installDevelopmentDependencies }));
|
|
78
|
+
installDevelopmentDependencies.mockResolvedValue(void 0);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### After
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { installDevelopmentDependencies } from "./dependencies";
|
|
85
|
+
|
|
86
|
+
vi.mock(import("./dependencies"), () => ({
|
|
87
|
+
installDevelopmentDependencies: vi.fn(),
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
vi.mocked(installDevelopmentDependencies).mockResolvedValue(void 0);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Valid
|
|
94
|
+
|
|
95
|
+
### Inline mock factory
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
vi.mock("./client", () => ({ client: vi.fn() }));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### External mock used elsewhere (allowed)
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const installDevelopmentDependencies = vi.fn();
|
|
105
|
+
console.log(installDevelopmentDependencies);
|
|
106
|
+
|
|
107
|
+
vi.mock(import("./dependencies"), () => ({ installDevelopmentDependencies }));
|
|
108
|
+
|
|
109
|
+
installDevelopmentDependencies.mockResolvedValue(void 0);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Proper use of `vi.mocked`
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { installDevelopmentDependencies } from "./dependencies";
|
|
116
|
+
|
|
117
|
+
vi.mock(import("./dependencies"), () => ({
|
|
118
|
+
installDevelopmentDependencies: vi.fn(),
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
vi.mocked(installDevelopmentDependencies).mockResolvedValue(void 0);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Local mocks not tied to module mocking
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const fn = vi.fn();
|
|
128
|
+
fn.mockReturnValue(1);
|
|
129
|
+
```
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# `codeperfect/require-act-result-capture`
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Require non-void Act expressions to capture their result in a named variable before the Assert phase.
|
|
6
|
+
|
|
7
|
+
## Enabled by
|
|
8
|
+
|
|
9
|
+
- `testing`
|
|
10
|
+
- internal `codeperfect` plugin registry
|
|
11
|
+
|
|
12
|
+
## Why this rule exists
|
|
13
|
+
|
|
14
|
+
Capturing Act results makes the observed value explicit and keeps the Assert phase focused on verification rather than execution. This improves readability, debuggability, and consistency across tests.
|
|
15
|
+
|
|
16
|
+
The rule allows intentional exceptions where capturing would add noise or reduce clarity.
|
|
17
|
+
|
|
18
|
+
## Rule Details
|
|
19
|
+
|
|
20
|
+
### What counts as an Act expression
|
|
21
|
+
|
|
22
|
+
Within the `// Act` section, the rule inspects:
|
|
23
|
+
|
|
24
|
+
- function calls
|
|
25
|
+
- method calls
|
|
26
|
+
- constructor calls (`new ...`)
|
|
27
|
+
- awaited calls, using the awaited return type to distinguish `Promise<void>` from meaningful results
|
|
28
|
+
|
|
29
|
+
### Required behavior
|
|
30
|
+
|
|
31
|
+
- If an Act expression returns a non-void value, it must be assigned to a variable
|
|
32
|
+
- The variable should represent the observed result (e.g. `actualResult`, `result`, `output`)
|
|
33
|
+
|
|
34
|
+
### Allowed patterns (exceptions)
|
|
35
|
+
|
|
36
|
+
The rule does **not** require capturing when:
|
|
37
|
+
|
|
38
|
+
#### 1. Combined Act & Assert
|
|
39
|
+
|
|
40
|
+
- The Act is embedded directly inside an assertion
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Act & Assert
|
|
44
|
+
expect(run(input)).toBe(1);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### 2. Void or side-effect-only interactions
|
|
48
|
+
|
|
49
|
+
- The call is clearly intended for side effects only
|
|
50
|
+
- The return value is unused and not meaningful
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
|
|
54
|
+
- mutating inputs
|
|
55
|
+
- pushing to arrays
|
|
56
|
+
- calling listeners or callbacks
|
|
57
|
+
|
|
58
|
+
#### 3. Framework or listener setup patterns
|
|
59
|
+
|
|
60
|
+
- Common testing or lint-rule patterns where return values are not relevant
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
|
|
64
|
+
- rule listeners (`create(...)`)
|
|
65
|
+
- event-style handlers
|
|
66
|
+
- registration APIs
|
|
67
|
+
|
|
68
|
+
Constructor-created fixtures and conventional setup values such as `Context`, `Fixture`, `Mock`, and `Options` are classified as Arrange setup by the shared analyzer and are not reported as uncaptured Act results.
|
|
69
|
+
|
|
70
|
+
### Disallowed patterns
|
|
71
|
+
|
|
72
|
+
- calling a non-void function in Act without capturing its result
|
|
73
|
+
- performing meaningful computation in Act that is only indirectly asserted
|
|
74
|
+
|
|
75
|
+
## Invalid
|
|
76
|
+
|
|
77
|
+
### Uncaptured non-void result
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
it("captures act results", () => {
|
|
81
|
+
// Arrange
|
|
82
|
+
const input = 1;
|
|
83
|
+
|
|
84
|
+
// Act
|
|
85
|
+
run(input); // ❌ result is ignored
|
|
86
|
+
|
|
87
|
+
// Assert
|
|
88
|
+
expect(input).toBe(1);
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Hidden result usage in Assert
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
it("uses result indirectly", () => {
|
|
96
|
+
// Arrange
|
|
97
|
+
const input = 1;
|
|
98
|
+
|
|
99
|
+
// Act
|
|
100
|
+
compute(input); // ❌ result not captured
|
|
101
|
+
|
|
102
|
+
// Assert
|
|
103
|
+
expect(input).toBe(2);
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Valid
|
|
108
|
+
|
|
109
|
+
### Captured result
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
it("allows captured results", () => {
|
|
113
|
+
// Arrange
|
|
114
|
+
const input = 1;
|
|
115
|
+
|
|
116
|
+
// Act
|
|
117
|
+
const actualResult = run(input);
|
|
118
|
+
|
|
119
|
+
// Assert
|
|
120
|
+
expect(actualResult).toBe(1);
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Combined Act & Assert
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
it("allows combined act and assert expectations", () => {
|
|
128
|
+
// Arrange
|
|
129
|
+
const input = 1;
|
|
130
|
+
|
|
131
|
+
// Act & Assert
|
|
132
|
+
expect(run(input)).toBe(1);
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Side-effect interaction
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
it("allows helper-driven act interactions", () => {
|
|
140
|
+
// Arrange
|
|
141
|
+
const reports: unknown[] = [];
|
|
142
|
+
const context = { report: (value: unknown) => reports.push(value) };
|
|
143
|
+
const node = { type: "Identifier" };
|
|
144
|
+
|
|
145
|
+
// Act
|
|
146
|
+
runListener(context, node);
|
|
147
|
+
|
|
148
|
+
// Assert
|
|
149
|
+
expect(reports).toStrictEqual([]);
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Listener or factory patterns
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
it("allows rule listener creation", () => {
|
|
157
|
+
// Arrange
|
|
158
|
+
const reportCalls: unknown[] = [];
|
|
159
|
+
const customRule = { create: (context: unknown) => ({ context }) };
|
|
160
|
+
const context = { report: (value: unknown) => reportCalls.push(value) };
|
|
161
|
+
|
|
162
|
+
// Act
|
|
163
|
+
customRule.create(context);
|
|
164
|
+
|
|
165
|
+
// Assert
|
|
166
|
+
expect(reportCalls).toStrictEqual([]);
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Explicit void interaction
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
it("allows obvious void interactions", () => {
|
|
174
|
+
// Arrange
|
|
175
|
+
const input = 1;
|
|
176
|
+
|
|
177
|
+
// Act
|
|
178
|
+
setValue(input);
|
|
179
|
+
|
|
180
|
+
// Assert
|
|
181
|
+
expect(input).toBe(1);
|
|
182
|
+
});
|
|
183
|
+
```
|