@venizia/dev-configs 0.5.0-0 → 0.5.0-10
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 +18 -13
- 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.js +42 -38
- 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.d.ts +1 -1
- package/dist/cli/codemod/any-aliases.js +14 -13
- 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 +18 -17
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.d.ts +32 -1
- package/dist/cli/codemod/binding-keys.js +251 -68
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +39 -0
- package/dist/cli/codemod/class-renames.js +297 -0
- package/dist/cli/codemod/class-renames.js.map +1 -0
- package/dist/cli/codemod/connector-imports.d.ts +1 -1
- package/dist/cli/codemod/connector-imports.js +13 -12
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-class-sets.d.ts +55 -0
- package/dist/cli/codemod/const-class-sets.js +219 -0
- package/dist/cli/codemod/const-class-sets.js.map +1 -0
- package/dist/cli/codemod/const-classes.d.ts +21 -3
- package/dist/cli/codemod/const-classes.js +151 -36
- 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 +19 -18
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.d.ts +4 -2
- package/dist/cli/codemod/files.js +7 -8
- 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 +25 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +14 -13
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +3 -3
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +58 -0
- package/dist/cli/codemod/typed-route-context.js +918 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -4
- 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 +43 -0
- package/dist/linters/house/browser-api-patterns.js +87 -0
- package/dist/linters/house/browser-api-patterns.js.map +1 -0
- package/dist/linters/house/common.d.ts +17 -2
- package/dist/linters/house/common.js +18 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +25 -0
- 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.d.ts +62 -0
- package/dist/linters/house/framework-exports.js +325 -0
- package/dist/linters/house/framework-exports.js.map +1 -0
- package/dist/linters/house/import-support.d.ts +56 -0
- package/dist/linters/house/import-support.js +179 -0
- package/dist/linters/house/import-support.js.map +1 -0
- package/dist/linters/house/index.d.ts +12 -0
- package/dist/linters/house/index.js +15 -1
- 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 +5 -5
- 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 +45 -0
- package/dist/linters/house/no-parent-import.rule.js +176 -0
- package/dist/linters/house/no-parent-import.rule.js.map +1 -0
- 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 +24 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js +100 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -0
- 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 +18 -2
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +83 -0
- package/dist/linters/house/prefer-framework-api.rule.js +562 -0
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -0
- package/dist/linters/house/prefer-http-method.rule.d.ts +22 -0
- package/dist/linters/house/prefer-http-method.rule.js +182 -0
- package/dist/linters/house/prefer-http-method.rule.js.map +1 -0
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +26 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js +155 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -0
- package/dist/linters/house/prefer-tnullable.rule.d.ts +25 -0
- package/dist/linters/house/prefer-tnullable.rule.js +124 -0
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -0
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +334 -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/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/{rejection.helper.d.ts → rejection.utility.d.ts} +4 -4
- package/dist/testing/{rejection.helper.js → rejection.utility.js} +7 -7
- package/dist/testing/rejection.utility.js.map +1 -0
- package/dist/testing/{spawn.helper.d.ts → spawn.utility.d.ts} +2 -2
- package/dist/testing/{spawn.helper.js → spawn.utility.js} +6 -6
- package/dist/testing/spawn.utility.js.map +1 -0
- package/package.json +7 -7
- package/dist/testing/rejection.helper.js.map +0 -1
- package/dist/testing/spawn.helper.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
1
2
|
/** The estree node types the house rules visit - computed visitor keys, so the names stay PascalCase as ESLint needs them. */
|
|
2
3
|
export declare class AstNodeTypes {
|
|
3
4
|
static readonly NEW_EXPRESSION = "NewExpression";
|
|
@@ -6,6 +7,13 @@ export declare class AstNodeTypes {
|
|
|
6
7
|
static readonly FUNCTION_EXPRESSION = "FunctionExpression";
|
|
7
8
|
static readonly ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression";
|
|
8
9
|
static readonly EXPORT_NAMED_DECLARATION = "ExportNamedDeclaration";
|
|
10
|
+
static readonly EXPORT_ALL_DECLARATION = "ExportAllDeclaration";
|
|
11
|
+
static readonly IMPORT_DECLARATION = "ImportDeclaration";
|
|
12
|
+
static readonly IMPORT_SPECIFIER = "ImportSpecifier";
|
|
13
|
+
static readonly IMPORT_EXPRESSION = "ImportExpression";
|
|
14
|
+
static readonly CLASS_DECLARATION = "ClassDeclaration";
|
|
15
|
+
static readonly CLASS_BODY = "ClassBody";
|
|
16
|
+
static readonly INTERFACE_DECLARATION = "TSInterfaceDeclaration";
|
|
9
17
|
static readonly UNION_TYPE = "TSUnionType";
|
|
10
18
|
static readonly AWAIT_EXPRESSION = "AwaitExpression";
|
|
11
19
|
static readonly RETURN_STATEMENT = "ReturnStatement";
|
|
@@ -15,14 +23,17 @@ export declare class AstNodeTypes {
|
|
|
15
23
|
static readonly ARRAY_EXPRESSION = "ArrayExpression";
|
|
16
24
|
static readonly AS_EXPRESSION = "TSAsExpression";
|
|
17
25
|
static readonly ASSIGNMENT_EXPRESSION = "AssignmentExpression";
|
|
26
|
+
static readonly ASSIGNMENT_PATTERN = "AssignmentPattern";
|
|
18
27
|
static readonly BINARY_EXPRESSION = "BinaryExpression";
|
|
19
28
|
static readonly CHAIN_EXPRESSION = "ChainExpression";
|
|
29
|
+
static readonly CLASS_IMPLEMENTS = "TSClassImplements";
|
|
20
30
|
static readonly CONDITIONAL_EXPRESSION = "ConditionalExpression";
|
|
21
31
|
static readonly EMPTY_STATEMENT = "EmptyStatement";
|
|
22
32
|
static readonly EXPORT_DEFAULT_DECLARATION = "ExportDefaultDeclaration";
|
|
23
33
|
static readonly EXPORT_SPECIFIER = "ExportSpecifier";
|
|
24
34
|
static readonly EXPRESSION_STATEMENT = "ExpressionStatement";
|
|
25
35
|
static readonly IDENTIFIER = "Identifier";
|
|
36
|
+
static readonly INTERFACE_HERITAGE = "TSInterfaceHeritage";
|
|
26
37
|
static readonly JSX_ATTRIBUTE = "JSXAttribute";
|
|
27
38
|
static readonly JSX_ELEMENT = "JSXElement";
|
|
28
39
|
static readonly JSX_EXPRESSION_CONTAINER = "JSXExpressionContainer";
|
|
@@ -39,10 +50,12 @@ export declare class AstNodeTypes {
|
|
|
39
50
|
static readonly PRIVATE_IDENTIFIER = "PrivateIdentifier";
|
|
40
51
|
static readonly PROGRAM = "Program";
|
|
41
52
|
static readonly PROPERTY = "Property";
|
|
53
|
+
static readonly PROPERTY_DEFINITION = "PropertyDefinition";
|
|
42
54
|
static readonly SATISFIES_EXPRESSION = "TSSatisfiesExpression";
|
|
43
55
|
static readonly SEQUENCE_EXPRESSION = "SequenceExpression";
|
|
44
56
|
static readonly SPREAD_ELEMENT = "SpreadElement";
|
|
45
57
|
static readonly STATIC_BLOCK = "StaticBlock";
|
|
58
|
+
static readonly TEMPLATE_ELEMENT = "TemplateElement";
|
|
46
59
|
static readonly TEMPLATE_LITERAL = "TemplateLiteral";
|
|
47
60
|
static readonly THIS_EXPRESSION = "ThisExpression";
|
|
48
61
|
static readonly TRY_STATEMENT = "TryStatement";
|
|
@@ -56,8 +69,8 @@ export declare class AstNodeTypes {
|
|
|
56
69
|
static readonly VARIABLE_DECLARATION = "VariableDeclaration";
|
|
57
70
|
static readonly VARIABLE_DECLARATOR = "VariableDeclarator";
|
|
58
71
|
}
|
|
59
|
-
/** The ESLint namespace the house rules live under:
|
|
60
|
-
export declare const HOUSE_PLUGIN_NAMESPACE = "venizia";
|
|
72
|
+
/** The ESLint namespace the house rules live under: `@venizia/<rule>`. */
|
|
73
|
+
export declare const HOUSE_PLUGIN_NAMESPACE = "@venizia";
|
|
61
74
|
/** Reads an AST node without trusting its type: TypeScript nodes carry fields estree does not declare. */
|
|
62
75
|
export declare class AstNode {
|
|
63
76
|
/** A field of an AST node. */
|
|
@@ -65,6 +78,8 @@ export declare class AstNode {
|
|
|
65
78
|
node: unknown;
|
|
66
79
|
key: string;
|
|
67
80
|
}): unknown;
|
|
81
|
+
/** Whether `value` is an AST node: an object with a string `type`. */
|
|
82
|
+
static isNode(value: unknown): value is Rule.Node;
|
|
68
83
|
/** The node's `type`, or `undefined` for anything that is not an AST node. */
|
|
69
84
|
static getType(opts: {
|
|
70
85
|
node: unknown;
|
|
@@ -9,6 +9,13 @@ class AstNodeTypes {
|
|
|
9
9
|
static { this.FUNCTION_EXPRESSION = 'FunctionExpression'; }
|
|
10
10
|
static { this.ARROW_FUNCTION_EXPRESSION = 'ArrowFunctionExpression'; }
|
|
11
11
|
static { this.EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration'; }
|
|
12
|
+
static { this.EXPORT_ALL_DECLARATION = 'ExportAllDeclaration'; }
|
|
13
|
+
static { this.IMPORT_DECLARATION = 'ImportDeclaration'; }
|
|
14
|
+
static { this.IMPORT_SPECIFIER = 'ImportSpecifier'; }
|
|
15
|
+
static { this.IMPORT_EXPRESSION = 'ImportExpression'; }
|
|
16
|
+
static { this.CLASS_DECLARATION = 'ClassDeclaration'; }
|
|
17
|
+
static { this.CLASS_BODY = 'ClassBody'; }
|
|
18
|
+
static { this.INTERFACE_DECLARATION = 'TSInterfaceDeclaration'; }
|
|
12
19
|
static { this.UNION_TYPE = 'TSUnionType'; }
|
|
13
20
|
static { this.AWAIT_EXPRESSION = 'AwaitExpression'; }
|
|
14
21
|
static { this.RETURN_STATEMENT = 'ReturnStatement'; }
|
|
@@ -18,14 +25,17 @@ class AstNodeTypes {
|
|
|
18
25
|
static { this.ARRAY_EXPRESSION = 'ArrayExpression'; }
|
|
19
26
|
static { this.AS_EXPRESSION = 'TSAsExpression'; }
|
|
20
27
|
static { this.ASSIGNMENT_EXPRESSION = 'AssignmentExpression'; }
|
|
28
|
+
static { this.ASSIGNMENT_PATTERN = 'AssignmentPattern'; }
|
|
21
29
|
static { this.BINARY_EXPRESSION = 'BinaryExpression'; }
|
|
22
30
|
static { this.CHAIN_EXPRESSION = 'ChainExpression'; }
|
|
31
|
+
static { this.CLASS_IMPLEMENTS = 'TSClassImplements'; }
|
|
23
32
|
static { this.CONDITIONAL_EXPRESSION = 'ConditionalExpression'; }
|
|
24
33
|
static { this.EMPTY_STATEMENT = 'EmptyStatement'; }
|
|
25
34
|
static { this.EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration'; }
|
|
26
35
|
static { this.EXPORT_SPECIFIER = 'ExportSpecifier'; }
|
|
27
36
|
static { this.EXPRESSION_STATEMENT = 'ExpressionStatement'; }
|
|
28
37
|
static { this.IDENTIFIER = 'Identifier'; }
|
|
38
|
+
static { this.INTERFACE_HERITAGE = 'TSInterfaceHeritage'; }
|
|
29
39
|
static { this.JSX_ATTRIBUTE = 'JSXAttribute'; }
|
|
30
40
|
static { this.JSX_ELEMENT = 'JSXElement'; }
|
|
31
41
|
static { this.JSX_EXPRESSION_CONTAINER = 'JSXExpressionContainer'; }
|
|
@@ -42,10 +52,12 @@ class AstNodeTypes {
|
|
|
42
52
|
static { this.PRIVATE_IDENTIFIER = 'PrivateIdentifier'; }
|
|
43
53
|
static { this.PROGRAM = 'Program'; }
|
|
44
54
|
static { this.PROPERTY = 'Property'; }
|
|
55
|
+
static { this.PROPERTY_DEFINITION = 'PropertyDefinition'; }
|
|
45
56
|
static { this.SATISFIES_EXPRESSION = 'TSSatisfiesExpression'; }
|
|
46
57
|
static { this.SEQUENCE_EXPRESSION = 'SequenceExpression'; }
|
|
47
58
|
static { this.SPREAD_ELEMENT = 'SpreadElement'; }
|
|
48
59
|
static { this.STATIC_BLOCK = 'StaticBlock'; }
|
|
60
|
+
static { this.TEMPLATE_ELEMENT = 'TemplateElement'; }
|
|
49
61
|
static { this.TEMPLATE_LITERAL = 'TemplateLiteral'; }
|
|
50
62
|
static { this.THIS_EXPRESSION = 'ThisExpression'; }
|
|
51
63
|
static { this.TRY_STATEMENT = 'TryStatement'; }
|
|
@@ -60,8 +72,8 @@ class AstNodeTypes {
|
|
|
60
72
|
static { this.VARIABLE_DECLARATOR = 'VariableDeclarator'; }
|
|
61
73
|
}
|
|
62
74
|
exports.AstNodeTypes = AstNodeTypes;
|
|
63
|
-
/** The ESLint namespace the house rules live under:
|
|
64
|
-
exports.HOUSE_PLUGIN_NAMESPACE = 'venizia';
|
|
75
|
+
/** The ESLint namespace the house rules live under: `@venizia/<rule>`. */
|
|
76
|
+
exports.HOUSE_PLUGIN_NAMESPACE = '@venizia';
|
|
65
77
|
/** Reads an AST node without trusting its type: TypeScript nodes carry fields estree does not declare. */
|
|
66
78
|
class AstNode {
|
|
67
79
|
/** A field of an AST node. */
|
|
@@ -71,6 +83,10 @@ class AstNode {
|
|
|
71
83
|
? Reflect.get(node, key)
|
|
72
84
|
: undefined;
|
|
73
85
|
}
|
|
86
|
+
/** Whether `value` is an AST node: an object with a string `type`. */
|
|
87
|
+
static isNode(value) {
|
|
88
|
+
return AstNode.getType({ node: value }) !== undefined;
|
|
89
|
+
}
|
|
74
90
|
/** The node's `type`, or `undefined` for anything that is not an AST node. */
|
|
75
91
|
static getType(opts) {
|
|
76
92
|
const type = AstNode.readField({ node: opts.node, key: 'type' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/linters/house/common.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/linters/house/common.ts"],"names":[],"mappings":";;;AAEA,8HAA8H;AAC9H,MAAa,YAAY;aACP,mBAAc,GAAG,eAAe,CAAC;aACjC,oBAAe,GAAG,gBAAgB,CAAC;aACnC,yBAAoB,GAAG,qBAAqB,CAAC;aAC7C,wBAAmB,GAAG,oBAAoB,CAAC;aAC3C,8BAAyB,GAAG,yBAAyB,CAAC;aACtD,6BAAwB,GAAG,wBAAwB,CAAC;aACpD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AS,CAAC;IAChB,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,MAAM,CAAC,KAAc;QAC1B,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,SAAS,CAAC;IACxD,CAAC;IAED,8EAA8E;IAC9E,MAAM,CAAC,OAAO,CAAC,IAAuB;QACpC,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAEjE,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;CACF;AArBD,0BAqBC","sourcesContent":["import type { Rule } from 'eslint';\n\n/** The estree node types the house rules visit - computed visitor keys, so the names stay PascalCase as ESLint needs them. */\nexport class AstNodeTypes {\n static readonly NEW_EXPRESSION = 'NewExpression';\n static readonly CALL_EXPRESSION = 'CallExpression';\n static readonly FUNCTION_DECLARATION = 'FunctionDeclaration';\n static readonly FUNCTION_EXPRESSION = 'FunctionExpression';\n static readonly ARROW_FUNCTION_EXPRESSION = 'ArrowFunctionExpression';\n static readonly EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration';\n static readonly EXPORT_ALL_DECLARATION = 'ExportAllDeclaration';\n static readonly IMPORT_DECLARATION = 'ImportDeclaration';\n static readonly IMPORT_SPECIFIER = 'ImportSpecifier';\n static readonly IMPORT_EXPRESSION = 'ImportExpression';\n static readonly CLASS_DECLARATION = 'ClassDeclaration';\n static readonly CLASS_BODY = 'ClassBody';\n static readonly INTERFACE_DECLARATION = 'TSInterfaceDeclaration';\n static readonly UNION_TYPE = 'TSUnionType';\n static readonly AWAIT_EXPRESSION = 'AwaitExpression';\n static readonly RETURN_STATEMENT = 'ReturnStatement';\n static readonly CATCH_CLAUSE = 'CatchClause';\n static readonly SWITCH_CASE = 'SwitchCase';\n static readonly BLOCK_STATEMENT = 'BlockStatement';\n static readonly ARRAY_EXPRESSION = 'ArrayExpression';\n static readonly AS_EXPRESSION = 'TSAsExpression';\n static readonly ASSIGNMENT_EXPRESSION = 'AssignmentExpression';\n static readonly ASSIGNMENT_PATTERN = 'AssignmentPattern';\n static readonly BINARY_EXPRESSION = 'BinaryExpression';\n static readonly CHAIN_EXPRESSION = 'ChainExpression';\n static readonly CLASS_IMPLEMENTS = 'TSClassImplements';\n static readonly CONDITIONAL_EXPRESSION = 'ConditionalExpression';\n static readonly EMPTY_STATEMENT = 'EmptyStatement';\n static readonly EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration';\n static readonly EXPORT_SPECIFIER = 'ExportSpecifier';\n static readonly EXPRESSION_STATEMENT = 'ExpressionStatement';\n static readonly IDENTIFIER = 'Identifier';\n static readonly INTERFACE_HERITAGE = 'TSInterfaceHeritage';\n static readonly JSX_ATTRIBUTE = 'JSXAttribute';\n static readonly JSX_ELEMENT = 'JSXElement';\n static readonly JSX_EXPRESSION_CONTAINER = 'JSXExpressionContainer';\n static readonly JSX_FRAGMENT = 'JSXFragment';\n static readonly LITERAL = 'Literal';\n static readonly LITERAL_TYPE = 'TSLiteralType';\n static readonly LOGICAL_EXPRESSION = 'LogicalExpression';\n static readonly MAPPED_TYPE = 'TSMappedType';\n static readonly MEMBER_EXPRESSION = 'MemberExpression';\n static readonly METHOD_DEFINITION = 'MethodDefinition';\n static readonly NON_NULL_EXPRESSION = 'TSNonNullExpression';\n static readonly NULL_KEYWORD = 'TSNullKeyword';\n static readonly OBJECT_EXPRESSION = 'ObjectExpression';\n static readonly PRIVATE_IDENTIFIER = 'PrivateIdentifier';\n static readonly PROGRAM = 'Program';\n static readonly PROPERTY = 'Property';\n static readonly PROPERTY_DEFINITION = 'PropertyDefinition';\n static readonly SATISFIES_EXPRESSION = 'TSSatisfiesExpression';\n static readonly SEQUENCE_EXPRESSION = 'SequenceExpression';\n static readonly SPREAD_ELEMENT = 'SpreadElement';\n static readonly STATIC_BLOCK = 'StaticBlock';\n static readonly TEMPLATE_ELEMENT = 'TemplateElement';\n static readonly TEMPLATE_LITERAL = 'TemplateLiteral';\n static readonly THIS_EXPRESSION = 'ThisExpression';\n static readonly TRY_STATEMENT = 'TryStatement';\n static readonly TYPE_ALIAS_DECLARATION = 'TSTypeAliasDeclaration';\n static readonly TYPE_ASSERTION = 'TSTypeAssertion';\n static readonly TYPE_PARAMETER_INSTANTIATION = 'TSTypeParameterInstantiation';\n static readonly TYPE_QUERY = 'TSTypeQuery';\n static readonly TYPE_REFERENCE = 'TSTypeReference';\n static readonly UNARY_EXPRESSION = 'UnaryExpression';\n static readonly UNDEFINED_KEYWORD = 'TSUndefinedKeyword';\n static readonly VARIABLE_DECLARATION = 'VariableDeclaration';\n static readonly VARIABLE_DECLARATOR = 'VariableDeclarator';\n}\n\n/** The ESLint namespace the house rules live under: `@venizia/<rule>`. */\nexport const HOUSE_PLUGIN_NAMESPACE = '@venizia';\n\n/** Reads an AST node without trusting its type: TypeScript nodes carry fields estree does not declare. */\nexport class AstNode {\n /** A field of an AST node. */\n static readField(opts: { node: unknown; key: string }): unknown {\n const { node, key } = opts;\n\n return typeof node === 'object' && node !== null && key in node\n ? Reflect.get(node, key)\n : undefined;\n }\n\n /** Whether `value` is an AST node: an object with a string `type`. */\n static isNode(value: unknown): value is Rule.Node {\n return AstNode.getType({ node: value }) !== undefined;\n }\n\n /** The node's `type`, or `undefined` for anything that is not an AST node. */\n static getType(opts: { node: unknown }): string | undefined {\n const type = AstNode.readField({ node: opts.node, key: 'type' });\n\n return typeof type === 'string' ? type : undefined;\n }\n}\n"]}
|
|
@@ -13,6 +13,13 @@ const max_params_own_rule_1 = require("./max-params-own.rule");
|
|
|
13
13
|
const no_async_hook_callback_rule_1 = require("./no-async-hook-callback.rule");
|
|
14
14
|
const no_leaked_render_rule_1 = require("./no-leaked-render.rule");
|
|
15
15
|
const no_new_error_rule_1 = require("./no-new-error.rule");
|
|
16
|
+
const no_shadow_framework_type_rule_1 = require("./no-shadow-framework-type.rule");
|
|
17
|
+
const prefer_framework_api_rule_1 = require("./prefer-framework-api.rule");
|
|
18
|
+
const prefer_http_method_rule_1 = require("./prefer-http-method.rule");
|
|
19
|
+
const prefer_promise_sleep_rule_1 = require("./prefer-promise-sleep.rule");
|
|
20
|
+
const prefer_tnullable_rule_1 = require("./prefer-tnullable.rule");
|
|
21
|
+
const typed_route_context_rule_1 = require("./typed-route-context.rule");
|
|
22
|
+
const zod_schema_convention_rule_1 = require("./zod-schema-convention.rule");
|
|
16
23
|
const plugin_1 = require("./plugin");
|
|
17
24
|
const SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];
|
|
18
25
|
const TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];
|
|
@@ -37,7 +44,14 @@ const houseRuleConfigs = [
|
|
|
37
44
|
rules: {
|
|
38
45
|
[max_params_own_rule_1.MaxParamsOwnRule.NAME]: max_params_own_rule_1.MaxParamsOwnRule.build(),
|
|
39
46
|
[no_new_error_rule_1.NoNewErrorRule.NAME]: no_new_error_rule_1.NoNewErrorRule.build(),
|
|
47
|
+
[no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.NAME]: no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.build(),
|
|
48
|
+
[prefer_tnullable_rule_1.PreferTNullableRule.NAME]: prefer_tnullable_rule_1.PreferTNullableRule.build(),
|
|
49
|
+
[prefer_promise_sleep_rule_1.PreferPromiseSleepRule.NAME]: prefer_promise_sleep_rule_1.PreferPromiseSleepRule.build(),
|
|
50
|
+
[prefer_http_method_rule_1.PreferHttpMethodRule.NAME]: prefer_http_method_rule_1.PreferHttpMethodRule.build(),
|
|
51
|
+
[prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: prefer_framework_api_rule_1.PreferFrameworkApiRule.build({ hooks: false }),
|
|
40
52
|
[const_class_values_rule_1.ConstClassValuesRule.NAME]: const_class_values_rule_1.ConstClassValuesRule.build({ severity: 'warn' }),
|
|
53
|
+
[zod_schema_convention_rule_1.ZodSchemaConventionRule.NAME]: zod_schema_convention_rule_1.ZodSchemaConventionRule.build(),
|
|
54
|
+
[typed_route_context_rule_1.TypedRouteContextRule.NAME]: typed_route_context_rule_1.TypedRouteContextRule.build(),
|
|
41
55
|
[NO_CAST_RULE]: ['warn', { assertionStyle: 'never' }],
|
|
42
56
|
},
|
|
43
57
|
},
|
|
@@ -45,6 +59,10 @@ const houseRuleConfigs = [
|
|
|
45
59
|
files: TEST_FILES,
|
|
46
60
|
rules: {
|
|
47
61
|
[no_new_error_rule_1.NoNewErrorRule.NAME]: 'off',
|
|
62
|
+
[no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.NAME]: 'off',
|
|
63
|
+
[prefer_promise_sleep_rule_1.PreferPromiseSleepRule.NAME]: 'off',
|
|
64
|
+
[prefer_http_method_rule_1.PreferHttpMethodRule.NAME]: 'off',
|
|
65
|
+
[prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: 'off',
|
|
48
66
|
[const_class_values_rule_1.ConstClassValuesRule.NAME]: 'off',
|
|
49
67
|
[NO_CAST_RULE]: 'off',
|
|
50
68
|
},
|
|
@@ -92,6 +110,13 @@ const reactHookRuleConfigs = [
|
|
|
92
110
|
[effect_cleanup_consistency_rule_1.EffectCleanupConsistencyRule.NAME]: effect_cleanup_consistency_rule_1.EffectCleanupConsistencyRule.build(),
|
|
93
111
|
},
|
|
94
112
|
},
|
|
113
|
+
// A hook or a util in a `.ts` file reaches the browser as well as a component does; a test stubs the browser on purpose.
|
|
114
|
+
{
|
|
115
|
+
files: SOURCE_FILES,
|
|
116
|
+
plugins: { [common_1.HOUSE_PLUGIN_NAMESPACE]: plugin_1.houseEslintPlugin },
|
|
117
|
+
rules: { [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: prefer_framework_api_rule_1.PreferFrameworkApiRule.build({ hooks: true }) },
|
|
118
|
+
},
|
|
119
|
+
{ files: TEST_FILES, rules: { [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: 'off' } },
|
|
95
120
|
];
|
|
96
121
|
/** `houseConfigs` for a React project: `reactNamingConventionConfigs`, the house rules, the async style rules, `no-leaked-render` and the hook rules. */
|
|
97
122
|
exports.reactHouseConfigs = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/linters/house/configs.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AACpD,4CAAyC;AACzC,wCAA4C;AAC5C,kDAA+D;AAC/D,+CAAiD;AACjD,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;AACzD,+EAAwE;AACxE,mEAA6D;AAC7D,2DAAqD;AACrD,qCAA6C;AAE7C,MAAM,YAAY,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAC/C,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAEnF;;;GAGG;AACH,MAAM,YAAY,GAAG,+CAA+C,CAAC;AAErE;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAoB;IACxC;QACE,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,EAAE,CAAC,+BAAsB,CAAC,EAAE,0BAAiB,EAAE;QACxD,KAAK,EAAE;YACL,CAAC,sCAAgB,CAAC,IAAI,CAAC,EAAE,sCAAgB,CAAC,KAAK,EAAE;YACjD,CAAC,kCAAc,CAAC,IAAI,CAAC,EAAE,kCAAc,CAAC,KAAK,EAAE;YAC7C,CAAC,8CAAoB,CAAC,IAAI,CAAC,EAAE,8CAAoB,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YAC7E,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;SACtD;KACF;IACD;QACE,KAAK,EAAE,UAAU;QACjB,KAAK,EAAE;YACL,CAAC,kCAAc,CAAC,IAAI,CAAC,EAAE,KAAK;YAC5B,CAAC,8CAAoB,CAAC,IAAI,CAAC,EAAE,KAAK;YAClC,CAAC,YAAY,CAAC,EAAE,KAAK;SACtB;KACF;CACF,CAAC;AAEF;;;;;;;;;;GAUG;AACU,QAAA,YAAY,GAAoB;IAC3C,GAAG,gCAAuB;IAC1B,GAAG,gBAAgB;IACnB,GAAG,8BAAgB;IACnB,GAAG,wBAAc;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,gBAAgB,GAAoB;IACxC;QACE,KAAK,EAAE,qBAAS;QAChB,OAAO,EAAE,EAAE,CAAC,+BAAsB,CAAC,EAAE,0BAAiB,EAAE;QACxD,KAAK,EAAE,EAAE,CAAC,0CAAkB,CAAC,IAAI,CAAC,EAAE,0CAAkB,CAAC,KAAK,EAAE,EAAE;KACjE;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,oBAAoB,GAAoB;IAC5C;QACE,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,EAAE,CAAC,+BAAsB,CAAC,EAAE,0BAAiB,EAAE;QACxD,KAAK,EAAE;YACL,CAAC,qDAAuB,CAAC,IAAI,CAAC,EAAE,qDAAuB,CAAC,KAAK,EAAE;YAC/D,CAAC,8DAA4B,CAAC,IAAI,CAAC,EAAE,8DAA4B,CAAC,KAAK,EAAE;SAC1E;KACF;
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/linters/house/configs.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AACpD,4CAAyC;AACzC,wCAA4C;AAC5C,kDAA+D;AAC/D,+CAAiD;AACjD,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;AACzD,+EAAwE;AACxE,mEAA6D;AAC7D,2DAAqD;AACrD,mFAA4E;AAC5E,2EAAqE;AACrE,uEAAiE;AACjE,2EAAqE;AACrE,mEAA8D;AAC9D,yEAAmE;AACnE,6EAAuE;AACvE,qCAA6C;AAE7C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AAsB,CAAC,IAAI,CAAC,EAAE,kDAAsB,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE;KACxF;IACD,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,kDAAsB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;CACvE,CAAC;AAEF,yJAAyJ;AAC5I,QAAA,iBAAiB,GAAoB;IAChD,GAAG,2CAA4B;IAC/B,GAAG,gBAAgB;IACnB,GAAG,8BAAgB;IACnB,GAAG,wBAAc;IACjB,GAAG,gBAAgB;IACnB,GAAG,oBAAoB;CACxB,CAAC","sourcesContent":["import type { Linter } from 'eslint';\nimport { namingConventionConfigs } from '../eslint';\nimport { JSX_FILES } from '../jsx-files';\nimport { paddingConfigs } from '../padding';\nimport { reactNamingConventionConfigs } from '../react-eslint';\nimport { asyncRuleConfigs } from './async-rules';\nimport { HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ConstClassValuesRule } from './const-class-values.rule';\nimport { EffectCleanupConsistencyRule } from './effect-cleanup-consistency.rule';\nimport { MaxParamsOwnRule } from './max-params-own.rule';\nimport { NoAsyncHookCallbackRule } from './no-async-hook-callback.rule';\nimport { NoLeakedRenderRule } from './no-leaked-render.rule';\nimport { NoNewErrorRule } from './no-new-error.rule';\nimport { NoShadowFrameworkTypeRule } from './no-shadow-framework-type.rule';\nimport { PreferFrameworkApiRule } from './prefer-framework-api.rule';\nimport { PreferHttpMethodRule } from './prefer-http-method.rule';\nimport { PreferPromiseSleepRule } from './prefer-promise-sleep.rule';\nimport { PreferTNullableRule } from './prefer-tnullable.rule';\nimport { TypedRouteContextRule } from './typed-route-context.rule';\nimport { ZodSchemaConventionRule } from './zod-schema-convention.rule';\nimport { houseEslintPlugin } from './plugin';\n\nconst SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];\nconst TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];\n\n/**\n * V-C-10: no explicit cast. `as const` is always allowed; `satisfies`, a generic or a narrower type\n * replaces the rest.\n */\nconst NO_CAST_RULE = '@typescript-eslint/consistent-type-assertions';\n\n/**\n * The house rules: at most 5 positional parameters on a function we write, and errors thrown through\n * `getError` only. Tests are exempt from `no-new-error`: a test throws a plain `Error` on purpose, to\n * stand in for what a driver or a third-party library throws.\n *\n * Two rules only warn, so a project adopts them without failing its lint: `const-class-values` (V-C-08, a\n * string-literal union in an exported declaration) and `consistent-type-assertions` (V-C-10, an `as X`\n * cast). Tests are exempt from both: a test stubs what it does not build.\n */\nconst houseRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [MaxParamsOwnRule.NAME]: MaxParamsOwnRule.build(),\n [NoNewErrorRule.NAME]: NoNewErrorRule.build(),\n [NoShadowFrameworkTypeRule.NAME]: NoShadowFrameworkTypeRule.build(),\n [PreferTNullableRule.NAME]: PreferTNullableRule.build(),\n [PreferPromiseSleepRule.NAME]: PreferPromiseSleepRule.build(),\n [PreferHttpMethodRule.NAME]: PreferHttpMethodRule.build(),\n [PreferFrameworkApiRule.NAME]: PreferFrameworkApiRule.build({ hooks: false }),\n [ConstClassValuesRule.NAME]: ConstClassValuesRule.build({ severity: 'warn' }),\n [ZodSchemaConventionRule.NAME]: ZodSchemaConventionRule.build(),\n [TypedRouteContextRule.NAME]: TypedRouteContextRule.build(),\n [NO_CAST_RULE]: ['warn', { assertionStyle: 'never' }],\n },\n },\n {\n files: TEST_FILES,\n rules: {\n [NoNewErrorRule.NAME]: 'off',\n [NoShadowFrameworkTypeRule.NAME]: 'off',\n [PreferPromiseSleepRule.NAME]: 'off',\n [PreferHttpMethodRule.NAME]: 'off',\n [PreferFrameworkApiRule.NAME]: 'off',\n [ConstClassValuesRule.NAME]: 'off',\n [NO_CAST_RULE]: 'off',\n },\n },\n];\n\n/**\n * The ESLint side of a project that lints with oxlint: the naming convention, the house rules and the async style\n * rules - everything oxlint cannot express. Run it next to `oxlintConfigs`.\n *\n * ```js\n * // .configs/lints/eslint.config.mjs\n * import { houseConfigs } from '@venizia/dev-configs/linters';\n *\n * export default houseConfigs;\n * ```\n */\nexport const houseConfigs: Linter.Config[] = [\n ...namingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n];\n\n/**\n * The React house rule: a JSX child is drawn with `cond ? <X /> : null`, never `cond && <X />`, which\n * draws `0` when `cond` is `0`.\n */\nconst reactRuleConfigs: Linter.Config[] = [\n {\n files: JSX_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [NoLeakedRenderRule.NAME]: NoLeakedRenderRule.build() },\n },\n];\n\n/**\n * The hook rules: a hook never gets an async function (`no-async-hook-callback`), and an effect callback returns a\n * cleanup on every path or on none (`effect-cleanup-consistency`). Hooks live in `.ts` files too, so it covers all\n * source files.\n */\nconst reactHookRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [NoAsyncHookCallbackRule.NAME]: NoAsyncHookCallbackRule.build(),\n [EffectCleanupConsistencyRule.NAME]: EffectCleanupConsistencyRule.build(),\n },\n },\n // A hook or a util in a `.ts` file reaches the browser as well as a component does; a test stubs the browser on purpose.\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [PreferFrameworkApiRule.NAME]: PreferFrameworkApiRule.build({ hooks: true }) },\n },\n { files: TEST_FILES, rules: { [PreferFrameworkApiRule.NAME]: 'off' } },\n];\n\n/** `houseConfigs` for a React project: `reactNamingConventionConfigs`, the house rules, the async style rules, `no-leaked-render` and the hook rules. */\nexport const reactHouseConfigs: Linter.Config[] = [\n ...reactNamingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n ...reactRuleConfigs,\n ...reactHookRuleConfigs,\n];\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Linter, Rule } from 'eslint';
|
|
2
2
|
import type { TRuleSeverity } from '../rules/common';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
|
|
5
5
|
* never a union of string literals in an exported declaration: a type alias, an interface member, a
|
|
6
6
|
* generic constraint, a parameter or a return type of an exported function or class.
|
|
7
7
|
*
|
|
@@ -11,7 +11,7 @@ import type { TRuleSeverity } from '../rules/common';
|
|
|
11
11
|
* matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.
|
|
12
12
|
*/
|
|
13
13
|
export declare class ConstClassValuesRule {
|
|
14
|
-
static readonly NAME = "venizia/const-class-values";
|
|
14
|
+
static readonly NAME = "@venizia/const-class-values";
|
|
15
15
|
static readonly RULE: Rule.RuleModule;
|
|
16
16
|
static build(opts?: {
|
|
17
17
|
severity?: TRuleSeverity;
|
|
@@ -4,6 +4,12 @@ exports.ConstClassValuesRule = void 0;
|
|
|
4
4
|
const common_1 = require("./common");
|
|
5
5
|
/** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */
|
|
6
6
|
const KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);
|
|
7
|
+
/** The node types that take type arguments, each with the field that holds the type's name. */
|
|
8
|
+
const TYPE_NAME_KEYS = new Map([
|
|
9
|
+
[common_1.AstNodeTypes.TYPE_REFERENCE, 'typeName'],
|
|
10
|
+
[common_1.AstNodeTypes.INTERFACE_HERITAGE, 'expression'],
|
|
11
|
+
[common_1.AstNodeTypes.CLASS_IMPLEMENTS, 'expression'],
|
|
12
|
+
]);
|
|
7
13
|
/** The union is a type argument of a key-set utility type, or the key range of a mapped type. */
|
|
8
14
|
const isKeySet = (opts) => {
|
|
9
15
|
const parent = common_1.AstNode.readField({ node: opts.node, key: 'parent' });
|
|
@@ -14,12 +20,15 @@ const isKeySet = (opts) => {
|
|
|
14
20
|
return false;
|
|
15
21
|
}
|
|
16
22
|
const reference = common_1.AstNode.readField({ node: parent, key: 'parent' });
|
|
23
|
+
const key = TYPE_NAME_KEYS.get(String(common_1.AstNode.getType({ node: reference })));
|
|
24
|
+
if (key === undefined) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
17
27
|
const name = common_1.AstNode.readField({
|
|
18
|
-
node: common_1.AstNode.readField({ node: reference, key
|
|
28
|
+
node: common_1.AstNode.readField({ node: reference, key }),
|
|
19
29
|
key: 'name',
|
|
20
30
|
});
|
|
21
|
-
return
|
|
22
|
-
KEY_SET_TYPES.has(String(name)));
|
|
31
|
+
return KEY_SET_TYPES.has(String(name));
|
|
23
32
|
};
|
|
24
33
|
/** The statement of the module that holds the node: the node's last ancestor before `Program`. */
|
|
25
34
|
const topLevelStatement = (opts) => {
|
|
@@ -46,7 +55,7 @@ const isNullish = (opts) => {
|
|
|
46
55
|
return type === common_1.AstNodeTypes.NULL_KEYWORD || type === common_1.AstNodeTypes.UNDEFINED_KEYWORD;
|
|
47
56
|
};
|
|
48
57
|
/**
|
|
49
|
-
*
|
|
58
|
+
* `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
|
|
50
59
|
* never a union of string literals in an exported declaration: a type alias, an interface member, a
|
|
51
60
|
* generic constraint, a parameter or a return type of an exported function or class.
|
|
52
61
|
*
|
|
@@ -62,7 +71,7 @@ class ConstClassValuesRule {
|
|
|
62
71
|
type: 'suggestion',
|
|
63
72
|
schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],
|
|
64
73
|
messages: {
|
|
65
|
-
constClass:
|
|
74
|
+
constClass: "An enumerable string is a class that extends `ConstClass`, typed as `TConstValue<typeof X>`, not a union of string literals: `import { ConstClass, type TConstValue } from '@venizia/ignis-helpers/common';`",
|
|
66
75
|
},
|
|
67
76
|
},
|
|
68
77
|
create: (context) =>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,CAAC;wBACvE,OAAO;oBACT,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;gBACpD,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAA2D,EAAE;QACxE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAEjD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9E,CAAC;;AApEH,oDAqEC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */\nconst KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);\n\n/** The union is a type argument of a key-set utility type, or the key range of a mapped type. */\nconst isKeySet = (opts: { node: unknown }): boolean => {\n const parent = AstNode.readField({ node: opts.node, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.MAPPED_TYPE) {\n return true;\n }\n\n if (AstNode.getType({ node: parent }) !== AstNodeTypes.TYPE_PARAMETER_INSTANTIATION) {\n return false;\n }\n\n const reference = AstNode.readField({ node: parent, key: 'parent' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: reference, key: 'typeName' }),\n key: 'name',\n });\n\n return (\n AstNode.getType({ node: reference }) === AstNodeTypes.TYPE_REFERENCE &&\n KEY_SET_TYPES.has(String(name))\n );\n};\n\n/** The statement of the module that holds the node: the node's last ancestor before `Program`. */\nconst topLevelStatement = (opts: { node: unknown }): unknown => {\n let current = opts.node;\n\n while (current) {\n const parent = AstNode.readField({ node: current, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.PROGRAM) {\n return current;\n }\n\n current = parent;\n }\n\n return undefined;\n};\n\nconst isStringLiteral = (opts: { member: unknown }): boolean => {\n const { member } = opts;\n\n return (\n AstNode.getType({ node: member }) === AstNodeTypes.LITERAL_TYPE &&\n typeof AstNode.readField({\n node: AstNode.readField({ node: member, key: 'literal' }),\n key: 'value',\n }) === 'string'\n );\n};\n\nconst isNullish = (opts: { member: unknown }): boolean => {\n const type = AstNode.getType({ node: opts.member });\n\n return type === AstNodeTypes.NULL_KEYWORD || type === AstNodeTypes.UNDEFINED_KEYWORD;\n};\n\n/**\n * `venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,\n * never a union of string literals in an exported declaration: a type alias, an interface member, a\n * generic constraint, a parameter or a return type of an exported function or class.\n *\n * Not counted: a union that is not all string literals (a `null` or `undefined` member is ignored),\n * a key set (`Pick`, `Omit`, `Extract`, `Exclude`, `Record` arguments and mapped-type keys), and a\n * declaration that is not exported. `namePattern` narrows the rule to exported type aliases whose name\n * matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.\n */\nexport class ConstClassValuesRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/const-class-values`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],\n messages: {\n constClass:\n 'An enumerable string is a const class plus TConstValue<typeof X>, not a union of string literals.',\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const configured = AstNode.readField({ node: options, key: 'namePattern' });\n const namePattern = typeof configured === 'string' ? new RegExp(configured) : undefined;\n\n const isNamed = (opts: { statement: unknown; node: unknown }) => {\n const { statement, node } = opts;\n const declaration = AstNode.readField({ node: statement, key: 'declaration' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: declaration, key: 'id' }),\n key: 'name',\n });\n\n return (\n namePattern === undefined ||\n (AstNode.getType({ node: declaration }) === AstNodeTypes.TYPE_ALIAS_DECLARATION &&\n AstNode.readField({ node: declaration, key: 'typeAnnotation' }) === node &&\n typeof name === 'string' &&\n namePattern.test(name))\n );\n };\n\n return {\n [AstNodeTypes.UNION_TYPE]: (node: Rule.Node) => {\n const members = AstNode.readField({ node, key: 'types' });\n\n if (!Array.isArray(members)) {\n return;\n }\n\n const values = members.filter((member) => !isNullish({ member }));\n\n if (values.length < 2 || !values.every((member) => isStringLiteral({ member }))) {\n return;\n }\n\n const statement = topLevelStatement({ node });\n const statementType = AstNode.getType({ node: statement });\n const isExported =\n statementType === AstNodeTypes.EXPORT_NAMED_DECLARATION ||\n statementType === AstNodeTypes.EXPORT_DEFAULT_DECLARATION;\n\n if (!isExported || isKeySet({ node }) || !isNamed({ statement, node })) {\n return;\n }\n\n context.report({ node, messageId: 'constClass' });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; namePattern?: string } = {}): Linter.RuleEntry {\n const { severity = 'error', namePattern } = opts;\n\n return namePattern === undefined ? [severity] : [severity, { namePattern }];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"const-class-values.rule.js","sourceRoot":"","sources":["../../../src/linters/house/const-class-values.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE,yGAAyG;AACzG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhF,+FAA+F;AAC/F,MAAM,cAAc,GAAgC,IAAI,GAAG,CAAC;IAC1D,CAAC,qBAAY,CAAC,cAAc,EAAE,UAAU,CAAC;IACzC,CAAC,qBAAY,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAC/C,CAAC,qBAAY,CAAC,gBAAgB,EAAE,YAAY,CAAC;CAC9C,CAAC,CAAC;AAEH,iGAAiG;AACjG,MAAM,QAAQ,GAAG,CAAC,IAAuB,EAAW,EAAE;IACpD,MAAM,MAAM,GAAG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,GAAG,IAAI,CAAC;QAEjD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9E,CAAC;;AApEH,oDAqEC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */\nconst KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);\n\n/** The node types that take type arguments, each with the field that holds the type's name. */\nconst TYPE_NAME_KEYS: ReadonlyMap<string, string> = new Map([\n [AstNodeTypes.TYPE_REFERENCE, 'typeName'],\n [AstNodeTypes.INTERFACE_HERITAGE, 'expression'],\n [AstNodeTypes.CLASS_IMPLEMENTS, 'expression'],\n]);\n\n/** The union is a type argument of a key-set utility type, or the key range of a mapped type. */\nconst isKeySet = (opts: { node: unknown }): boolean => {\n const parent = AstNode.readField({ node: opts.node, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.MAPPED_TYPE) {\n return true;\n }\n\n if (AstNode.getType({ node: parent }) !== AstNodeTypes.TYPE_PARAMETER_INSTANTIATION) {\n return false;\n }\n\n const reference = AstNode.readField({ node: parent, key: 'parent' });\n const key = TYPE_NAME_KEYS.get(String(AstNode.getType({ node: reference })));\n\n if (key === undefined) {\n return false;\n }\n\n const name = AstNode.readField({\n node: AstNode.readField({ node: reference, key }),\n key: 'name',\n });\n\n return KEY_SET_TYPES.has(String(name));\n};\n\n/** The statement of the module that holds the node: the node's last ancestor before `Program`. */\nconst topLevelStatement = (opts: { node: unknown }): unknown => {\n let current = opts.node;\n\n while (current) {\n const parent = AstNode.readField({ node: current, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.PROGRAM) {\n return current;\n }\n\n current = parent;\n }\n\n return undefined;\n};\n\nconst isStringLiteral = (opts: { member: unknown }): boolean => {\n const { member } = opts;\n\n return (\n AstNode.getType({ node: member }) === AstNodeTypes.LITERAL_TYPE &&\n typeof AstNode.readField({\n node: AstNode.readField({ node: member, key: 'literal' }),\n key: 'value',\n }) === 'string'\n );\n};\n\nconst isNullish = (opts: { member: unknown }): boolean => {\n const type = AstNode.getType({ node: opts.member });\n\n return type === AstNodeTypes.NULL_KEYWORD || type === AstNodeTypes.UNDEFINED_KEYWORD;\n};\n\n/**\n * `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,\n * never a union of string literals in an exported declaration: a type alias, an interface member, a\n * generic constraint, a parameter or a return type of an exported function or class.\n *\n * Not counted: a union that is not all string literals (a `null` or `undefined` member is ignored),\n * a key set (`Pick`, `Omit`, `Extract`, `Exclude`, `Record` arguments and mapped-type keys), and a\n * declaration that is not exported. `namePattern` narrows the rule to exported type aliases whose name\n * matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.\n */\nexport class ConstClassValuesRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/const-class-values`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],\n messages: {\n constClass:\n \"An enumerable string is a class that extends `ConstClass`, typed as `TConstValue<typeof X>`, not a union of string literals: `import { ConstClass, type TConstValue } from '@venizia/ignis-helpers/common';`\",\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const configured = AstNode.readField({ node: options, key: 'namePattern' });\n const namePattern = typeof configured === 'string' ? new RegExp(configured) : undefined;\n\n const isNamed = (opts: { statement: unknown; node: unknown }) => {\n const { statement, node } = opts;\n const declaration = AstNode.readField({ node: statement, key: 'declaration' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: declaration, key: 'id' }),\n key: 'name',\n });\n\n return (\n namePattern === undefined ||\n (AstNode.getType({ node: declaration }) === AstNodeTypes.TYPE_ALIAS_DECLARATION &&\n AstNode.readField({ node: declaration, key: 'typeAnnotation' }) === node &&\n typeof name === 'string' &&\n namePattern.test(name))\n );\n };\n\n return {\n [AstNodeTypes.UNION_TYPE]: (node: Rule.Node) => {\n const members = AstNode.readField({ node, key: 'types' });\n\n if (!Array.isArray(members)) {\n return;\n }\n\n const values = members.filter((member) => !isNullish({ member }));\n\n if (values.length < 2 || !values.every((member) => isStringLiteral({ member }))) {\n return;\n }\n\n const statement = topLevelStatement({ node });\n const statementType = AstNode.getType({ node: statement });\n const isExported =\n statementType === AstNodeTypes.EXPORT_NAMED_DECLARATION ||\n statementType === AstNodeTypes.EXPORT_DEFAULT_DECLARATION;\n\n if (!isExported || isKeySet({ node }) || !isNamed({ statement, node })) {\n return;\n }\n\n context.report({ node, messageId: 'constClass' });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; namePattern?: string } = {}): Linter.RuleEntry {\n const { severity = 'error', namePattern } = opts;\n\n return namePattern === undefined ? [severity] : [severity, { namePattern }];\n }\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import type { TRuleSeverity } from '../rules/common';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
|
|
5
5
|
* returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React
|
|
6
6
|
* with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the
|
|
7
7
|
* end both mean "no value". It uses ESLint's code path analysis the way `consistent-return` does, so an
|
|
8
8
|
* unreachable end of the function is not a path. A nested function's own `return` is not counted.
|
|
9
9
|
*/
|
|
10
10
|
export declare class EffectCleanupConsistencyRule {
|
|
11
|
-
static readonly NAME = "venizia/effect-cleanup-consistency";
|
|
11
|
+
static readonly NAME = "@venizia/effect-cleanup-consistency";
|
|
12
12
|
static readonly RULE: Rule.RuleModule;
|
|
13
13
|
static build(opts?: {
|
|
14
14
|
severity?: TRuleSeverity;
|
|
@@ -4,7 +4,7 @@ exports.EffectCleanupConsistencyRule = void 0;
|
|
|
4
4
|
const common_1 = require("./common");
|
|
5
5
|
const hook_support_1 = require("./hook-support");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
|
|
8
8
|
* returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React
|
|
9
9
|
* with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the
|
|
10
10
|
* end both mean "no value". It uses ESLint's code path analysis the way `consistent-return` does, so an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-cleanup-consistency.rule.js","sourceRoot":"","sources":["../../../src/linters/house/effect-cleanup-consistency.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AACzE,iDAA6C;AAW7C;;;;;;GAMG;AACH,MAAa,4BAA4B;aACvB,SAAI,GAAG,GAAG,+BAAsB,6BAA6B,CAAC;aAE9D,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE;gBACR,YAAY,EACV,8IAA8I;aACjJ;SACF;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;YAC3C,IAAI,KAAiC,CAAC;YAEtC,MAAM,SAAS,GAAG,CAAC,IAAe,EAAE,EAAE;gBACpC,MAAM,OAAO,GAAG,KAAK,CAAC;gBAEtB,IACE,CAAC,OAAO,EAAE,IAAI;oBACd,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC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AClC,CAAC;;AAtFH,oEAuFC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { HookSupport } from './hook-support';\n\n/** What the rule knows about the function whose code path is open; one per function, so a nested function is its own. */\ninterface IFunctionFrame {\n upper: IFunctionFrame | undefined;\n hook: string | undefined;\n returnsValue: boolean;\n returnsNothing: boolean;\n segments: Set<{ reachable: boolean }>;\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"effect-cleanup-consistency.rule.js","sourceRoot":"","sources":["../../../src/linters/house/effect-cleanup-consistency.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AACzE,iDAA6C;AAW7C;;;;;;GAMG;AACH,MAAa,4BAA4B;aACvB,SAAI,GAAG,GAAG,+BAAsB,6BAA6B,CAAC;aAE9D,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE;gBACR,YAAY,EACV,8IAA8I;aACjJ;SACF;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;YAC3C,IAAI,KAAiC,CAAC;YAEtC,MAAM,SAAS,GAAG,CAAC,IAAe,EAAE,EAAE;gBACpC,MAAM,OAAO,GAAG,KAAK,CAAC;gBAEtB,IACE,CAAC,OAAO,EAAE,IAAI;oBACd,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;wBACjE,qBAAY,CAAC,eAAe,EAC9B,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,MAAM,cAAc,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CA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C;gBACJ,CAAC;gBACD,aAAa,EAAE,GAAG,EAAE;oBAClB,KAAK,GAAG,KAAK,EAAE,KAAK,CAAC;gBACvB,CAAC;gBACD,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;gBACjE,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;gBAClE,iCAAiC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC5E,+BAA+B,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC7E,CAAC,qBAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBACnD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACX,OAAO;oBACT,CAAC;oBAED,IAAI,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;wBACjD,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;oBAC5B,CAAC;yBAAM,CAAC;wBACN,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC;oBAC9B,CAAC;gBACH,CAAC;gBACD,yBAAyB,EAAE,SAAS;gBACpC,8BAA8B,EAAE,SAAS;aAC1C,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AAtFH,oEAuFC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { HookSupport } from './hook-support';\n\n/** What the rule knows about the function whose code path is open; one per function, so a nested function is its own. */\ninterface IFunctionFrame {\n upper: IFunctionFrame | undefined;\n hook: string | undefined;\n returnsValue: boolean;\n returnsNothing: boolean;\n segments: Set<{ reachable: boolean }>;\n}\n\n/**\n * `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`\n * returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React\n * with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the\n * end both mean \"no value\". It uses ESLint's code path analysis the way `consistent-return` does, so an\n * unreachable end of the function is not a path. A nested function's own `return` is not counted.\n */\nexport class EffectCleanupConsistencyRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/effect-cleanup-consistency`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n inconsistent:\n 'The callback of `{{hook}}` returns a cleanup on some paths only; return one on every path (a no-op `() => {}` for an early exit) or on none.',\n },\n },\n create: (context) => {\n const targets = new Map<unknown, string>();\n let frame: IFunctionFrame | undefined;\n\n const checkExit = (node: Rule.Node) => {\n const current = frame;\n\n if (\n !current?.hook ||\n AstNode.getType({ node: AstNode.readField({ node, key: 'body' }) }) !==\n AstNodeTypes.BLOCK_STATEMENT\n ) {\n return;\n }\n\n const endIsReachable = [...current.segments].some((segment) => segment.reachable);\n\n if (current.returnsValue && (current.returnsNothing || endIsReachable)) {\n context.report({ node, messageId: 'inconsistent', data: { hook: current.hook } });\n }\n };\n\n return {\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const hook = HookSupport.calleeName({ call: node });\n const args = AstNode.readField({ node, key: 'arguments' });\n\n if (\n !HookSupport.isEffectHook({ name: hook }) ||\n hook === undefined ||\n !Array.isArray(args)\n ) {\n return;\n }\n\n if (HookSupport.isCallback({ node: args[0] })) {\n targets.set(args[0], hook);\n }\n },\n onCodePathStart: (_codePath, node) => {\n frame = {\n upper: frame,\n hook: targets.get(node),\n returnsValue: false,\n returnsNothing: false,\n segments: new Set(),\n };\n },\n onCodePathEnd: () => {\n frame = frame?.upper;\n },\n onCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n onUnreachableCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onUnreachableCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n [AstNodeTypes.RETURN_STATEMENT]: (node: Rule.Node) => {\n if (!frame) {\n return;\n }\n\n if (AstNode.readField({ node, key: 'argument' })) {\n frame.returnsValue = true;\n } else {\n frame.returnsNothing = true;\n }\n },\n 'FunctionExpression:exit': checkExit,\n 'ArrowFunctionExpression:exit': checkExit,\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { TBrowserApiMatch } from './browser-api-patterns';
|
|
2
|
+
/** How a hand-written form shows up in code. */
|
|
3
|
+
export type TFrameworkApiMatch = TBrowserApiMatch
|
|
4
|
+
/**
|
|
5
|
+
* A member of a global object read or called: `localStorage.getItem`; `window.` in front is the same object. With
|
|
6
|
+
* `property`, the source of a regular expression, only a member whose name matches it. With `isReadOnly`, an
|
|
7
|
+
* assignment to it and a `delete` of it pass.
|
|
8
|
+
*/
|
|
9
|
+
| {
|
|
10
|
+
type: 'member';
|
|
11
|
+
objects: ReadonlyArray<string>;
|
|
12
|
+
property?: string;
|
|
13
|
+
isReadOnly?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A string or a template whose text matches `pattern`, the source of a regular expression. With
|
|
17
|
+
* `isFallbackOnly`, only where it stands in for a missing value: after `??`, `||`, `??=` or `||=`, a
|
|
18
|
+
* parameter default, or a `default`, `defaultValue` or `fallback` property.
|
|
19
|
+
*/
|
|
20
|
+
| {
|
|
21
|
+
type: 'literal';
|
|
22
|
+
pattern: string;
|
|
23
|
+
isFallbackOnly?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** An `import` or `import()` of one of these modules; `import type` is not one. */
|
|
26
|
+
| {
|
|
27
|
+
type: 'import';
|
|
28
|
+
sources: ReadonlyArray<string>;
|
|
29
|
+
}
|
|
30
|
+
/** Every node an ESLint selector matches. */
|
|
31
|
+
| {
|
|
32
|
+
type: 'selector';
|
|
33
|
+
selector: string;
|
|
34
|
+
};
|
|
35
|
+
/** One hand-written form `@venizia/prefer-framework-api` reports anywhere in a file. */
|
|
36
|
+
export interface IFrameworkApiPattern {
|
|
37
|
+
/** The name `ignore` takes to switch the row off. */
|
|
38
|
+
id: string;
|
|
39
|
+
match: TFrameworkApiMatch;
|
|
40
|
+
/** The whole message. */
|
|
41
|
+
message: string;
|
|
42
|
+
/** The row applies only in a package that depends on a package whose name starts with this. */
|
|
43
|
+
dependsOn?: string;
|
|
44
|
+
/** The package that writes the API: the row is not reported in it. */
|
|
45
|
+
owner?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a
|
|
49
|
+
* file: a service or a module function can call the API as well as a component.
|
|
50
|
+
*/
|
|
51
|
+
export declare class FrameworkApiPatterns {
|
|
52
|
+
static readonly TABLE: ReadonlyArray<IFrameworkApiPattern>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=framework-api-patterns.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FrameworkApiPatterns = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a
|
|
6
|
+
* file: a service or a module function can call the API as well as a component.
|
|
7
|
+
*/
|
|
8
|
+
class FrameworkApiPatterns {
|
|
9
|
+
static { this.TABLE = [
|
|
10
|
+
{
|
|
11
|
+
id: 'application-error-instanceof',
|
|
12
|
+
match: {
|
|
13
|
+
type: 'selector',
|
|
14
|
+
selector: "BinaryExpression[operator='instanceof'][right.name='ApplicationError']",
|
|
15
|
+
},
|
|
16
|
+
message: "Use `isApplicationError(error)`, not `instanceof ApplicationError`, which fails across two installed copies: `import { isApplicationError } from '@venizia/ignis-helpers/core';`",
|
|
17
|
+
dependsOn: '@venizia/ignis',
|
|
18
|
+
owner: '@venizia/ignis-inversion',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'process-env',
|
|
22
|
+
// Only the names `AppEnvs` keeps: it drops a key without its prefix, such as `PORT`.
|
|
23
|
+
match: { type: 'member', objects: ['process.env'], property: '^APP_ENV_', isReadOnly: true },
|
|
24
|
+
message: "Read an `APP_ENV_` name with `AppEnvs.get(key)`, not `process.env`: `import { AppEnvs } from '@venizia/ignis-helpers';`",
|
|
25
|
+
dependsOn: '@venizia/ignis',
|
|
26
|
+
owner: '@venizia/ignis-helpers',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'env-boolean-comparison',
|
|
30
|
+
match: {
|
|
31
|
+
type: 'selector',
|
|
32
|
+
selector: ['left', 'right']
|
|
33
|
+
.map((side) => {
|
|
34
|
+
const other = side === 'left' ? 'right' : 'left';
|
|
35
|
+
return `BinaryExpression[operator=/^[!=]==?$/][${side}.callee.property.name='get'][${side}.callee.object.name=/^(AppEnvs|applicationEnvironment)$/][${other}.value=/^(true|false)$/]`;
|
|
36
|
+
})
|
|
37
|
+
.join(', '),
|
|
38
|
+
},
|
|
39
|
+
message: "Read a boolean setting with `ParseUtility.toBoolean({ input: AppEnvs.get(key) })`, not a comparison with `'true'` or `'false'`: `import { ParseUtility } from '@venizia/ignis-helpers/core';`",
|
|
40
|
+
dependsOn: '@venizia/ignis',
|
|
41
|
+
owner: '@venizia/ignis-helpers',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'web-storage',
|
|
45
|
+
match: { type: 'member', objects: ['localStorage', 'sessionStorage'] },
|
|
46
|
+
message: "Use `BrowserStorage` (or the `useStoredState` hook), not `localStorage` / `sessionStorage`: it never throws: `import { BrowserStorage } from '@venizia/ardor-kernel';`",
|
|
47
|
+
dependsOn: '@venizia/ardor',
|
|
48
|
+
owner: '@venizia/ardor-kernel',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'localhost-url',
|
|
52
|
+
match: {
|
|
53
|
+
type: 'literal',
|
|
54
|
+
pattern: '^https?://(?:localhost|127\\.0\\.0\\.1)(?![\\w.-])',
|
|
55
|
+
isFallbackOnly: true,
|
|
56
|
+
},
|
|
57
|
+
message: "Require the value instead, a `localhost` URL as a fallback is used wherever the setting is missing: `AppEnvs.getRequired(key)` (`import { AppEnvs } from '@venizia/ignis-helpers';`) or `RuntimeConfig.getRequired({ key })` (`import { RuntimeConfig } from '@venizia/ardor-kernel';`).",
|
|
58
|
+
},
|
|
59
|
+
]; }
|
|
60
|
+
}
|
|
61
|
+
exports.FrameworkApiPatterns = FrameworkApiPatterns;
|
|
62
|
+
//# sourceMappingURL=framework-api-patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-api-patterns.js","sourceRoot":"","sources":["../../../src/linters/house/framework-api-patterns.ts"],"names":[],"mappings":";;;AAmCA;;;GAGG;AACH,MAAa,oBAAoB;aACf,UAAK,GAAwC;QAC3D;YACE,EAAE,EAAE,8BAA8B;YAClC,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,wEAAwE;aACnF;YACD,OAAO,EACL,kLAAkL;YACpL,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,0BAA0B;SAClC;QACD;YACE,EAAE,EAAE,aAAa;YACjB,qFAAqF;YACrF,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE;YAC5F,OAAO,EACL,yHAAyH;YAC3H,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,wBAAwB;SAChC;QACD;YACE,EAAE,EAAE,wBAAwB;YAC5B,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;qBACxB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;oBACZ,MAAM,KAAK,GAAG,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;oBAEjD,OAAO,0CAA0C,IAAI,gCAAgC,IAAI,6DAA6D,KAAK,0BAA0B,CAAC;gBACxL,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC;aACd;YACD,OAAO,EACL,+LAA+L;YACjM,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,wBAAwB;SAChC;QACD;YACE,EAAE,EAAE,aAAa;YACjB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;YACtE,OAAO,EACL,wKAAwK;YAC1K,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,uBAAuB;SAC/B;QACD;YACE,EAAE,EAAE,eAAe;YACnB,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,oDAAoD;gBAC7D,cAAc,EAAE,IAAI;aACrB;YACD,OAAO,EACL,0RAA0R;SAC7R;KACF,CAAC;;AAzDJ,oDA0DC","sourcesContent":["import type { TBrowserApiMatch } from './browser-api-patterns';\n\n/** How a hand-written form shows up in code. */\nexport type TFrameworkApiMatch =\n | TBrowserApiMatch\n /**\n * A member of a global object read or called: `localStorage.getItem`; `window.` in front is the same object. With\n * `property`, the source of a regular expression, only a member whose name matches it. With `isReadOnly`, an\n * assignment to it and a `delete` of it pass.\n */\n | { type: 'member'; objects: ReadonlyArray<string>; property?: string; isReadOnly?: boolean }\n /**\n * A string or a template whose text matches `pattern`, the source of a regular expression. With\n * `isFallbackOnly`, only where it stands in for a missing value: after `??`, `||`, `??=` or `||=`, a\n * parameter default, or a `default`, `defaultValue` or `fallback` property.\n */\n | { type: 'literal'; pattern: string; isFallbackOnly?: boolean }\n /** An `import` or `import()` of one of these modules; `import type` is not one. */\n | { type: 'import'; sources: ReadonlyArray<string> }\n /** Every node an ESLint selector matches. */\n | { type: 'selector'; selector: string };\n\n/** One hand-written form `@venizia/prefer-framework-api` reports anywhere in a file. */\nexport interface IFrameworkApiPattern {\n /** The name `ignore` takes to switch the row off. */\n id: string;\n match: TFrameworkApiMatch;\n /** The whole message. */\n message: string;\n /** The row applies only in a package that depends on a package whose name starts with this. */\n dependsOn?: string;\n /** The package that writes the API: the row is not reported in it. */\n owner?: string;\n}\n\n/**\n * The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a\n * file: a service or a module function can call the API as well as a component.\n */\nexport class FrameworkApiPatterns {\n static readonly TABLE: ReadonlyArray<IFrameworkApiPattern> = [\n {\n id: 'application-error-instanceof',\n match: {\n type: 'selector',\n selector: \"BinaryExpression[operator='instanceof'][right.name='ApplicationError']\",\n },\n message:\n \"Use `isApplicationError(error)`, not `instanceof ApplicationError`, which fails across two installed copies: `import { isApplicationError } from '@venizia/ignis-helpers/core';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-inversion',\n },\n {\n id: 'process-env',\n // Only the names `AppEnvs` keeps: it drops a key without its prefix, such as `PORT`.\n match: { type: 'member', objects: ['process.env'], property: '^APP_ENV_', isReadOnly: true },\n message:\n \"Read an `APP_ENV_` name with `AppEnvs.get(key)`, not `process.env`: `import { AppEnvs } from '@venizia/ignis-helpers';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-helpers',\n },\n {\n id: 'env-boolean-comparison',\n match: {\n type: 'selector',\n selector: ['left', 'right']\n .map((side) => {\n const other = side === 'left' ? 'right' : 'left';\n\n return `BinaryExpression[operator=/^[!=]==?$/][${side}.callee.property.name='get'][${side}.callee.object.name=/^(AppEnvs|applicationEnvironment)$/][${other}.value=/^(true|false)$/]`;\n })\n .join(', '),\n },\n message:\n \"Read a boolean setting with `ParseUtility.toBoolean({ input: AppEnvs.get(key) })`, not a comparison with `'true'` or `'false'`: `import { ParseUtility } from '@venizia/ignis-helpers/core';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-helpers',\n },\n {\n id: 'web-storage',\n match: { type: 'member', objects: ['localStorage', 'sessionStorage'] },\n message:\n \"Use `BrowserStorage` (or the `useStoredState` hook), not `localStorage` / `sessionStorage`: it never throws: `import { BrowserStorage } from '@venizia/ardor-kernel';`\",\n dependsOn: '@venizia/ardor',\n owner: '@venizia/ardor-kernel',\n },\n {\n id: 'localhost-url',\n match: {\n type: 'literal',\n pattern: '^https?://(?:localhost|127\\\\.0\\\\.0\\\\.1)(?![\\\\w.-])',\n isFallbackOnly: true,\n },\n message:\n \"Require the value instead, a `localhost` URL as a fallback is used wherever the setting is missing: `AppEnvs.getRequired(key)` (`import { AppEnvs } from '@venizia/ignis-helpers';`) or `RuntimeConfig.getRequired({ key })` (`import { RuntimeConfig } from '@venizia/ardor-kernel';`).\",\n },\n ];\n}\n"]}
|