eslint-config-agent 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/index.js +1 -0
- package/package.json +3 -3
- package/rules/index.js +3 -0
- package/rules/no-trivial-type-aliases/index.js +112 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. See [Conven
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
## [1.4.4](https://github.com/tupe12334/eslint-config/compare/v1.4.3...v1.4.4) (2025-09-30)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add no-trivial-type-aliases rule with examples and tests ([27da82f](https://github.com/tupe12334/eslint-config/commit/27da82f53a084e2cdb88b26b06b53e11992a2a32))
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* restore eslint-plugin-single-export dependency in package.json and pnpm-lock.yaml ([7b273a5](https://github.com/tupe12334/eslint-config/commit/7b273a595c7ee1c5c5919b98f800fdca2c1d6fb9))
|
|
16
|
+
|
|
7
17
|
## [1.4.3](https://github.com/tupe12334/eslint-config/compare/v1.4.2...v1.4.3) (2025-09-27)
|
|
8
18
|
|
|
9
19
|
### Features
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-agent",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "ESLint configuration package with TypeScript support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -107,7 +107,6 @@
|
|
|
107
107
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
108
108
|
"eslint-plugin-required-exports": "^0.2.0",
|
|
109
109
|
"eslint-plugin-security": "^3.0.1",
|
|
110
|
-
"eslint-plugin-single-export": "^1.1.2",
|
|
111
110
|
"eslint-plugin-storybook": "^9.1.5",
|
|
112
111
|
"globals": "^16.3.0",
|
|
113
112
|
"release-it": "^19.0.4",
|
|
@@ -116,6 +115,7 @@
|
|
|
116
115
|
"dependencies": {
|
|
117
116
|
"eslint-plugin-default": "^1.1.0",
|
|
118
117
|
"eslint-plugin-error": "^1.1.3",
|
|
119
|
-
"eslint-plugin-no-optional-chaining": "^1.0.0"
|
|
118
|
+
"eslint-plugin-no-optional-chaining": "^1.0.0",
|
|
119
|
+
"eslint-plugin-single-export": "^1.1.2"
|
|
120
120
|
}
|
|
121
121
|
}
|
package/rules/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { noNullishCoalescingConfig } from "./nullish-coalescing/index.js";
|
|
|
21
21
|
import { switchStatementsReturnTypeConfigs } from "./switch-statements-return-type/index.js";
|
|
22
22
|
import { switchCaseFunctionsReturnTypeConfigs } from "./switch-case-functions-return-type/index.js";
|
|
23
23
|
import { switchCaseExplicitReturnConfigs } from "./switch-case-explicit-return/index.js";
|
|
24
|
+
import { noTrivialTypeAliasesConfigs } from "./no-trivial-type-aliases/index.js";
|
|
24
25
|
|
|
25
26
|
// Plugin rule configurations
|
|
26
27
|
import { pluginRules } from "./plugin/index.js";
|
|
@@ -46,6 +47,7 @@ const allRules = {
|
|
|
46
47
|
switchStatementsReturnTypeConfigs,
|
|
47
48
|
switchCaseFunctionsReturnTypeConfigs,
|
|
48
49
|
switchCaseExplicitReturnConfigs,
|
|
50
|
+
noTrivialTypeAliasesConfigs,
|
|
49
51
|
|
|
50
52
|
// Plugin rule configurations
|
|
51
53
|
pluginRules,
|
|
@@ -74,6 +76,7 @@ export {
|
|
|
74
76
|
switchStatementsReturnTypeConfigs,
|
|
75
77
|
switchCaseFunctionsReturnTypeConfigs,
|
|
76
78
|
switchCaseExplicitReturnConfigs,
|
|
79
|
+
noTrivialTypeAliasesConfigs,
|
|
77
80
|
|
|
78
81
|
// Plugin rule configurations
|
|
79
82
|
pluginRules,
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule configuration for no-trivial-type-aliases
|
|
3
|
+
*
|
|
4
|
+
* This rule disallows trivial TypeScript type aliases that don't add semantic value.
|
|
5
|
+
* Trivial type aliases are direct assignments to primitive types, other types, or literals
|
|
6
|
+
* without any transformation.
|
|
7
|
+
*
|
|
8
|
+
* ## Rationale
|
|
9
|
+
*
|
|
10
|
+
* Trivial type aliases can make code harder to understand and maintain because they:
|
|
11
|
+
* - Add unnecessary indirection without semantic meaning
|
|
12
|
+
* - Increase cognitive load when reading code
|
|
13
|
+
* - Can make refactoring more difficult
|
|
14
|
+
* - Don't provide any type safety benefits
|
|
15
|
+
*
|
|
16
|
+
* ## Rule Details
|
|
17
|
+
*
|
|
18
|
+
* This rule flags the following patterns:
|
|
19
|
+
*
|
|
20
|
+
* ### ❌ Invalid (will trigger errors):
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Primitive type aliases
|
|
24
|
+
* type MyString = string;
|
|
25
|
+
* type MyNumber = number;
|
|
26
|
+
* type MyBoolean = boolean;
|
|
27
|
+
*
|
|
28
|
+
* // Direct type reference aliases
|
|
29
|
+
* type UserId = OtherId;
|
|
30
|
+
* type UserData = SomeOtherType;
|
|
31
|
+
*
|
|
32
|
+
* // Literal type aliases
|
|
33
|
+
* type Status = 'active';
|
|
34
|
+
* type Count = 42;
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ### ✅ Valid (will NOT trigger errors):
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Union types (add semantic meaning)
|
|
41
|
+
* type StringOrNumber = string | number;
|
|
42
|
+
* type Status = 'active' | 'inactive' | 'pending';
|
|
43
|
+
*
|
|
44
|
+
* // Generic types (parameterized)
|
|
45
|
+
* type Container<T> = { value: T };
|
|
46
|
+
* type Result<T, E = Error> = T | E;
|
|
47
|
+
*
|
|
48
|
+
* // Mapped types (transformation)
|
|
49
|
+
* type Partial<T> = { [P in keyof T]?: T[P] };
|
|
50
|
+
*
|
|
51
|
+
* // Conditional types (logic)
|
|
52
|
+
* type NonNullable<T> = T extends null | undefined ? never : T;
|
|
53
|
+
*
|
|
54
|
+
* // Type references with generics
|
|
55
|
+
* type ListOfUsers = Array<User>;
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see https://eslint.org/docs/latest/rules/no-restricted-syntax
|
|
59
|
+
* @see ./examples/invalid.js for more invalid examples
|
|
60
|
+
* @see ./examples/valid.js for more valid examples
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Rule configuration for type aliases to other types without generics
|
|
65
|
+
* Catches: type A = B (where B is not a generic type)
|
|
66
|
+
*/
|
|
67
|
+
const noTrivialTypeReferenceConfig = {
|
|
68
|
+
selector:
|
|
69
|
+
"TSTypeAliasDeclaration > TSTypeReference:not(:has(TSTypeParameterInstantiation))",
|
|
70
|
+
message:
|
|
71
|
+
"Trivial type aliases are not allowed. Use the original type directly instead of creating an alias that doesn't add meaning.",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Rule configuration for type aliases to primitive types
|
|
76
|
+
* Catches: type A = string, type B = number, etc.
|
|
77
|
+
*/
|
|
78
|
+
const noTrivialPrimitiveTypeConfig = {
|
|
79
|
+
selector:
|
|
80
|
+
"TSTypeAliasDeclaration:has(TSStringKeyword):not(:has(TSUnionType)):not(:has(TSIntersectionType)):not(:has(TSMappedType))",
|
|
81
|
+
message:
|
|
82
|
+
"Trivial type aliases to primitive types are not allowed. Use the primitive type directly instead.",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Rule configuration for type aliases to literal types
|
|
87
|
+
* Catches: type A = 'literal', type B = 42, etc.
|
|
88
|
+
*/
|
|
89
|
+
const noTrivialLiteralTypeConfig = {
|
|
90
|
+
selector: "TSTypeAliasDeclaration > TSLiteralType",
|
|
91
|
+
message:
|
|
92
|
+
"Trivial type aliases to literal types are not allowed. Use the literal type directly instead.",
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Combined configuration array for all trivial type alias rules
|
|
97
|
+
*/
|
|
98
|
+
const noTrivialTypeAliasesConfigs = [
|
|
99
|
+
noTrivialTypeReferenceConfig,
|
|
100
|
+
noTrivialPrimitiveTypeConfig,
|
|
101
|
+
noTrivialLiteralTypeConfig,
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
// Consolidated exports
|
|
105
|
+
export {
|
|
106
|
+
noTrivialTypeReferenceConfig,
|
|
107
|
+
noTrivialPrimitiveTypeConfig,
|
|
108
|
+
noTrivialLiteralTypeConfig,
|
|
109
|
+
noTrivialTypeAliasesConfigs,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default noTrivialTypeAliasesConfigs;
|