@reasonabletech/eslint-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +89 -0
- package/dist/src/base-configs.d.ts +53 -0
- package/dist/src/base-configs.js +105 -0
- package/dist/src/custom-rules/architecture-patterns.d.ts +193 -0
- package/dist/src/custom-rules/architecture-patterns.js +344 -0
- package/dist/src/custom-rules/code-quality.d.ts +201 -0
- package/dist/src/custom-rules/code-quality.js +388 -0
- package/dist/src/custom-rules/error-handling.d.ts +103 -0
- package/dist/src/custom-rules/error-handling.js +349 -0
- package/dist/src/custom-rules/index.d.ts +79 -0
- package/dist/src/custom-rules/index.js +119 -0
- package/dist/src/custom-rules/null-undefined-checks.d.ts +20 -0
- package/dist/src/custom-rules/null-undefined-checks.js +153 -0
- package/dist/src/custom-rules/platform-conventions.d.ts +115 -0
- package/dist/src/custom-rules/platform-conventions.js +249 -0
- package/dist/src/custom-rules/test-quality.d.ts +38 -0
- package/dist/src/custom-rules/test-quality.js +68 -0
- package/dist/src/custom-rules/type-safety.d.ts +71 -0
- package/dist/src/custom-rules/type-safety.js +121 -0
- package/dist/src/custom-rules/ui-library-imports.d.ts +21 -0
- package/dist/src/custom-rules/ui-library-imports.js +31 -0
- package/dist/src/custom-rules/utils.d.ts +95 -0
- package/dist/src/custom-rules/utils.js +146 -0
- package/dist/src/index.d.ts +73 -0
- package/dist/src/index.js +80 -0
- package/dist/src/next/config.d.ts +26 -0
- package/dist/src/next/config.js +76 -0
- package/dist/src/next/ignores.d.ts +37 -0
- package/dist/src/next/ignores.js +69 -0
- package/dist/src/next/plugins.d.ts +44 -0
- package/dist/src/next/plugins.js +104 -0
- package/dist/src/next/rules.d.ts +39 -0
- package/dist/src/next/rules.js +48 -0
- package/dist/src/next/settings.d.ts +41 -0
- package/dist/src/next/settings.js +45 -0
- package/dist/src/next.d.ts +33 -0
- package/dist/src/next.js +74 -0
- package/dist/src/plugin.d.ts +48 -0
- package/dist/src/plugin.js +30 -0
- package/dist/src/react/config.d.ts +30 -0
- package/dist/src/react/config.js +40 -0
- package/dist/src/react/plugins.d.ts +24 -0
- package/dist/src/react/plugins.js +46 -0
- package/dist/src/react/rules.d.ts +30 -0
- package/dist/src/react/rules.js +35 -0
- package/dist/src/react.d.ts +27 -0
- package/dist/src/react.js +35 -0
- package/dist/src/shared/parser-options.d.ts +3 -0
- package/dist/src/shared/parser-options.js +19 -0
- package/dist/src/shared/plugin-utils.d.ts +8 -0
- package/dist/src/shared/plugin-utils.js +23 -0
- package/dist/src/shared/react-rules.d.ts +97 -0
- package/dist/src/shared/react-rules.js +126 -0
- package/dist/src/shared/strict-rules.d.ts +27 -0
- package/dist/src/shared/strict-rules.js +54 -0
- package/dist/src/shared-ignores.d.ts +15 -0
- package/dist/src/shared-ignores.js +68 -0
- package/dist/src/shared-rules.d.ts +29 -0
- package/dist/src/shared-rules.js +163 -0
- package/package.json +122 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling rule definitions for ReasonableTech projects
|
|
3
|
+
*
|
|
4
|
+
* These rules enforce safe error handling patterns and prevent dangerous
|
|
5
|
+
* error message parsing. They are designed to be reusable across different
|
|
6
|
+
* projects with configurable documentation references.
|
|
7
|
+
*/
|
|
8
|
+
import { AST_NODE_TYPES, ESLintUtils, } from "@typescript-eslint/utils";
|
|
9
|
+
import { mergeRuleConfigurations } from "./utils.js";
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration for ReasonableTech error handling rules
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_OPTIONS = {
|
|
14
|
+
docBaseUrl: "docs/standards/error-handling.md",
|
|
15
|
+
errorTypePattern: ".*Error$",
|
|
16
|
+
resultTypeName: "Result",
|
|
17
|
+
requireErrorTypeJSDoc: true,
|
|
18
|
+
};
|
|
19
|
+
/** Set of string methods that are forbidden on `.message` properties */
|
|
20
|
+
const MESSAGE_STRING_METHODS = new Set([
|
|
21
|
+
"includes",
|
|
22
|
+
"startsWith",
|
|
23
|
+
"endsWith",
|
|
24
|
+
"match",
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Custom ESLint rule that prevents parsing error messages with string methods
|
|
28
|
+
*
|
|
29
|
+
* Detects the following patterns on any `.message` property:
|
|
30
|
+
* - `error.message.includes(...)` / `.startsWith(...)` / `.endsWith(...)` / `.match(...)`
|
|
31
|
+
* - `error.message === "..."` / `error.message == "..."`
|
|
32
|
+
* - `/.../\.test(error.message)`
|
|
33
|
+
*
|
|
34
|
+
* All of these are fragile because error messages are not part of a stable API
|
|
35
|
+
* and may change without notice. Use `error.code`, `error.status`, or
|
|
36
|
+
* `instanceof` checks instead.
|
|
37
|
+
*/
|
|
38
|
+
export const noErrorMessageParsingRule = ESLintUtils.RuleCreator(() => "docs/standards/error-handling.md")({
|
|
39
|
+
name: "no-error-message-parsing",
|
|
40
|
+
meta: {
|
|
41
|
+
type: "problem",
|
|
42
|
+
docs: {
|
|
43
|
+
description: "Prevents parsing error messages with string methods or direct comparisons",
|
|
44
|
+
},
|
|
45
|
+
messages: {
|
|
46
|
+
stringMethod: "Never parse error messages with .{{method}}(). Use error.code, error.status, or instanceof checks instead.",
|
|
47
|
+
directComparison: "Never compare error messages directly. Use error.code, error.status, or instanceof checks instead.",
|
|
48
|
+
regexTest: "Never use regex test on error messages. Use error.code, error.status, or instanceof checks instead.",
|
|
49
|
+
},
|
|
50
|
+
schema: [],
|
|
51
|
+
},
|
|
52
|
+
defaultOptions: [],
|
|
53
|
+
create(context) {
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a MemberExpression's object ends with `.message`
|
|
56
|
+
* (i.e. `<something>.message`).
|
|
57
|
+
* @param node The member expression node to check
|
|
58
|
+
* @returns Whether the node accesses a `.message` property
|
|
59
|
+
*/
|
|
60
|
+
function isMessageAccess(node) {
|
|
61
|
+
return (node.property.type === AST_NODE_TYPES.Identifier &&
|
|
62
|
+
node.property.name === "message");
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
// Detect: error.message.includes/startsWith/endsWith/match(...)
|
|
66
|
+
CallExpression(node) {
|
|
67
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const callee = node.callee;
|
|
71
|
+
const methodName = callee.property.type === AST_NODE_TYPES.Identifier
|
|
72
|
+
? callee.property.name
|
|
73
|
+
: null;
|
|
74
|
+
if (methodName === null) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Case 1: error.message.<method>(...)
|
|
78
|
+
if (MESSAGE_STRING_METHODS.has(methodName) &&
|
|
79
|
+
callee.object.type === AST_NODE_TYPES.MemberExpression &&
|
|
80
|
+
isMessageAccess(callee.object)) {
|
|
81
|
+
context.report({
|
|
82
|
+
node,
|
|
83
|
+
messageId: "stringMethod",
|
|
84
|
+
data: { method: methodName },
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Case 2: /regex/.test(error.message) — callee is regex.test,
|
|
89
|
+
// and the first argument is a `.message` member expression
|
|
90
|
+
if (methodName === "test" &&
|
|
91
|
+
node.arguments.length > 0 &&
|
|
92
|
+
node.arguments[0].type === AST_NODE_TYPES.MemberExpression &&
|
|
93
|
+
isMessageAccess(node.arguments[0])) {
|
|
94
|
+
context.report({ node, messageId: "regexTest" });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
// Detect: error.message === "..." / error.message == "..."
|
|
98
|
+
BinaryExpression(node) {
|
|
99
|
+
if (node.operator !== "===" && node.operator !== "==") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (node.left.type === AST_NODE_TYPES.MemberExpression &&
|
|
103
|
+
isMessageAccess(node.left)) {
|
|
104
|
+
context.report({ node, messageId: "directComparison" });
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Creates rules that prevent dangerous error message parsing patterns
|
|
112
|
+
*
|
|
113
|
+
* These rules block the use of string methods on error.message properties,
|
|
114
|
+
* enforcing the use of structured error detection instead.
|
|
115
|
+
* @param _options Configuration options for error handling rules (reserved for future use)
|
|
116
|
+
* @returns ESLint rules that prevent error message parsing
|
|
117
|
+
*/
|
|
118
|
+
export function createErrorMessageParsingRules(_options = {}) {
|
|
119
|
+
return {
|
|
120
|
+
"@reasonabletech/no-error-message-parsing": "error",
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Creates rules that enforce JSDoc documentation on error types
|
|
125
|
+
*
|
|
126
|
+
* Requires comprehensive documentation on all exported error type aliases
|
|
127
|
+
* to ensure error codes are properly documented and understood.
|
|
128
|
+
* @param options Configuration options for error handling rules
|
|
129
|
+
* @returns ESLint rules that enforce JSDoc documentation on error types
|
|
130
|
+
*/
|
|
131
|
+
export function createErrorTypeDocumentationRules(options = {}) {
|
|
132
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
133
|
+
if (!config.requireErrorTypeJSDoc) {
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
"jsdoc/require-jsdoc": [
|
|
138
|
+
"error",
|
|
139
|
+
{
|
|
140
|
+
require: {
|
|
141
|
+
FunctionDeclaration: false,
|
|
142
|
+
MethodDefinition: false,
|
|
143
|
+
ClassDeclaration: false,
|
|
144
|
+
ArrowFunctionExpression: false,
|
|
145
|
+
FunctionExpression: false,
|
|
146
|
+
},
|
|
147
|
+
contexts: [
|
|
148
|
+
// Enforce JSDoc on all exported type aliases that match the error pattern
|
|
149
|
+
`ExportNamedDeclaration > TSTypeAliasDeclaration[id.name=/${config.errorTypePattern}/]`,
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates rules that enforce consistent error type naming conventions
|
|
157
|
+
*
|
|
158
|
+
* Enforces PascalCase with "Error" suffix for error types and
|
|
159
|
+
* lowercase_with_underscores for error code literals.
|
|
160
|
+
* @param options Configuration options for error handling rules
|
|
161
|
+
* @returns ESLint rules that enforce consistent error type naming
|
|
162
|
+
*/
|
|
163
|
+
export function createErrorTypeNamingRules(options = {}) {
|
|
164
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
165
|
+
return {
|
|
166
|
+
"@typescript-eslint/naming-convention": [
|
|
167
|
+
"error",
|
|
168
|
+
{
|
|
169
|
+
// Enforce PascalCase with "Error" suffix for error types
|
|
170
|
+
selector: "typeAlias",
|
|
171
|
+
filter: {
|
|
172
|
+
regex: config.errorTypePattern,
|
|
173
|
+
match: true,
|
|
174
|
+
},
|
|
175
|
+
format: ["PascalCase"],
|
|
176
|
+
suffix: ["Error"],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Custom ESLint rule that prevents inline error union types in Result types
|
|
183
|
+
*
|
|
184
|
+
* Detects inline union types (containing literal members) used as type
|
|
185
|
+
* arguments in `Result<T, E>` and `Promise<Result<T, E>>` type references.
|
|
186
|
+
* These should be extracted to documented named types for maintainability.
|
|
187
|
+
*
|
|
188
|
+
* ❌ `Result<User, "not_found" | "forbidden">`
|
|
189
|
+
* ✅ `Result<User, GetUserError>` where `GetUserError` is a named type
|
|
190
|
+
*/
|
|
191
|
+
export const noInlineErrorUnionsRule = ESLintUtils.RuleCreator(() => "docs/standards/error-handling.md")({
|
|
192
|
+
name: "no-inline-error-unions",
|
|
193
|
+
meta: {
|
|
194
|
+
type: "problem",
|
|
195
|
+
docs: {
|
|
196
|
+
description: "Prevents inline error union types in Result type parameters",
|
|
197
|
+
},
|
|
198
|
+
messages: {
|
|
199
|
+
inlineUnion: "Never use inline error unions in {{typeName}} types. Extract to a documented named type.",
|
|
200
|
+
},
|
|
201
|
+
schema: [
|
|
202
|
+
{
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: {
|
|
205
|
+
resultTypeName: { type: "string" },
|
|
206
|
+
},
|
|
207
|
+
additionalProperties: false,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
defaultOptions: [{ resultTypeName: "Result" }],
|
|
212
|
+
create(context) {
|
|
213
|
+
const resultTypeName = context.options[0].resultTypeName;
|
|
214
|
+
/**
|
|
215
|
+
* Checks if a TSUnionType contains at least one TSLiteralType member.
|
|
216
|
+
* @param union The union type node to inspect
|
|
217
|
+
* @returns Whether the union contains a literal type member
|
|
218
|
+
*/
|
|
219
|
+
function hasLiteralMember(union) {
|
|
220
|
+
return union.types.some((t) => t.type === AST_NODE_TYPES.TSLiteralType);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Checks if a TSTypeReference refers to the configured Result type name.
|
|
224
|
+
* @param node The type reference node to check
|
|
225
|
+
* @returns Whether the node references the Result type
|
|
226
|
+
*/
|
|
227
|
+
function isResultReference(node) {
|
|
228
|
+
return (node.typeName.type === AST_NODE_TYPES.Identifier &&
|
|
229
|
+
node.typeName.name === resultTypeName);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Walks TSUnionType nodes that are descendants of a given type parameter
|
|
233
|
+
* list, returning any that contain literal members.
|
|
234
|
+
* @param params The type parameter instantiation to search
|
|
235
|
+
* @returns Array of union type nodes containing literal members
|
|
236
|
+
*/
|
|
237
|
+
function findInlineUnions(params) {
|
|
238
|
+
const results = [];
|
|
239
|
+
function walk(node) {
|
|
240
|
+
if (node.type === AST_NODE_TYPES.TSUnionType &&
|
|
241
|
+
hasLiteralMember(node)) {
|
|
242
|
+
results.push(node);
|
|
243
|
+
return; // Don't recurse into nested unions of the same node
|
|
244
|
+
}
|
|
245
|
+
for (const key of Object.keys(node)) {
|
|
246
|
+
if (key === "parent") {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const value = node[key];
|
|
250
|
+
if (Array.isArray(value)) {
|
|
251
|
+
for (const item of value) {
|
|
252
|
+
if (item !== null &&
|
|
253
|
+
typeof item === "object" &&
|
|
254
|
+
typeof item.type === "string") {
|
|
255
|
+
walk(item);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (value !== null &&
|
|
260
|
+
typeof value === "object" &&
|
|
261
|
+
typeof value.type === "string") {
|
|
262
|
+
walk(value);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (const param of params.params) {
|
|
267
|
+
walk(param);
|
|
268
|
+
}
|
|
269
|
+
return results;
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
TSTypeReference(node) {
|
|
273
|
+
if (!isResultReference(node)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (node.typeArguments === undefined) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
// Determine the display name: if the Result reference is nested inside
|
|
280
|
+
// a Promise<...>, display "Promise<Result<T, E>>".
|
|
281
|
+
let displayName = resultTypeName;
|
|
282
|
+
const parentRef = node.parent;
|
|
283
|
+
if (parentRef.type === AST_NODE_TYPES.TSTypeParameterInstantiation) {
|
|
284
|
+
const grandparent = parentRef.parent;
|
|
285
|
+
if (grandparent.type === AST_NODE_TYPES.TSTypeReference &&
|
|
286
|
+
grandparent.typeName.type === AST_NODE_TYPES.Identifier &&
|
|
287
|
+
grandparent.typeName.name === "Promise") {
|
|
288
|
+
displayName = `Promise<${resultTypeName}<T, E>>`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const inlineUnions = findInlineUnions(node.typeArguments);
|
|
292
|
+
for (const union of inlineUnions) {
|
|
293
|
+
context.report({
|
|
294
|
+
node: union,
|
|
295
|
+
messageId: "inlineUnion",
|
|
296
|
+
data: { typeName: displayName },
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
/**
|
|
304
|
+
* Creates rules that detect inline error unions in Result types
|
|
305
|
+
*
|
|
306
|
+
* Prevents the use of inline union types in Result<T, E> signatures,
|
|
307
|
+
* enforcing extraction to documented named types.
|
|
308
|
+
* @param options Configuration options for error handling rules
|
|
309
|
+
* @returns ESLint rules that detect inline error unions in Result types
|
|
310
|
+
*/
|
|
311
|
+
export function createInlineErrorUnionRules(options = {}) {
|
|
312
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
313
|
+
return {
|
|
314
|
+
"@reasonabletech/no-inline-error-unions": [
|
|
315
|
+
"error",
|
|
316
|
+
{
|
|
317
|
+
resultTypeName: config.resultTypeName,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Creates a complete set of error handling rules with all components
|
|
324
|
+
*
|
|
325
|
+
* This is the main function that combines all error handling rules
|
|
326
|
+
* into a single configuration object.
|
|
327
|
+
* @param options Configuration options for error handling rules
|
|
328
|
+
* @returns Complete set of error handling ESLint rules
|
|
329
|
+
*/
|
|
330
|
+
export function createErrorHandlingRules(options = {}) {
|
|
331
|
+
const messageParsingRules = createErrorMessageParsingRules(options);
|
|
332
|
+
const documentationRules = createErrorTypeDocumentationRules(options);
|
|
333
|
+
const namingRules = createErrorTypeNamingRules(options);
|
|
334
|
+
const inlineUnionRules = createInlineErrorUnionRules(options);
|
|
335
|
+
return mergeRuleConfigurations(messageParsingRules, documentationRules, namingRules, inlineUnionRules);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Preset for Platform-specific error handling rules
|
|
339
|
+
* @returns ESLint rules configured for platform projects
|
|
340
|
+
*/
|
|
341
|
+
export function createPlatformErrorHandlingRules() {
|
|
342
|
+
return createErrorHandlingRules({
|
|
343
|
+
docBaseUrl: "docs/standards/error-handling.md",
|
|
344
|
+
errorTypePattern: ".*Error$",
|
|
345
|
+
resultTypeName: "Result",
|
|
346
|
+
requireErrorTypeJSDoc: true,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
//# sourceMappingURL=error-handling.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom ESLint rules for ReasonableTech projects
|
|
3
|
+
*
|
|
4
|
+
* This module provides a collection of reusable ESLint rule configurations
|
|
5
|
+
* designed to enforce best practices for TypeScript development, with a focus
|
|
6
|
+
* on type safety, error handling, and maintainable code patterns.
|
|
7
|
+
*
|
|
8
|
+
* The rules are designed to be:
|
|
9
|
+
* - Configurable for different project contexts
|
|
10
|
+
* - Reusable across different organizations and projects
|
|
11
|
+
* - Focused on preventing common bugs and anti-patterns
|
|
12
|
+
* - Easy to extract into a standalone ESLint plugin
|
|
13
|
+
* Main entry point for custom ESLint rules
|
|
14
|
+
*/
|
|
15
|
+
export { noErrorMessageParsingRule, noInlineErrorUnionsRule, createErrorHandlingRules, createErrorMessageParsingRules, createErrorTypeDocumentationRules, createErrorTypeNamingRules, createInlineErrorUnionRules, createPlatformErrorHandlingRules, type ErrorHandlingRuleOptions, } from "./error-handling.js";
|
|
16
|
+
export { noNullUndefinedChecksRule, createNullUndefinedChecksRules, } from "./null-undefined-checks.js";
|
|
17
|
+
export { createArchitecturePatternRules, createDependencyBundlingRules, createDependencyInjectionRules, createServiceArchitectureRules, createPlatformArchitecturePatternRules, noConstructorInstantiationRule, type ArchitecturePatternRuleOptions, } from "./architecture-patterns.js";
|
|
18
|
+
export { noAsAnyRule, createNoAnyRules, createTypeSafetyRules, createPlatformTypeSafetyRules, type TypeSafetyRuleOptions, } from "./type-safety.js";
|
|
19
|
+
export { noLinterDisablingRule, noBarrelExportsRule, createBarrelExportRules, createAsyncPatternRules, createTerminologyRules, createMagicNumbersRules, createCodeQualityRules, createPlatformCodeQualityRules, type NoLinterDisablingOptions, type TerminologyOptions, type MagicNumbersOptions, } from "./code-quality.js";
|
|
20
|
+
export { createPlatformConventionRules, createResultHelperRules, createUIBarrelImportRules, createPlatformConventionPresetRules, type PlatformConventionRuleOptions, } from "./platform-conventions.js";
|
|
21
|
+
export { createUILibraryImportRules, type UILibraryImportRuleOptions, } from "./ui-library-imports.js";
|
|
22
|
+
export { createNoTypeofInExpectRules } from "./test-quality.js";
|
|
23
|
+
export { mergeRuleConfigurations, createConditionalRules, createExportedTypeSelector, createTypeReferenceSelector, createResultInlineUnionSelector, createPromiseResultInlineUnionSelector, createDocReference, isRuleEnabled, AST_SELECTORS, ERROR_MESSAGES, type BaseRuleOptions, } from "./utils.js";
|
|
24
|
+
import type { Linter } from "eslint";
|
|
25
|
+
import { type ErrorHandlingRuleOptions } from "./error-handling.js";
|
|
26
|
+
import { type ArchitecturePatternRuleOptions } from "./architecture-patterns.js";
|
|
27
|
+
import { type TypeSafetyRuleOptions } from "./type-safety.js";
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for all ReasonableTech custom rules
|
|
30
|
+
*/
|
|
31
|
+
export interface ReasonableTechRuleOptions {
|
|
32
|
+
/** Error handling rule options */
|
|
33
|
+
errorHandling?: Partial<ErrorHandlingRuleOptions>;
|
|
34
|
+
/** Architecture pattern rule options */
|
|
35
|
+
architecturePatterns?: Partial<ArchitecturePatternRuleOptions>;
|
|
36
|
+
/** Type safety rule options */
|
|
37
|
+
typeSafety?: Partial<TypeSafetyRuleOptions>;
|
|
38
|
+
/** Base URL for all documentation references */
|
|
39
|
+
docBaseUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a complete set of ReasonableTech custom rules
|
|
43
|
+
*
|
|
44
|
+
* This function combines all available rule sets into a single configuration,
|
|
45
|
+
* making it easy to apply consistent standards across projects.
|
|
46
|
+
* @param options Configuration options for customizing rule behavior
|
|
47
|
+
* @returns Complete ESLint rule configuration
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createReasonableTechRules } from './custom-rules';
|
|
51
|
+
*
|
|
52
|
+
* const rules = createReasonableTechRules({
|
|
53
|
+
* docBaseUrl: 'docs/standards/',
|
|
54
|
+
* errorHandling: {
|
|
55
|
+
* resultTypeName: 'Result',
|
|
56
|
+
* requireErrorTypeJSDoc: true,
|
|
57
|
+
* },
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createReasonableTechRules(options?: ReasonableTechRuleOptions): Linter.RulesRecord;
|
|
62
|
+
/**
|
|
63
|
+
* Preset configuration for platform projects
|
|
64
|
+
*
|
|
65
|
+
* This preset provides all the custom rules configured specifically
|
|
66
|
+
* for platform project conventions and documentation structure.
|
|
67
|
+
* @returns ESLint rule configuration for platform projects
|
|
68
|
+
*/
|
|
69
|
+
export declare function createPlatformRulePreset(): Linter.RulesRecord;
|
|
70
|
+
/**
|
|
71
|
+
* Preset configuration for generic ReasonableTech projects
|
|
72
|
+
*
|
|
73
|
+
* This preset provides sensible defaults that work well for most
|
|
74
|
+
* TypeScript projects following ReasonableTech conventions.
|
|
75
|
+
* @param docBaseUrl Base URL for documentation references
|
|
76
|
+
* @returns ESLint rule configuration for generic projects
|
|
77
|
+
*/
|
|
78
|
+
export declare function createGenericRulePreset(docBaseUrl?: string): Linter.RulesRecord;
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom ESLint rules for ReasonableTech projects
|
|
3
|
+
*
|
|
4
|
+
* This module provides a collection of reusable ESLint rule configurations
|
|
5
|
+
* designed to enforce best practices for TypeScript development, with a focus
|
|
6
|
+
* on type safety, error handling, and maintainable code patterns.
|
|
7
|
+
*
|
|
8
|
+
* The rules are designed to be:
|
|
9
|
+
* - Configurable for different project contexts
|
|
10
|
+
* - Reusable across different organizations and projects
|
|
11
|
+
* - Focused on preventing common bugs and anti-patterns
|
|
12
|
+
* - Easy to extract into a standalone ESLint plugin
|
|
13
|
+
* Main entry point for custom ESLint rules
|
|
14
|
+
*/
|
|
15
|
+
// Re-export all error handling functionality
|
|
16
|
+
export { noErrorMessageParsingRule, noInlineErrorUnionsRule, createErrorHandlingRules, createErrorMessageParsingRules, createErrorTypeDocumentationRules, createErrorTypeNamingRules, createInlineErrorUnionRules, createPlatformErrorHandlingRules, } from "./error-handling.js";
|
|
17
|
+
// Re-export null/undefined checks rule
|
|
18
|
+
export { noNullUndefinedChecksRule, createNullUndefinedChecksRules, } from "./null-undefined-checks.js";
|
|
19
|
+
// Re-export architecture pattern rules
|
|
20
|
+
export { createArchitecturePatternRules, createDependencyBundlingRules, createDependencyInjectionRules, createServiceArchitectureRules, createPlatformArchitecturePatternRules, noConstructorInstantiationRule, } from "./architecture-patterns.js";
|
|
21
|
+
// Re-export type safety rules
|
|
22
|
+
export { noAsAnyRule, createNoAnyRules, createTypeSafetyRules, createPlatformTypeSafetyRules, } from "./type-safety.js";
|
|
23
|
+
// Re-export code quality rules
|
|
24
|
+
export { noLinterDisablingRule, noBarrelExportsRule, createBarrelExportRules, createAsyncPatternRules, createTerminologyRules, createMagicNumbersRules, createCodeQualityRules, createPlatformCodeQualityRules, } from "./code-quality.js";
|
|
25
|
+
// Re-export platform convention rules
|
|
26
|
+
export { createPlatformConventionRules, createResultHelperRules, createUIBarrelImportRules, createPlatformConventionPresetRules, } from "./platform-conventions.js";
|
|
27
|
+
// Re-export UI import boundary rules
|
|
28
|
+
export { createUILibraryImportRules, } from "./ui-library-imports.js";
|
|
29
|
+
// Re-export test quality rules
|
|
30
|
+
export { createNoTypeofInExpectRules } from "./test-quality.js";
|
|
31
|
+
// Re-export utilities
|
|
32
|
+
export { mergeRuleConfigurations, createConditionalRules, createExportedTypeSelector, createTypeReferenceSelector, createResultInlineUnionSelector, createPromiseResultInlineUnionSelector, createDocReference, isRuleEnabled, AST_SELECTORS, ERROR_MESSAGES, } from "./utils.js";
|
|
33
|
+
import { createErrorHandlingRules, } from "./error-handling.js";
|
|
34
|
+
import { createArchitecturePatternRules, } from "./architecture-patterns.js";
|
|
35
|
+
import { createTypeSafetyRules, } from "./type-safety.js";
|
|
36
|
+
import { createCodeQualityRules } from "./code-quality.js";
|
|
37
|
+
import { mergeRuleConfigurations } from "./utils.js";
|
|
38
|
+
/**
|
|
39
|
+
* Creates a complete set of ReasonableTech custom rules
|
|
40
|
+
*
|
|
41
|
+
* This function combines all available rule sets into a single configuration,
|
|
42
|
+
* making it easy to apply consistent standards across projects.
|
|
43
|
+
* @param options Configuration options for customizing rule behavior
|
|
44
|
+
* @returns Complete ESLint rule configuration
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { createReasonableTechRules } from './custom-rules';
|
|
48
|
+
*
|
|
49
|
+
* const rules = createReasonableTechRules({
|
|
50
|
+
* docBaseUrl: 'docs/standards/',
|
|
51
|
+
* errorHandling: {
|
|
52
|
+
* resultTypeName: 'Result',
|
|
53
|
+
* requireErrorTypeJSDoc: true,
|
|
54
|
+
* },
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createReasonableTechRules(options = {}) {
|
|
59
|
+
const errorHandlingOptions = {
|
|
60
|
+
docBaseUrl: options.docBaseUrl ?? "docs/standards/error-handling.md",
|
|
61
|
+
...options.errorHandling,
|
|
62
|
+
};
|
|
63
|
+
const architecturePatternOptions = {
|
|
64
|
+
docBaseUrl: options.docBaseUrl ?? "docs/standards/architecture-principles.md",
|
|
65
|
+
...options.architecturePatterns,
|
|
66
|
+
};
|
|
67
|
+
const typeSafetyOptions = {
|
|
68
|
+
docBaseUrl: options.docBaseUrl ?? "docs/standards/typescript-standards.md",
|
|
69
|
+
...options.typeSafety,
|
|
70
|
+
};
|
|
71
|
+
const errorHandlingRules = createErrorHandlingRules(errorHandlingOptions);
|
|
72
|
+
const architecturePatternRules = createArchitecturePatternRules(architecturePatternOptions);
|
|
73
|
+
const typeSafetyRules = createTypeSafetyRules(typeSafetyOptions);
|
|
74
|
+
const codeQualityRules = createCodeQualityRules();
|
|
75
|
+
return mergeRuleConfigurations(errorHandlingRules, architecturePatternRules, typeSafetyRules, codeQualityRules);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Preset configuration for platform projects
|
|
79
|
+
*
|
|
80
|
+
* This preset provides all the custom rules configured specifically
|
|
81
|
+
* for platform project conventions and documentation structure.
|
|
82
|
+
* @returns ESLint rule configuration for platform projects
|
|
83
|
+
*/
|
|
84
|
+
export function createPlatformRulePreset() {
|
|
85
|
+
return createReasonableTechRules({
|
|
86
|
+
docBaseUrl: "docs/standards/error-handling.md",
|
|
87
|
+
errorHandling: {
|
|
88
|
+
errorTypePattern: ".*Error$",
|
|
89
|
+
resultTypeName: "Result",
|
|
90
|
+
requireErrorTypeJSDoc: true,
|
|
91
|
+
},
|
|
92
|
+
architecturePatterns: {
|
|
93
|
+
enforceIndividualDependencies: true,
|
|
94
|
+
},
|
|
95
|
+
typeSafety: {
|
|
96
|
+
docBaseUrl: "docs/standards/typescript-standards.md",
|
|
97
|
+
allowInTests: false,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Preset configuration for generic ReasonableTech projects
|
|
103
|
+
*
|
|
104
|
+
* This preset provides sensible defaults that work well for most
|
|
105
|
+
* TypeScript projects following ReasonableTech conventions.
|
|
106
|
+
* @param docBaseUrl Base URL for documentation references
|
|
107
|
+
* @returns ESLint rule configuration for generic projects
|
|
108
|
+
*/
|
|
109
|
+
export function createGenericRulePreset(docBaseUrl = "docs/") {
|
|
110
|
+
return createReasonableTechRules({
|
|
111
|
+
docBaseUrl: `${docBaseUrl}error-handling.md`,
|
|
112
|
+
errorHandling: {
|
|
113
|
+
errorTypePattern: ".*Error$",
|
|
114
|
+
resultTypeName: "Result",
|
|
115
|
+
requireErrorTypeJSDoc: true,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom ESLint rule: no-null-undefined-checks
|
|
3
|
+
*
|
|
4
|
+
* Flags code that checks for both null and undefined on the same value,
|
|
5
|
+
* which indicates a type mismatch. null and undefined are different types
|
|
6
|
+
* in TypeScript, and you should only check for what's in your type union.
|
|
7
|
+
*/
|
|
8
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
9
|
+
/**
|
|
10
|
+
* Creates the no-null-undefined-checks rule
|
|
11
|
+
*/
|
|
12
|
+
export declare const noNullUndefinedChecksRule: ESLintUtils.RuleModule<"checksBoth", [], unknown, ESLintUtils.RuleListener> & {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates the rule configuration for the null/undefined checks rule
|
|
17
|
+
* @returns ESLint rule configuration
|
|
18
|
+
*/
|
|
19
|
+
export declare function createNullUndefinedChecksRules(): Record<string, string>;
|
|
20
|
+
//# sourceMappingURL=null-undefined-checks.d.ts.map
|