@blumintinc/eslint-plugin-blumint 1.4.0 → 1.5.1
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/lib/index.js +19 -1
- package/lib/rules/array-methods-this-context.js +2 -2
- package/lib/rules/enforce-callback-memo.js +3 -3
- package/lib/rules/enforce-dynamic-firebase-imports.js +2 -2
- package/lib/rules/enforce-exported-function-types.js +115 -85
- package/lib/rules/enforce-firestore-doc-ref-generic.js +2 -2
- package/lib/rules/enforce-firestore-path-utils.js +2 -2
- package/lib/rules/enforce-firestore-set-merge.js +35 -4
- package/lib/rules/enforce-identifiable-firestore-type.js +2 -2
- package/lib/rules/enforce-memoize-async.js +6 -4
- package/lib/rules/enforce-mock-firestore.js +3 -3
- package/lib/rules/enforce-realtimedb-path-utils.js +1 -1
- package/lib/rules/enforce-safe-stringify.js +2 -2
- package/lib/rules/enforce-serializable-params.js +3 -3
- package/lib/rules/enforce-verb-noun-naming.js +34 -12
- package/lib/rules/no-async-array-filter.js +2 -2
- package/lib/rules/no-async-foreach.js +1 -1
- package/lib/rules/no-class-instance-destructuring.d.ts +1 -0
- package/lib/rules/no-class-instance-destructuring.js +95 -0
- package/lib/rules/no-compositing-layer-props.js +1 -1
- package/lib/rules/no-conditional-literals-in-jsx.js +1 -1
- package/lib/rules/no-entire-object-hook-deps.js +1 -1
- package/lib/rules/no-explicit-return-type.d.ts +1 -0
- package/lib/rules/no-explicit-return-type.js +5 -2
- package/lib/rules/no-filter-without-return.js +1 -1
- package/lib/rules/no-firestore-object-arrays.d.ts +1 -0
- package/lib/rules/no-firestore-object-arrays.js +86 -0
- package/lib/rules/no-jsx-in-hooks.d.ts +1 -0
- package/lib/rules/no-jsx-in-hooks.js +200 -0
- package/lib/rules/no-memoize-on-static.d.ts +1 -0
- package/lib/rules/no-memoize-on-static.js +54 -0
- package/lib/rules/no-misused-switch-case.js +2 -2
- package/lib/rules/no-redundant-param-types.d.ts +2 -0
- package/lib/rules/no-redundant-param-types.js +129 -0
- package/lib/rules/no-unsafe-firestore-spread.d.ts +3 -0
- package/lib/rules/no-unsafe-firestore-spread.js +125 -0
- package/lib/rules/no-unused-props.js +1 -1
- package/lib/rules/no-useless-fragment.js +1 -1
- package/lib/rules/prefer-destructuring-no-class.d.ts +8 -0
- package/lib/rules/prefer-destructuring-no-class.js +200 -0
- package/lib/rules/require-hooks-default-params.d.ts +1 -0
- package/lib/rules/require-hooks-default-params.js +195 -0
- package/lib/rules/require-usememo-object-literals.js +1 -1
- package/lib/rules/semantic-function-prefixes.js +43 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -50,10 +50,16 @@ const enforce_serializable_params_1 = __importDefault(require("./rules/enforce-s
|
|
|
50
50
|
const enforce_realtimedb_path_utils_1 = require("./rules/enforce-realtimedb-path-utils");
|
|
51
51
|
const enforce_memoize_async_1 = require("./rules/enforce-memoize-async");
|
|
52
52
|
const enforce_exported_function_types_1 = require("./rules/enforce-exported-function-types");
|
|
53
|
+
const no_redundant_param_types_1 = require("./rules/no-redundant-param-types");
|
|
54
|
+
const no_class_instance_destructuring_1 = require("./rules/no-class-instance-destructuring");
|
|
55
|
+
const no_firestore_object_arrays_1 = require("./rules/no-firestore-object-arrays");
|
|
56
|
+
const no_memoize_on_static_1 = require("./rules/no-memoize-on-static");
|
|
57
|
+
const no_unsafe_firestore_spread_1 = require("./rules/no-unsafe-firestore-spread");
|
|
58
|
+
const no_jsx_in_hooks_1 = require("./rules/no-jsx-in-hooks");
|
|
53
59
|
module.exports = {
|
|
54
60
|
meta: {
|
|
55
61
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
56
|
-
version: '1.
|
|
62
|
+
version: '1.5.1',
|
|
57
63
|
},
|
|
58
64
|
parseOptions: {
|
|
59
65
|
ecmaVersion: 2020,
|
|
@@ -109,6 +115,12 @@ module.exports = {
|
|
|
109
115
|
'@blumintinc/blumint/enforce-realtimedb-path-utils': 'error',
|
|
110
116
|
'@blumintinc/blumint/enforce-memoize-async': 'error',
|
|
111
117
|
'@blumintinc/blumint/enforce-exported-function-types': 'error',
|
|
118
|
+
'@blumintinc/blumint/no-redundant-param-types': 'error',
|
|
119
|
+
'@blumintinc/blumint/no-class-instance-destructuring': 'error',
|
|
120
|
+
'@blumintinc/blumint/no-firestore-object-arrays': 'warn',
|
|
121
|
+
'@blumintinc/blumint/no-memoize-on-static': 'error',
|
|
122
|
+
'@blumintinc/blumint/no-unsafe-firestore-spread': 'error',
|
|
123
|
+
'@blumintinc/blumint/no-jsx-in-hooks': 'error',
|
|
112
124
|
},
|
|
113
125
|
},
|
|
114
126
|
},
|
|
@@ -160,6 +172,12 @@ module.exports = {
|
|
|
160
172
|
'enforce-realtimedb-path-utils': enforce_realtimedb_path_utils_1.enforceRealtimedbPathUtils,
|
|
161
173
|
'enforce-memoize-async': enforce_memoize_async_1.enforceMemoizeAsync,
|
|
162
174
|
'enforce-exported-function-types': enforce_exported_function_types_1.enforceExportedFunctionTypes,
|
|
175
|
+
'no-redundant-param-types': no_redundant_param_types_1.noRedundantParamTypes,
|
|
176
|
+
'no-class-instance-destructuring': no_class_instance_destructuring_1.noClassInstanceDestructuring,
|
|
177
|
+
'no-firestore-object-arrays': no_firestore_object_arrays_1.noFirestoreObjectArrays,
|
|
178
|
+
'no-memoize-on-static': no_memoize_on_static_1.noMemoizeOnStatic,
|
|
179
|
+
'no-unsafe-firestore-spread': no_unsafe_firestore_spread_1.noUnsafeFirestoreSpread,
|
|
180
|
+
'no-jsx-in-hooks': no_jsx_in_hooks_1.noJsxInHooks,
|
|
163
181
|
},
|
|
164
182
|
};
|
|
165
183
|
//# sourceMappingURL=index.js.map
|
|
@@ -55,8 +55,8 @@ exports.arrayMethodsThisContext = (0, createRule_1.createRule)({
|
|
|
55
55
|
},
|
|
56
56
|
schema: [],
|
|
57
57
|
messages: {
|
|
58
|
-
unexpected: 'Use an arrow function to preserve "this" context.',
|
|
59
|
-
preferArrow: 'Use an arrow function instead of binding this.',
|
|
58
|
+
unexpected: 'Use an arrow function to preserve "this" context in array methods. Instead of `array.map(this.method)`, use `array.map((x) => this.method(x))`.',
|
|
59
|
+
preferArrow: 'Use an arrow function instead of binding "this". Instead of `array.map(function(x) {}.bind(this))`, use `array.map((x) => {...})`.',
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
defaultOptions: [],
|
|
@@ -7,12 +7,12 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
7
7
|
meta: {
|
|
8
8
|
type: 'suggestion',
|
|
9
9
|
docs: {
|
|
10
|
-
description: 'Enforce useCallback
|
|
10
|
+
description: 'Enforce useCallback for inline functions and useMemo for objects/arrays containing functions in JSX props to prevent unnecessary re-renders. This improves React component performance by ensuring stable function references across renders and memoizing complex objects.',
|
|
11
11
|
recommended: 'error',
|
|
12
12
|
},
|
|
13
13
|
messages: {
|
|
14
|
-
enforceCallback: 'Inline functions in JSX props should be wrapped with useCallback',
|
|
15
|
-
enforceMemo: 'Objects/arrays containing functions in JSX props should be wrapped with useMemo',
|
|
14
|
+
enforceCallback: 'Inline functions in JSX props should be wrapped with useCallback to prevent unnecessary re-renders. Instead of `<Button onClick={() => handleClick(id)} />`, use `<Button onClick={useCallback(() => handleClick(id), [id])} />`.',
|
|
15
|
+
enforceMemo: 'Objects/arrays containing functions in JSX props should be wrapped with useMemo to prevent unnecessary re-renders. Instead of `<Component config={{ onSubmit: () => {...} }} />`, use `<Component config={useMemo(() => ({ onSubmit: () => {...} }), [])} />`.',
|
|
16
16
|
},
|
|
17
17
|
schema: [],
|
|
18
18
|
},
|
|
@@ -7,12 +7,12 @@ exports.enforceFirebaseImports = (0, createRule_1.createRule)({
|
|
|
7
7
|
meta: {
|
|
8
8
|
type: 'problem',
|
|
9
9
|
docs: {
|
|
10
|
-
description: 'Enforce dynamic importing for modules within the firebaseCloud directory',
|
|
10
|
+
description: 'Enforce dynamic importing for modules within the firebaseCloud directory to optimize initial bundle size. This ensures Firebase-related code is only loaded when needed, improving application startup time and reducing the main bundle size.',
|
|
11
11
|
recommended: 'error',
|
|
12
12
|
},
|
|
13
13
|
schema: [],
|
|
14
14
|
messages: {
|
|
15
|
-
noDynamicImport: 'Static imports from firebaseCloud directory are not allowed.
|
|
15
|
+
noDynamicImport: 'Static imports from firebaseCloud directory are not allowed to reduce initial bundle size. Instead of `import { func } from "./firebaseCloud/module"`, use dynamic import: `const { func } = await import("./firebaseCloud/module")`.',
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
defaultOptions: [],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.enforceExportedFunctionTypes = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
5
|
const utils_1 = require("@typescript-eslint/utils");
|
|
5
6
|
const createRule_1 = require("../utils/createRule");
|
|
6
7
|
exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
@@ -13,9 +14,9 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
13
14
|
},
|
|
14
15
|
schema: [],
|
|
15
16
|
messages: {
|
|
16
|
-
missingExportedType: 'Type {{typeName}} should be exported since it is used in an exported function',
|
|
17
|
-
missingExportedReturnType: 'Return type {{typeName}} should be exported since it is used in an exported function',
|
|
18
|
-
missingExportedPropsType: 'Props type {{typeName}} should be exported since it is used in an exported React component',
|
|
17
|
+
missingExportedType: 'Type {{typeName}} should be exported since it is used in an exported function. Add `export` before the type definition: `export type {{typeName}} = ...`',
|
|
18
|
+
missingExportedReturnType: 'Return type {{typeName}} should be exported since it is used in an exported function. Add `export` before the type definition: `export type {{typeName}} = ...`',
|
|
19
|
+
missingExportedPropsType: 'Props type {{typeName}} should be exported since it is used in an exported React component. Add `export` before the type definition: `export type {{typeName}} = ...`',
|
|
19
20
|
},
|
|
20
21
|
},
|
|
21
22
|
defaultOptions: [],
|
|
@@ -33,30 +34,122 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
33
34
|
return false;
|
|
34
35
|
if (parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration ||
|
|
35
36
|
parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
|
|
36
|
-
parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
37
|
+
(parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
38
|
+
isExported(parent.parent))) {
|
|
37
39
|
return true;
|
|
38
40
|
}
|
|
39
41
|
return false;
|
|
40
42
|
}
|
|
41
|
-
function
|
|
43
|
+
function findTypeParameters(node) {
|
|
44
|
+
// Find all type parameters in scope
|
|
45
|
+
const typeParams = new Set();
|
|
46
|
+
let current = node;
|
|
47
|
+
while (current) {
|
|
48
|
+
// Handle type parameters in function declarations
|
|
49
|
+
if (current.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
50
|
+
current.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
|
|
51
|
+
if ('typeParameters' in current && current.typeParameters) {
|
|
52
|
+
current.typeParameters.params.forEach((param) => {
|
|
53
|
+
if (param.type === utils_1.AST_NODE_TYPES.TSTypeParameter) {
|
|
54
|
+
typeParams.add(param.name.name);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
current = current.parent;
|
|
60
|
+
}
|
|
61
|
+
return typeParams;
|
|
62
|
+
}
|
|
63
|
+
function getTypeNames(node, typeParams) {
|
|
42
64
|
if (!node)
|
|
43
|
-
return
|
|
65
|
+
return [];
|
|
66
|
+
// Initialize type parameters if not provided
|
|
67
|
+
if (!typeParams) {
|
|
68
|
+
typeParams = findTypeParameters(node);
|
|
69
|
+
}
|
|
44
70
|
switch (node.type) {
|
|
45
71
|
case utils_1.AST_NODE_TYPES.TSTypeReference:
|
|
46
72
|
if (node.typeName.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
47
|
-
|
|
73
|
+
// Skip checking generic type parameters (e.g., T in <T extends DocumentData>)
|
|
74
|
+
if (typeParams.has(node.typeName.name))
|
|
75
|
+
return [];
|
|
76
|
+
const names = [node.typeName.name];
|
|
77
|
+
// For generic types like AuthenticatedRequest<Params>, check type arguments
|
|
78
|
+
if ('typeParameters' in node && node.typeParameters) {
|
|
79
|
+
node.typeParameters.params.forEach((param) => {
|
|
80
|
+
names.push(...getTypeNames(param, typeParams));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return names;
|
|
48
84
|
}
|
|
49
85
|
break;
|
|
50
86
|
case utils_1.AST_NODE_TYPES.TSTypeLiteral:
|
|
51
|
-
return 'AnonymousType';
|
|
87
|
+
return ['AnonymousType'];
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
function isBuiltInType(typeName) {
|
|
92
|
+
const builtInTypes = new Set([
|
|
93
|
+
'string',
|
|
94
|
+
'number',
|
|
95
|
+
'boolean',
|
|
96
|
+
'null',
|
|
97
|
+
'undefined',
|
|
98
|
+
'void',
|
|
99
|
+
'any',
|
|
100
|
+
'never',
|
|
101
|
+
'unknown',
|
|
102
|
+
'object',
|
|
103
|
+
'Date',
|
|
104
|
+
'RegExp',
|
|
105
|
+
'Error',
|
|
106
|
+
'Promise',
|
|
107
|
+
'Array',
|
|
108
|
+
'Function',
|
|
109
|
+
'Symbol',
|
|
110
|
+
'BigInt',
|
|
111
|
+
'Map',
|
|
112
|
+
'Set',
|
|
113
|
+
'WeakMap',
|
|
114
|
+
'WeakSet',
|
|
115
|
+
]);
|
|
116
|
+
return builtInTypes.has(typeName);
|
|
117
|
+
}
|
|
118
|
+
function checkAndReportType(node, parentNode, messageId) {
|
|
119
|
+
const typeNames = getTypeNames(node);
|
|
120
|
+
for (const typeName of typeNames) {
|
|
121
|
+
if (typeName !== 'AnonymousType' &&
|
|
122
|
+
!isBuiltInType(typeName) &&
|
|
123
|
+
!isTypeExported(typeName)) {
|
|
124
|
+
// Check if we've already reported this type
|
|
125
|
+
const key = `${typeName}-${parentNode.loc?.start.line}-${parentNode.loc?.start.column}`;
|
|
126
|
+
if (!reportedTypes.has(key)) {
|
|
127
|
+
reportedTypes.add(key);
|
|
128
|
+
context.report({
|
|
129
|
+
node: parentNode,
|
|
130
|
+
messageId,
|
|
131
|
+
data: { typeName },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
52
135
|
}
|
|
53
|
-
return undefined;
|
|
54
136
|
}
|
|
55
137
|
function isTypeExported(typeName) {
|
|
56
138
|
const sourceCode = context.getSourceCode();
|
|
57
139
|
const program = sourceCode.ast;
|
|
140
|
+
// Check for imported types
|
|
141
|
+
const importedTypes = program.body.filter((node) => {
|
|
142
|
+
if (node.type === utils_1.AST_NODE_TYPES.ImportDeclaration) {
|
|
143
|
+
return node.specifiers.some((specifier) => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
|
|
144
|
+
specifier.local.name === typeName);
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
});
|
|
148
|
+
if (importedTypes.length > 0) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
58
151
|
// Check for exported type declarations
|
|
59
|
-
const exportedTypes = program.body.filter(node => {
|
|
152
|
+
const exportedTypes = program.body.filter((node) => {
|
|
60
153
|
if (node.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
61
154
|
if (node.declaration?.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
62
155
|
return node.declaration.id.name === typeName;
|
|
@@ -72,7 +165,7 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
72
165
|
}
|
|
73
166
|
// Check for type aliases in the current scope
|
|
74
167
|
const scope = context.getScope();
|
|
75
|
-
const variable = scope.variables.find(v => v.name === typeName);
|
|
168
|
+
const variable = scope.variables.find((v) => v.name === typeName);
|
|
76
169
|
if (!variable)
|
|
77
170
|
return false;
|
|
78
171
|
const def = variable.defs[0];
|
|
@@ -112,36 +205,13 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
112
205
|
return;
|
|
113
206
|
// Check return type
|
|
114
207
|
if (node.returnType?.typeAnnotation) {
|
|
115
|
-
|
|
116
|
-
if (typeName && !isTypeExported(typeName)) {
|
|
117
|
-
// Check if we've already reported this type
|
|
118
|
-
const key = `${typeName}-${node.loc?.start.line}-${node.loc?.start.column}`;
|
|
119
|
-
if (!reportedTypes.has(key)) {
|
|
120
|
-
reportedTypes.add(key);
|
|
121
|
-
context.report({
|
|
122
|
-
node: node.returnType,
|
|
123
|
-
messageId: 'missingExportedReturnType',
|
|
124
|
-
data: { typeName },
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
208
|
+
checkAndReportType(node.returnType.typeAnnotation, node.returnType, 'missingExportedReturnType');
|
|
128
209
|
}
|
|
129
210
|
// Check parameter types
|
|
130
|
-
node.params.forEach(param => {
|
|
131
|
-
if (param.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// Check if we've already reported this type
|
|
135
|
-
const key = `${typeName}-${param.loc?.start.line}-${param.loc?.start.column}`;
|
|
136
|
-
if (!reportedTypes.has(key)) {
|
|
137
|
-
reportedTypes.add(key);
|
|
138
|
-
context.report({
|
|
139
|
-
node: param.typeAnnotation,
|
|
140
|
-
messageId: 'missingExportedType',
|
|
141
|
-
data: { typeName },
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
211
|
+
node.params.forEach((param) => {
|
|
212
|
+
if (param.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
213
|
+
param.typeAnnotation) {
|
|
214
|
+
checkAndReportType(param.typeAnnotation.typeAnnotation, param.typeAnnotation, 'missingExportedType');
|
|
145
215
|
}
|
|
146
216
|
});
|
|
147
217
|
},
|
|
@@ -155,36 +225,13 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
155
225
|
return;
|
|
156
226
|
// Check return type
|
|
157
227
|
if (node.returnType?.typeAnnotation) {
|
|
158
|
-
|
|
159
|
-
if (typeName && !isTypeExported(typeName)) {
|
|
160
|
-
// Check if we've already reported this type
|
|
161
|
-
const key = `${typeName}-${node.loc?.start.line}-${node.loc?.start.column}`;
|
|
162
|
-
if (!reportedTypes.has(key)) {
|
|
163
|
-
reportedTypes.add(key);
|
|
164
|
-
context.report({
|
|
165
|
-
node: node.returnType,
|
|
166
|
-
messageId: 'missingExportedReturnType',
|
|
167
|
-
data: { typeName },
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
228
|
+
checkAndReportType(node.returnType.typeAnnotation, node.returnType, 'missingExportedReturnType');
|
|
171
229
|
}
|
|
172
230
|
// Check parameter types
|
|
173
|
-
node.params.forEach(param => {
|
|
174
|
-
if (param.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// Check if we've already reported this type
|
|
178
|
-
const key = `${typeName}-${param.loc?.start.line}-${param.loc?.start.column}`;
|
|
179
|
-
if (!reportedTypes.has(key)) {
|
|
180
|
-
reportedTypes.add(key);
|
|
181
|
-
context.report({
|
|
182
|
-
node: param.typeAnnotation,
|
|
183
|
-
messageId: 'missingExportedType',
|
|
184
|
-
data: { typeName },
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
231
|
+
node.params.forEach((param) => {
|
|
232
|
+
if (param.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
233
|
+
param.typeAnnotation) {
|
|
234
|
+
checkAndReportType(param.typeAnnotation.typeAnnotation, param.typeAnnotation, 'missingExportedType');
|
|
188
235
|
}
|
|
189
236
|
});
|
|
190
237
|
},
|
|
@@ -194,20 +241,7 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
194
241
|
return;
|
|
195
242
|
// Check props parameter
|
|
196
243
|
if (node.typeAnnotation) {
|
|
197
|
-
|
|
198
|
-
if (typeName && !isTypeExported(typeName)) {
|
|
199
|
-
// Check if we've already reported this type
|
|
200
|
-
const key = `${typeName}-${node.loc?.start.line}-${node.loc?.start.column}`;
|
|
201
|
-
if (!reportedTypes.has(key)) {
|
|
202
|
-
reportedTypes.add(key);
|
|
203
|
-
context.report({
|
|
204
|
-
node: node.typeAnnotation,
|
|
205
|
-
messageId: 'missingExportedType',
|
|
206
|
-
data: { typeName },
|
|
207
|
-
});
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
244
|
+
checkAndReportType(node.typeAnnotation.typeAnnotation, node.typeAnnotation, 'missingExportedPropsType');
|
|
211
245
|
}
|
|
212
246
|
},
|
|
213
247
|
// Skip type checking for React components since we handle them separately
|
|
@@ -239,10 +273,6 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
239
273
|
'VariableDeclarator[id.name=/^[A-Z]/] > ArrowFunctionExpression > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > Identifier'() { },
|
|
240
274
|
'FunctionDeclaration[id.name=/^[A-Z]/] > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName'() { },
|
|
241
275
|
'VariableDeclarator[id.name=/^[A-Z]/] > ArrowFunctionExpression > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName'() { },
|
|
242
|
-
'FunctionDeclaration[id.name=/^[A-Z]/] > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > Identifier'() { },
|
|
243
|
-
'VariableDeclarator[id.name=/^[A-Z]/] > ArrowFunctionExpression > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > Identifier'() { },
|
|
244
|
-
'FunctionDeclaration[id.name=/^[A-Z]/] > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName'() { },
|
|
245
|
-
'VariableDeclarator[id.name=/^[A-Z]/] > ArrowFunctionExpression > Identifier[typeAnnotation] > TSTypeAnnotation > TSTypeReference > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName > TSQualifiedName'() { },
|
|
246
276
|
};
|
|
247
277
|
},
|
|
248
278
|
});
|
|
@@ -24,8 +24,8 @@ exports.enforceFirestoreDocRefGeneric = (0, createRule_1.createRule)({
|
|
|
24
24
|
},
|
|
25
25
|
schema: [],
|
|
26
26
|
messages: {
|
|
27
|
-
missingGeneric: '{{ type }} must specify a generic type argument',
|
|
28
|
-
invalidGeneric: '{{ type }} must not use "any" or "{}" as generic type argument',
|
|
27
|
+
missingGeneric: '{{ type }} must specify a generic type argument for type safety. Instead of `const docRef = doc(collection)`, use `const docRef = doc<YourType>(collection)`.',
|
|
28
|
+
invalidGeneric: '{{ type }} must not use "any" or "{}" as generic type argument. Define a proper interface/type for your document: `interface UserDoc { name: string; age: number; }` and use it: `const docRef = doc<UserDoc>(collection)`.',
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
defaultOptions: [],
|
|
@@ -9,12 +9,12 @@ exports.enforceFirestorePathUtils = (0, createRule_1.createRule)({
|
|
|
9
9
|
meta: {
|
|
10
10
|
type: 'suggestion',
|
|
11
11
|
docs: {
|
|
12
|
-
description: 'Enforce usage of utility functions for Firestore paths',
|
|
12
|
+
description: 'Enforce usage of utility functions for Firestore paths to ensure type safety, maintainability, and consistent path construction. This prevents errors from manual string concatenation and makes path changes easier to manage.',
|
|
13
13
|
recommended: 'error',
|
|
14
14
|
},
|
|
15
15
|
schema: [],
|
|
16
16
|
messages: {
|
|
17
|
-
requirePathUtil: 'Use a utility function
|
|
17
|
+
requirePathUtil: 'Use a utility function for Firestore paths to ensure type safety and maintainability. Instead of `doc("users/" + userId)`, create and use a utility function: `const toUserPath = (id: string) => `users/${id}`; doc(toUserPath(userId))`.',
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
defaultOptions: [],
|
|
@@ -8,7 +8,7 @@ exports.enforceFirestoreSetMerge = (0, createRule_1.createRule)({
|
|
|
8
8
|
meta: {
|
|
9
9
|
type: 'suggestion',
|
|
10
10
|
docs: {
|
|
11
|
-
description: 'Enforce using set() with { merge: true } instead of update() for Firestore operations',
|
|
11
|
+
description: 'Enforce using set() with { merge: true } instead of update() for Firestore operations to ensure consistent behavior. The update() method fails if the document does not exist, while set() with { merge: true } creates the document if needed and safely merges fields, making it more reliable and predictable.',
|
|
12
12
|
recommended: 'error',
|
|
13
13
|
requiresTypeChecking: false,
|
|
14
14
|
extendsBaseRule: false,
|
|
@@ -16,19 +16,50 @@ exports.enforceFirestoreSetMerge = (0, createRule_1.createRule)({
|
|
|
16
16
|
fixable: 'code',
|
|
17
17
|
schema: [],
|
|
18
18
|
messages: {
|
|
19
|
-
preferSetMerge: 'Use set() with { merge: true } instead of update() for more predictable Firestore operations',
|
|
19
|
+
preferSetMerge: 'Use set() with { merge: true } instead of update() for more predictable Firestore operations. Instead of `docRef.update({ field: value })`, use `docRef.set({ field: value }, { merge: true })`. This ensures consistent behavior when the document does not exist.',
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
defaultOptions: [],
|
|
23
23
|
create(context) {
|
|
24
24
|
const updateAliases = new Set();
|
|
25
25
|
function isFirestoreUpdateCall(node) {
|
|
26
|
+
// Check if it's a set() call with merge: true
|
|
26
27
|
if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
27
28
|
const property = node.callee.property;
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (property.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
30
|
+
// If it's a set() call, check if it has merge: true
|
|
31
|
+
if (property.name === 'set') {
|
|
32
|
+
const lastArg = node.arguments[node.arguments.length - 1];
|
|
33
|
+
if (lastArg?.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
34
|
+
const hasMergeTrue = lastArg.properties.some((prop) => prop.type === utils_1.AST_NODE_TYPES.Property &&
|
|
35
|
+
prop.key.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
36
|
+
prop.key.name === 'merge' &&
|
|
37
|
+
prop.value.type === utils_1.AST_NODE_TYPES.Literal &&
|
|
38
|
+
prop.value.value === true);
|
|
39
|
+
if (hasMergeTrue) {
|
|
40
|
+
return false; // Already using set with merge: true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Only flag update() calls
|
|
45
|
+
return property.name === 'update';
|
|
46
|
+
}
|
|
30
47
|
}
|
|
31
48
|
if (node.callee.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
49
|
+
// Check if it's a setDoc() call with merge: true
|
|
50
|
+
if (node.callee.name === 'setDoc') {
|
|
51
|
+
const lastArg = node.arguments[node.arguments.length - 1];
|
|
52
|
+
if (lastArg?.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
53
|
+
const hasMergeTrue = lastArg.properties.some((prop) => prop.type === utils_1.AST_NODE_TYPES.Property &&
|
|
54
|
+
prop.key.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
55
|
+
prop.key.name === 'merge' &&
|
|
56
|
+
prop.value.type === utils_1.AST_NODE_TYPES.Literal &&
|
|
57
|
+
prop.value.value === true);
|
|
58
|
+
if (hasMergeTrue) {
|
|
59
|
+
return false; // Already using setDoc with merge: true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
32
63
|
return updateAliases.has(node.callee.name);
|
|
33
64
|
}
|
|
34
65
|
return false;
|
|
@@ -17,8 +17,8 @@ exports.enforceIdentifiableFirestoreType = (0, createRule_1.createRule)({
|
|
|
17
17
|
},
|
|
18
18
|
schema: [],
|
|
19
19
|
messages: {
|
|
20
|
-
missingType: 'Expected exported type "{{ typeName }}" in index.ts under folder "{{ folderName }}"',
|
|
21
|
-
notExtendingIdentifiable: 'Type "{{ typeName }}" must extend "Identifiable"
|
|
20
|
+
missingType: 'Expected exported type "{{ typeName }}" in index.ts under folder "{{ folderName }}". Create a type that matches the folder name: `export type {{ typeName }} = { /* fields */ }`.',
|
|
21
|
+
notExtendingIdentifiable: 'Type "{{ typeName }}" must extend "Identifiable" to ensure all Firestore documents have an ID field. Add `extends Identifiable` or include `id: string`: `export type {{ typeName }} = { id: string; /* other fields */ }`.',
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
defaultOptions: [],
|
|
@@ -8,13 +8,13 @@ exports.enforceMemoizeAsync = (0, createRule_1.createRule)({
|
|
|
8
8
|
meta: {
|
|
9
9
|
type: 'suggestion',
|
|
10
10
|
docs: {
|
|
11
|
-
description: 'Enforce @Memoize() decorator on async methods with 0-1 parameters',
|
|
11
|
+
description: 'Enforce @Memoize() decorator on async methods with 0-1 parameters to cache results and prevent redundant API calls or expensive computations. This improves performance by reusing previous results when the same parameters are provided, particularly useful for data fetching methods.',
|
|
12
12
|
recommended: 'error',
|
|
13
13
|
},
|
|
14
14
|
fixable: 'code',
|
|
15
15
|
schema: [],
|
|
16
16
|
messages: {
|
|
17
|
-
requireMemoize: 'Async methods with 0-1 parameters should be decorated with @Memoize()',
|
|
17
|
+
requireMemoize: 'Async methods with 0-1 parameters should be decorated with @Memoize() to cache results and improve performance. Instead of `async getData(id?: string)`, use `@Memoize()\nasync getData(id?: string)`. Import Memoize from "typescript-memoize".',
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
defaultOptions: [],
|
|
@@ -35,8 +35,10 @@ exports.enforceMemoizeAsync = (0, createRule_1.createRule)({
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
MethodDefinition(node) {
|
|
38
|
-
// Only process async methods
|
|
39
|
-
if (node.value.type !== utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
38
|
+
// Only process async instance methods (skip static methods)
|
|
39
|
+
if (node.value.type !== utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
40
|
+
!node.value.async ||
|
|
41
|
+
node.static) {
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
44
|
// Skip methods with more than one parameter
|
|
@@ -13,13 +13,13 @@ exports.enforceFirestoreMock = (0, createRule_1.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'problem',
|
|
15
15
|
docs: {
|
|
16
|
-
description: 'Enforce using mockFirestore
|
|
16
|
+
description: 'Enforce using the standardized mockFirestore utility instead of manual Firestore mocking or third-party mocks. This ensures consistent test behavior across the codebase, reduces boilerplate, and provides type-safe mocking of Firestore operations.',
|
|
17
17
|
recommended: 'error',
|
|
18
18
|
},
|
|
19
19
|
schema: [],
|
|
20
20
|
messages: {
|
|
21
|
-
noManualFirestoreMock: 'Use mockFirestore from __mocks__/functions/src/config/mockFirestore instead of manually mocking Firestore',
|
|
22
|
-
noMockFirebase: 'Use mockFirestore from __mocks__/functions/src/config/mockFirestore instead of mockFirebase',
|
|
21
|
+
noManualFirestoreMock: 'Use mockFirestore from __mocks__/functions/src/config/mockFirestore instead of manually mocking Firestore. Replace `jest.mock("firebase-admin", () => ({ firestore: () => ({ /* mock */ }) }))` with `import { mockFirestore } from "__mocks__/functions/src/config/mockFirestore"; jest.mock("firebase-admin", () => mockFirestore)`.',
|
|
22
|
+
noMockFirebase: 'Use mockFirestore from __mocks__/functions/src/config/mockFirestore instead of mockFirebase. Replace `import { mockFirebase } from "firestore-jest-mock"` with `import { mockFirestore } from "__mocks__/functions/src/config/mockFirestore"`.',
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
defaultOptions: [],
|
|
@@ -14,7 +14,7 @@ exports.enforceRealtimedbPathUtils = (0, createRule_1.createRule)({
|
|
|
14
14
|
},
|
|
15
15
|
schema: [],
|
|
16
16
|
messages: {
|
|
17
|
-
requirePathUtil: 'Use a utility function
|
|
17
|
+
requirePathUtil: 'Use a utility function for Realtime Database paths to ensure type safety and maintainability. Instead of `ref("users/" + userId)`, create and use a utility function: `const toUserPath = (id: string) => `users/${id}`; ref(toUserPath(userId))`.',
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
defaultOptions: [],
|
|
@@ -8,13 +8,13 @@ exports.enforceStableStringify = (0, createRule_1.createRule)({
|
|
|
8
8
|
meta: {
|
|
9
9
|
type: 'problem',
|
|
10
10
|
docs: {
|
|
11
|
-
description: 'Enforce using safe-stable-stringify instead of JSON.stringify',
|
|
11
|
+
description: 'Enforce using safe-stable-stringify instead of JSON.stringify to handle circular references and ensure deterministic output. JSON.stringify can throw errors on circular references and produce inconsistent output for objects with the same properties in different orders. safe-stable-stringify handles these cases safely.',
|
|
12
12
|
recommended: 'error',
|
|
13
13
|
},
|
|
14
14
|
fixable: 'code',
|
|
15
15
|
schema: [],
|
|
16
16
|
messages: {
|
|
17
|
-
useStableStringify: 'Use safe-stable-stringify instead of JSON.stringify for safer serialization',
|
|
17
|
+
useStableStringify: 'Use safe-stable-stringify instead of JSON.stringify for safer serialization. Replace `JSON.stringify(obj)` with `stringify(obj)`. First import it: `import stringify from "safe-stable-stringify"`. This handles circular references and provides deterministic output.',
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
defaultOptions: [],
|
|
@@ -17,7 +17,7 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
17
17
|
meta: {
|
|
18
18
|
type: 'problem',
|
|
19
19
|
docs: {
|
|
20
|
-
description: 'Enforce serializable parameters in Firebase Callable/HTTPS Cloud Functions',
|
|
20
|
+
description: 'Enforce serializable parameters in Firebase Callable/HTTPS Cloud Functions to prevent runtime errors. Firebase Functions can only pass JSON-serializable data, so using non-serializable types like Date, DocumentReference, or Map will cause failures. Use primitive types, plain objects, and arrays instead, converting complex types to their serializable representations (e.g., Date to ISO string).',
|
|
21
21
|
recommended: 'error',
|
|
22
22
|
},
|
|
23
23
|
schema: [
|
|
@@ -38,8 +38,8 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
38
38
|
},
|
|
39
39
|
],
|
|
40
40
|
messages: {
|
|
41
|
-
nonSerializableParam: 'Parameter type "{{ type }}" is not serializable',
|
|
42
|
-
nonSerializableProperty: 'Property "{{ prop }}" has non-serializable type "{{ type }}"',
|
|
41
|
+
nonSerializableParam: 'Parameter type "{{ type }}" is not serializable in Firebase Cloud Functions. Use JSON-serializable types like string, number, boolean, arrays, or plain objects. Instead of `Date`, use ISO strings: `new Date().toISOString()`.',
|
|
42
|
+
nonSerializableProperty: 'Property "{{ prop }}" has non-serializable type "{{ type }}". Use JSON-serializable types. For example, instead of `{ timestamp: Date }`, use `{ timestamp: string }` with ISO format.',
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
45
|
defaultOptions: [
|