@blumintinc/eslint-plugin-blumint 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -11
- package/lib/index.js +14 -12
- package/lib/rules/avoid-utils-directory.js +0 -4
- package/lib/rules/consistent-callback-naming.js +42 -3
- package/lib/rules/dynamic-https-errors.d.ts +1 -1
- package/lib/rules/dynamic-https-errors.js +132 -41
- package/lib/rules/enforce-boolean-naming-prefixes.js +0 -212
- package/lib/rules/enforce-date-ttime.d.ts +1 -0
- package/lib/rules/enforce-date-ttime.js +156 -0
- package/lib/rules/enforce-dynamic-firebase-imports.d.ts +2 -1
- package/lib/rules/enforce-dynamic-firebase-imports.js +3 -2
- package/lib/rules/enforce-f-extension-for-entry-points.d.ts +8 -0
- package/lib/rules/enforce-f-extension-for-entry-points.js +283 -0
- package/lib/rules/enforce-global-constants.js +3 -3
- package/lib/rules/enforce-id-capitalization.js +1 -1
- package/lib/rules/enforce-memoize-async.js +69 -15
- package/lib/rules/enforce-props-argument-name.js +42 -16
- package/lib/rules/enforce-stable-hash-spread-props.js +3 -3
- package/lib/rules/enforce-transform-memoization.js +1 -1
- package/lib/rules/enforce-verb-noun-naming.js +3814 -4641
- package/lib/rules/global-const-style.js +16 -4
- package/lib/rules/memo-compare-deeply-complex-props.js +16 -3
- package/lib/rules/memo-nested-react-components.js +108 -103
- package/lib/rules/no-async-foreach.js +7 -2
- package/lib/rules/no-circular-references.d.ts +2 -1
- package/lib/rules/no-circular-references.js +13 -15
- package/lib/rules/no-console-error.js +12 -10
- package/lib/rules/no-empty-dependency-use-callbacks.js +1 -1
- package/lib/rules/no-entire-object-hook-deps.js +48 -1
- package/lib/rules/no-excessive-parent-chain.js +3 -0
- package/lib/rules/no-inline-component-prop.js +16 -7
- package/lib/rules/no-passthrough-getters.d.ts +2 -2
- package/lib/rules/no-passthrough-getters.js +83 -1
- package/lib/rules/no-redundant-this-params.js +50 -1
- package/lib/rules/no-unmemoized-memo-without-props.js +1 -1
- package/lib/rules/no-unnecessary-destructuring-rename.js +2 -5
- package/lib/rules/parallelize-async-operations.js +119 -54
- package/lib/rules/prefer-nullish-coalescing-boolean-props.js +109 -4
- package/lib/rules/prefer-params-over-parent-id.js +1 -1
- package/lib/rules/prefer-settings-object.js +27 -10
- package/lib/rules/prefer-type-alias-over-typeof-constant.js +9 -0
- package/lib/rules/prefer-usememo-over-useeffect-usestate.js +1 -1
- package/lib/rules/prevent-children-clobber.js +9 -5
- package/lib/rules/react-memoize-literals.js +131 -12
- package/lib/rules/require-https-error-cause.js +30 -11
- package/lib/rules/require-memo.js +17 -9
- package/lib/utils/ASTHelpers.d.ts +34 -1
- package/lib/utils/ASTHelpers.js +346 -112
- package/package.json +1 -1
|
@@ -73,8 +73,6 @@ exports.enforceBooleanNamingPrefixes = (0, createRule_1.createRule)({
|
|
|
73
73
|
const approvedPrefixes = options.prefixes || DEFAULT_OPTIONS.prefixes;
|
|
74
74
|
const ignoreOverriddenGetters = options.ignoreOverriddenGetters ??
|
|
75
75
|
DEFAULT_OPTIONS.ignoreOverriddenGetters;
|
|
76
|
-
const importStatusCache = new Map();
|
|
77
|
-
const externalApiUsageCache = new Map();
|
|
78
76
|
function findVariableInScopes(name) {
|
|
79
77
|
let currentScope = context.getScope();
|
|
80
78
|
while (currentScope) {
|
|
@@ -1072,215 +1070,6 @@ exports.enforceBooleanNamingPrefixes = (0, createRule_1.createRule)({
|
|
|
1072
1070
|
});
|
|
1073
1071
|
}
|
|
1074
1072
|
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Check if an identifier is imported from an external module
|
|
1077
|
-
*/
|
|
1078
|
-
function isImportedIdentifier(name) {
|
|
1079
|
-
if (importStatusCache.has(name)) {
|
|
1080
|
-
const cached = importStatusCache.get(name);
|
|
1081
|
-
if (cached !== undefined)
|
|
1082
|
-
return cached;
|
|
1083
|
-
}
|
|
1084
|
-
const variable = findVariableInScopes(name);
|
|
1085
|
-
if (!variable) {
|
|
1086
|
-
importStatusCache.set(name, false);
|
|
1087
|
-
return false;
|
|
1088
|
-
}
|
|
1089
|
-
const isImport = variable.defs.some((def) => def.type === 'ImportBinding');
|
|
1090
|
-
importStatusCache.set(name, isImport);
|
|
1091
|
-
return isImport;
|
|
1092
|
-
}
|
|
1093
|
-
/**
|
|
1094
|
-
* Check if a variable is used with an external API
|
|
1095
|
-
*/
|
|
1096
|
-
function isVariableUsedWithExternalApi(variableName) {
|
|
1097
|
-
if (externalApiUsageCache.has(variableName)) {
|
|
1098
|
-
const cached = externalApiUsageCache.get(variableName);
|
|
1099
|
-
if (cached !== undefined)
|
|
1100
|
-
return cached;
|
|
1101
|
-
}
|
|
1102
|
-
const variable = findVariableInScopes(variableName);
|
|
1103
|
-
if (!variable) {
|
|
1104
|
-
externalApiUsageCache.set(variableName, false);
|
|
1105
|
-
return false;
|
|
1106
|
-
}
|
|
1107
|
-
for (const reference of variable.references) {
|
|
1108
|
-
if (reference.identifier === variable.identifiers[0])
|
|
1109
|
-
continue;
|
|
1110
|
-
const id = reference.identifier;
|
|
1111
|
-
const markAndReturnTrue = () => {
|
|
1112
|
-
externalApiUsageCache.set(variableName, true);
|
|
1113
|
-
return true;
|
|
1114
|
-
};
|
|
1115
|
-
if (id.parent?.type === utils_1.AST_NODE_TYPES.Property &&
|
|
1116
|
-
id.parent.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1117
|
-
id.parent.parent.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
|
1118
|
-
id.parent.parent.parent.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
1119
|
-
isImportedIdentifier(id.parent.parent.parent.callee.name)) {
|
|
1120
|
-
return markAndReturnTrue();
|
|
1121
|
-
}
|
|
1122
|
-
if (id.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
1123
|
-
if (id.parent.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
1124
|
-
isImportedIdentifier(id.parent.callee.name)) {
|
|
1125
|
-
return markAndReturnTrue();
|
|
1126
|
-
}
|
|
1127
|
-
if (id.parent.callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
|
|
1128
|
-
id.parent.callee.object.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
1129
|
-
isImportedIdentifier(id.parent.callee.object.name)) {
|
|
1130
|
-
return markAndReturnTrue();
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
if (id.parent?.type === utils_1.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1134
|
-
id.parent.parent?.type === utils_1.AST_NODE_TYPES.JSXAttribute &&
|
|
1135
|
-
id.parent.parent.parent?.type === utils_1.AST_NODE_TYPES.JSXOpeningElement &&
|
|
1136
|
-
id.parent.parent.parent.name.type === utils_1.AST_NODE_TYPES.JSXIdentifier &&
|
|
1137
|
-
isImportedIdentifier(id.parent.parent.parent.name.name)) {
|
|
1138
|
-
return markAndReturnTrue();
|
|
1139
|
-
}
|
|
1140
|
-
if (id.parent?.type === utils_1.AST_NODE_TYPES.JSXSpreadAttribute &&
|
|
1141
|
-
id.parent.parent?.type === utils_1.AST_NODE_TYPES.JSXOpeningElement &&
|
|
1142
|
-
id.parent.parent.name.type === utils_1.AST_NODE_TYPES.JSXIdentifier &&
|
|
1143
|
-
isImportedIdentifier(id.parent.parent.name.name)) {
|
|
1144
|
-
return markAndReturnTrue();
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
externalApiUsageCache.set(variableName, false);
|
|
1148
|
-
return false;
|
|
1149
|
-
}
|
|
1150
|
-
const HOOK_NAMES = new Set(['useMemo', 'useCallback', 'useState']);
|
|
1151
|
-
function findVariableFromReactHook(objectExpr) {
|
|
1152
|
-
let current = objectExpr;
|
|
1153
|
-
while (current) {
|
|
1154
|
-
if (current.type === utils_1.AST_NODE_TYPES.TSAsExpression) {
|
|
1155
|
-
current = current.parent;
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
if (current.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
|
1159
|
-
current.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
|
1160
|
-
current.parent.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
1161
|
-
HOOK_NAMES.has(current.parent.callee.name) &&
|
|
1162
|
-
current.parent.parent?.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
1163
|
-
current.parent.parent.id.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
1164
|
-
return current.parent.parent.id.name;
|
|
1165
|
-
}
|
|
1166
|
-
current = current.parent;
|
|
1167
|
-
}
|
|
1168
|
-
return undefined;
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Check property definitions for boolean values
|
|
1172
|
-
*/
|
|
1173
|
-
function checkProperty(node) {
|
|
1174
|
-
if (node.key.type !== utils_1.AST_NODE_TYPES.Identifier)
|
|
1175
|
-
return;
|
|
1176
|
-
const propertyName = node.key.name;
|
|
1177
|
-
// Check if it's a boolean property
|
|
1178
|
-
let isBooleanProperty = false;
|
|
1179
|
-
// Check if it's initialized with a boolean value
|
|
1180
|
-
if (node.value.type === utils_1.AST_NODE_TYPES.Literal &&
|
|
1181
|
-
typeof node.value.value === 'boolean') {
|
|
1182
|
-
isBooleanProperty = true;
|
|
1183
|
-
}
|
|
1184
|
-
// Check if it's a method that returns a boolean
|
|
1185
|
-
if ((node.value.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
1186
|
-
node.value.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression) &&
|
|
1187
|
-
node.value.returnType?.typeAnnotation.type ===
|
|
1188
|
-
utils_1.AST_NODE_TYPES.TSBooleanKeyword) {
|
|
1189
|
-
isBooleanProperty = true;
|
|
1190
|
-
}
|
|
1191
|
-
// Skip checking if this property is part of an object literal passed to an external function
|
|
1192
|
-
if (isBooleanProperty && !hasApprovedPrefix(propertyName)) {
|
|
1193
|
-
// Special cases for common Node.js API boolean properties
|
|
1194
|
-
if ((propertyName === 'recursive' || propertyName === 'keepAlive') &&
|
|
1195
|
-
node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1196
|
-
node.parent.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
1197
|
-
return; // Skip checking for these properties in object literals passed to functions
|
|
1198
|
-
}
|
|
1199
|
-
// Check if this property is in an object literal that's an argument to a function call
|
|
1200
|
-
let isExternalApiCall = false;
|
|
1201
|
-
// Navigate up to find if we're in an object expression that's an argument to a function call
|
|
1202
|
-
if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1203
|
-
node.parent.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
1204
|
-
const callExpression = node.parent.parent;
|
|
1205
|
-
// Check if the function being called is an identifier (like mkdirSync, createServer, etc.)
|
|
1206
|
-
if (callExpression.callee.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
1207
|
-
const calleeName = callExpression.callee.name;
|
|
1208
|
-
if (isImportedIdentifier(calleeName)) {
|
|
1209
|
-
isExternalApiCall = true;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
// Also check for member expressions like fs.mkdirSync
|
|
1213
|
-
if (callExpression.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
1214
|
-
// For member expressions, check if the object is imported
|
|
1215
|
-
const objectNode = callExpression.callee.object;
|
|
1216
|
-
if (objectNode.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
1217
|
-
const objectName = objectNode.name;
|
|
1218
|
-
if (isImportedIdentifier(objectName)) {
|
|
1219
|
-
isExternalApiCall = true;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
// Check if this property is in an object literal that's being assigned to a variable
|
|
1225
|
-
// This handles cases like const messageInputProps = { grow: true }
|
|
1226
|
-
if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1227
|
-
node.parent.parent?.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
1228
|
-
node.parent.parent.id.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
1229
|
-
const variableName = node.parent.parent.id.name;
|
|
1230
|
-
if (isVariableUsedWithExternalApi(variableName)) {
|
|
1231
|
-
isExternalApiCall = true;
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
// Special case for useMemo and other React hooks
|
|
1235
|
-
// This handles cases like:
|
|
1236
|
-
// 1. const messageInputProps = useMemo(() => ({ grow: true }), [])
|
|
1237
|
-
// 2. const messageInputProps = useMemo(() => { return { grow: true }; }, [])
|
|
1238
|
-
if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
1239
|
-
const hookVariable = findVariableFromReactHook(node.parent);
|
|
1240
|
-
if (hookVariable && isVariableUsedWithExternalApi(hookVariable)) {
|
|
1241
|
-
isExternalApiCall = true;
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
// Check if this property is in an object literal that's directly passed to an imported function
|
|
1245
|
-
// This handles cases like ExternalComponent({ grow: true })
|
|
1246
|
-
if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1247
|
-
node.parent.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
|
1248
|
-
node.parent.parent.callee.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
1249
|
-
const calleeName = node.parent.parent.callee.name;
|
|
1250
|
-
if (isImportedIdentifier(calleeName)) {
|
|
1251
|
-
isExternalApiCall = true;
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
// Check if this property is in an object literal that's directly passed as a JSX attribute
|
|
1255
|
-
// This handles cases like <ExternalComponent config={{ active: true }} />
|
|
1256
|
-
if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
1257
|
-
node.parent.parent?.type === utils_1.AST_NODE_TYPES.JSXExpressionContainer &&
|
|
1258
|
-
node.parent.parent.parent?.type === utils_1.AST_NODE_TYPES.JSXAttribute &&
|
|
1259
|
-
node.parent.parent.parent.parent?.type ===
|
|
1260
|
-
utils_1.AST_NODE_TYPES.JSXOpeningElement) {
|
|
1261
|
-
const jsxOpeningElement = node.parent.parent.parent.parent;
|
|
1262
|
-
if (jsxOpeningElement.name.type === utils_1.AST_NODE_TYPES.JSXIdentifier) {
|
|
1263
|
-
const componentName = jsxOpeningElement.name.name;
|
|
1264
|
-
if (isImportedIdentifier(componentName)) {
|
|
1265
|
-
isExternalApiCall = true;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
// Only report if it's not an external API call
|
|
1270
|
-
if (!isExternalApiCall) {
|
|
1271
|
-
context.report({
|
|
1272
|
-
node: node.key,
|
|
1273
|
-
messageId: 'missingBooleanPrefix',
|
|
1274
|
-
data: {
|
|
1275
|
-
type: 'property',
|
|
1276
|
-
name: propertyName,
|
|
1277
|
-
capitalizedName: capitalizeFirst(propertyName),
|
|
1278
|
-
prefixes: formatPrefixes(),
|
|
1279
|
-
},
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
1073
|
/**
|
|
1285
1074
|
* Check property signatures in interfaces/types for boolean types
|
|
1286
1075
|
*/
|
|
@@ -1390,7 +1179,6 @@ exports.enforceBooleanNamingPrefixes = (0, createRule_1.createRule)({
|
|
|
1390
1179
|
},
|
|
1391
1180
|
MethodDefinition: checkMethodDefinition,
|
|
1392
1181
|
TSAbstractMethodDefinition: checkMethodDefinition,
|
|
1393
|
-
Property: checkProperty,
|
|
1394
1182
|
ClassProperty: checkClassProperty,
|
|
1395
1183
|
PropertyDefinition: checkClassPropertyDeclaration,
|
|
1396
1184
|
TSPropertySignature: checkPropertySignature,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const enforceDateTTime: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"enforceDateTTime", [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.enforceDateTTime = void 0;
|
|
27
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
28
|
+
const ts = __importStar(require("typescript"));
|
|
29
|
+
const createRule_1 = require("../utils/createRule");
|
|
30
|
+
exports.enforceDateTTime = (0, createRule_1.createRule)({
|
|
31
|
+
name: 'enforce-date-ttime',
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'suggestion',
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'Enforce that any generic type parameter named TTime is explicitly set to Date in frontend code',
|
|
36
|
+
recommended: 'error',
|
|
37
|
+
},
|
|
38
|
+
fixable: 'code',
|
|
39
|
+
schema: [],
|
|
40
|
+
messages: {
|
|
41
|
+
enforceDateTTime: '{{typeName}} leaves TTime unspecified or not Date → Firestore Frontend Hooks convert Timestamp to Date on the client, so non-Date TTime misrepresents runtime values and forces defensive conversions → Set the TTime argument to Date explicitly (e.g., {{typeName}}<..., Date, ...>).',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
defaultOptions: [],
|
|
45
|
+
create(context) {
|
|
46
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
47
|
+
const parserServices = sourceCode?.parserServices ?? context.parserServices;
|
|
48
|
+
const checker = parserServices?.program?.getTypeChecker();
|
|
49
|
+
if (!parserServices || !checker) {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const tTimeIndexCache = new WeakMap();
|
|
53
|
+
/**
|
|
54
|
+
* Finds the index of the TTime parameter in the given symbol's declarations.
|
|
55
|
+
*/
|
|
56
|
+
function findTTimeParameterIndex(symbol) {
|
|
57
|
+
if (tTimeIndexCache.has(symbol)) {
|
|
58
|
+
return tTimeIndexCache.get(symbol);
|
|
59
|
+
}
|
|
60
|
+
const declarations = symbol.getDeclarations();
|
|
61
|
+
if (!declarations) {
|
|
62
|
+
tTimeIndexCache.set(symbol, undefined);
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
for (const declaration of declarations) {
|
|
66
|
+
if (ts.isTypeAliasDeclaration(declaration) ||
|
|
67
|
+
ts.isInterfaceDeclaration(declaration) ||
|
|
68
|
+
ts.isClassDeclaration(declaration)) {
|
|
69
|
+
if (declaration.typeParameters) {
|
|
70
|
+
const index = declaration.typeParameters.findIndex((tp) => tp.name.text === 'TTime');
|
|
71
|
+
if (index !== -1) {
|
|
72
|
+
tTimeIndexCache.set(symbol, index);
|
|
73
|
+
return index;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
tTimeIndexCache.set(symbol, undefined);
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks if a type node is exactly "Date".
|
|
83
|
+
*/
|
|
84
|
+
function isExactDate(node) {
|
|
85
|
+
if (node.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
|
|
86
|
+
node.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
87
|
+
node.typeName.name === 'Date' &&
|
|
88
|
+
(!node.typeParameters || node.typeParameters.params.length === 0)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
TSTypeReference(node) {
|
|
95
|
+
const typeNameNode = node.typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName
|
|
96
|
+
? node.typeName.right
|
|
97
|
+
: node.typeName;
|
|
98
|
+
if (typeNameNode.type !== utils_1.AST_NODE_TYPES.Identifier)
|
|
99
|
+
return;
|
|
100
|
+
// Skip the "Date" type itself
|
|
101
|
+
if (typeNameNode.name === 'Date')
|
|
102
|
+
return;
|
|
103
|
+
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
|
104
|
+
const symbol = checker.getSymbolAtLocation(tsNode.typeName);
|
|
105
|
+
if (!symbol)
|
|
106
|
+
return;
|
|
107
|
+
const resolvedSymbol = symbol.flags & ts.SymbolFlags.Alias
|
|
108
|
+
? checker.getAliasedSymbol(symbol)
|
|
109
|
+
: symbol;
|
|
110
|
+
const tTimeIndex = findTTimeParameterIndex(resolvedSymbol);
|
|
111
|
+
if (tTimeIndex === undefined)
|
|
112
|
+
return;
|
|
113
|
+
const typeArgs = node.typeParameters?.params || [];
|
|
114
|
+
const tTimeArg = typeArgs[tTimeIndex];
|
|
115
|
+
const typeName = sourceCode.getText(node.typeName);
|
|
116
|
+
if (!tTimeArg) {
|
|
117
|
+
// TTime is omitted
|
|
118
|
+
context.report({
|
|
119
|
+
node,
|
|
120
|
+
messageId: 'enforceDateTTime',
|
|
121
|
+
data: { typeName },
|
|
122
|
+
fix(fixer) {
|
|
123
|
+
if (node.typeParameters) {
|
|
124
|
+
// Already has type parameters, but not enough to cover TTime
|
|
125
|
+
const lastParam = node.typeParameters.params[node.typeParameters.params.length - 1];
|
|
126
|
+
// Check if we can just append ", Date"
|
|
127
|
+
// We can only do this safely if all parameters between existing ones and TTime have defaults.
|
|
128
|
+
// For simplicity and safety, we only fix if tTimeIndex is the next one or if it's already provided.
|
|
129
|
+
if (tTimeIndex === node.typeParameters.params.length) {
|
|
130
|
+
return fixer.insertTextAfter(lastParam, ', Date');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (tTimeIndex === 0) {
|
|
134
|
+
// No type parameters and TTime is the first one
|
|
135
|
+
return fixer.insertTextAfter(node.typeName, '<Date>');
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (!isExactDate(tTimeArg)) {
|
|
142
|
+
// TTime is provided but is not exactly Date
|
|
143
|
+
context.report({
|
|
144
|
+
node: tTimeArg,
|
|
145
|
+
messageId: 'enforceDateTTime',
|
|
146
|
+
data: { typeName },
|
|
147
|
+
fix(fixer) {
|
|
148
|
+
return fixer.replaceText(tTimeArg, 'Date');
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=enforce-date-ttime.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
|
|
2
|
+
declare const enforceFirebaseImports: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"noDynamicImport", never[], {
|
|
3
3
|
ImportDeclaration(node: TSESTree.ImportDeclaration): void;
|
|
4
4
|
}>;
|
|
5
|
+
export default enforceFirebaseImports;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enforceFirebaseImports = void 0;
|
|
4
3
|
const createRule_1 = require("../utils/createRule");
|
|
5
|
-
|
|
4
|
+
const enforceFirebaseImports = (0, createRule_1.createRule)({
|
|
6
5
|
name: 'enforce-dynamic-firebase-imports',
|
|
7
6
|
meta: {
|
|
8
7
|
type: 'problem',
|
|
@@ -112,6 +111,7 @@ exports.enforceFirebaseImports = (0, createRule_1.createRule)({
|
|
|
112
111
|
suggest: [
|
|
113
112
|
{
|
|
114
113
|
messageId: 'noDynamicImport',
|
|
114
|
+
data: { importPath },
|
|
115
115
|
fix(fixer) {
|
|
116
116
|
const replacement = buildReplacement({
|
|
117
117
|
allowSideEffectFix: true,
|
|
@@ -127,4 +127,5 @@ exports.enforceFirebaseImports = (0, createRule_1.createRule)({
|
|
|
127
127
|
};
|
|
128
128
|
},
|
|
129
129
|
});
|
|
130
|
+
exports.default = enforceFirebaseImports;
|
|
130
131
|
//# sourceMappingURL=enforce-dynamic-firebase-imports.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
type EnforceFExtensionOptions = [
|
|
3
|
+
{
|
|
4
|
+
entryPoints?: string[];
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
export declare const enforceFExtensionForEntryPoints: TSESLint.RuleModule<"requireFExtension", EnforceFExtensionOptions, TSESLint.RuleListener>;
|
|
8
|
+
export {};
|