@blumintinc/eslint-plugin-blumint 1.5.5 → 1.7.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 +62 -39
- package/lib/index.js +37 -1
- package/lib/rules/enforce-assert-throws.d.ts +1 -0
- package/lib/rules/enforce-assert-throws.js +132 -0
- package/lib/rules/enforce-centralized-mock-firestore.d.ts +1 -0
- package/lib/rules/enforce-centralized-mock-firestore.js +55 -0
- package/lib/rules/enforce-exported-function-types.js +3 -2
- package/lib/rules/enforce-firestore-facade.d.ts +3 -0
- package/lib/rules/enforce-firestore-facade.js +126 -0
- package/lib/rules/enforce-firestore-set-merge.js +83 -2
- package/lib/rules/enforce-verb-noun-naming.js +2 -0
- package/lib/rules/no-complex-cloud-params.d.ts +1 -0
- package/lib/rules/no-complex-cloud-params.js +363 -0
- package/lib/rules/no-explicit-return-type.js +11 -3
- package/lib/rules/no-firestore-jest-mock.d.ts +1 -0
- package/lib/rules/no-firestore-jest-mock.js +59 -0
- package/lib/rules/no-mixed-firestore-transactions.d.ts +1 -0
- package/lib/rules/no-mixed-firestore-transactions.js +115 -0
- package/lib/rules/no-mock-firebase-admin.d.ts +1 -0
- package/lib/rules/no-mock-firebase-admin.js +50 -0
- package/lib/rules/prefer-batch-operations.d.ts +3 -0
- package/lib/rules/prefer-batch-operations.js +176 -0
- package/lib/rules/prefer-clone-deep.d.ts +1 -0
- package/lib/rules/prefer-clone-deep.js +72 -0
- package/lib/rules/prefer-settings-object.js +164 -6
- package/lib/rules/semantic-function-prefixes.js +7 -0
- package/lib/rules/sync-onwrite-name-func.d.ts +1 -0
- package/lib/rules/sync-onwrite-name-func.js +79 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,48 +52,71 @@ Or use the recommended config:
|
|
|
52
52
|
<!-- begin auto-generated rules list -->
|
|
53
53
|
|
|
54
54
|
💼 Configurations enabled in.\
|
|
55
|
+
⚠️ Configurations set to warn in.\
|
|
55
56
|
✅ Set in the `recommended` configuration.\
|
|
56
57
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
57
58
|
💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
58
59
|
|
|
59
|
-
| Name | Description
|
|
60
|
-
| :--------------------------------------------------------------------------------------- |
|
|
61
|
-
| [array-methods-this-context](docs/rules/array-methods-this-context.md) | Prevent misuse of Array methods in OOP
|
|
62
|
-
| [avoid-utils-directory](docs/rules/avoid-utils-directory.md) | Enforce using util/ instead of utils/ directory
|
|
63
|
-
| [class-methods-read-top-to-bottom](docs/rules/class-methods-read-top-to-bottom.md) | Ensures classes read linearly from top to bottom.
|
|
64
|
-
| [consistent-callback-naming](docs/rules/consistent-callback-naming.md) | Enforce consistent naming conventions for callback props and functions
|
|
65
|
-
| [dynamic-https-errors](docs/rules/dynamic-https-errors.md) | Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id.
|
|
66
|
-
| [enforce-
|
|
67
|
-
| [enforce-
|
|
68
|
-
| [enforce-
|
|
69
|
-
| [enforce-
|
|
70
|
-
| [enforce-
|
|
71
|
-
| [enforce-
|
|
72
|
-
| [enforce-
|
|
73
|
-
| [enforce-
|
|
74
|
-
| [
|
|
75
|
-
| [
|
|
76
|
-
| [
|
|
77
|
-
| [
|
|
78
|
-
| [
|
|
79
|
-
| [
|
|
80
|
-
| [
|
|
81
|
-
| [
|
|
82
|
-
| [
|
|
83
|
-
| [
|
|
84
|
-
| [
|
|
85
|
-
| [
|
|
86
|
-
| [no-
|
|
87
|
-
| [no-
|
|
88
|
-
| [no-
|
|
89
|
-
| [
|
|
90
|
-
| [
|
|
91
|
-
| [
|
|
92
|
-
| [
|
|
93
|
-
| [
|
|
94
|
-
| [
|
|
95
|
-
| [
|
|
96
|
-
| [
|
|
97
|
-
| [
|
|
60
|
+
| Name | Description | 💼 | ⚠️ | 🔧 | 💭 |
|
|
61
|
+
| :--------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :- | :- | :- | :- |
|
|
62
|
+
| [array-methods-this-context](docs/rules/array-methods-this-context.md) | Prevent misuse of Array methods in OOP | ✅ | | | |
|
|
63
|
+
| [avoid-utils-directory](docs/rules/avoid-utils-directory.md) | Enforce using util/ instead of utils/ directory | ✅ | | 🔧 | |
|
|
64
|
+
| [class-methods-read-top-to-bottom](docs/rules/class-methods-read-top-to-bottom.md) | Ensures classes read linearly from top to bottom. | ✅ | | 🔧 | |
|
|
65
|
+
| [consistent-callback-naming](docs/rules/consistent-callback-naming.md) | Enforce consistent naming conventions for callback props and functions | ✅ | | 🔧 | |
|
|
66
|
+
| [dynamic-https-errors](docs/rules/dynamic-https-errors.md) | Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id. | ✅ | | | |
|
|
67
|
+
| [enforce-assert-throws](docs/rules/enforce-assert-throws.md) | Enforce that functions with assert- prefix must throw an error | ✅ | | | |
|
|
68
|
+
| [enforce-callable-types](docs/rules/enforce-callable-types.md) | Enforce Params and Response type exports in callable functions | ✅ | | | |
|
|
69
|
+
| [enforce-callback-memo](docs/rules/enforce-callback-memo.md) | 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. | ✅ | | | |
|
|
70
|
+
| [enforce-dynamic-firebase-imports](docs/rules/enforce-dynamic-firebase-imports.md) | 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. | ✅ | | | |
|
|
71
|
+
| [enforce-exported-function-types](docs/rules/enforce-exported-function-types.md) | Enforce exporting types for function props and return values | ✅ | | | |
|
|
72
|
+
| [enforce-firestore-doc-ref-generic](docs/rules/enforce-firestore-doc-ref-generic.md) | Enforce generic argument for Firestore DocumentReference, CollectionReference and CollectionGroup | ✅ | | | 💭 |
|
|
73
|
+
| [enforce-firestore-facade](docs/rules/enforce-firestore-facade.md) | Enforce usage of Firestore facades instead of direct Firestore methods | ✅ | | | |
|
|
74
|
+
| [enforce-firestore-path-utils](docs/rules/enforce-firestore-path-utils.md) | 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. | ✅ | | | |
|
|
75
|
+
| [enforce-firestore-set-merge](docs/rules/enforce-firestore-set-merge.md) | 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. | ✅ | | 🔧 | |
|
|
76
|
+
| [enforce-identifiable-firestore-type](docs/rules/enforce-identifiable-firestore-type.md) | Enforce that Firestore type definitions extend Identifiable and match their folder name | ✅ | | | |
|
|
77
|
+
| [enforce-memoize-async](docs/rules/enforce-memoize-async.md) | 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. | ✅ | | 🔧 | |
|
|
78
|
+
| [enforce-mock-firestore](docs/rules/enforce-mock-firestore.md) | 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. | ✅ | | | |
|
|
79
|
+
| [enforce-realtimedb-path-utils](docs/rules/enforce-realtimedb-path-utils.md) | Enforce usage of utility functions for Realtime Database paths | ✅ | | | |
|
|
80
|
+
| [enforce-safe-stringify](docs/rules/enforce-safe-stringify.md) | 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. | ✅ | | 🔧 | |
|
|
81
|
+
| [enforce-serializable-params](docs/rules/enforce-serializable-params.md) | 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). | ✅ | | | |
|
|
82
|
+
| [enforce-verb-noun-naming](docs/rules/enforce-verb-noun-naming.md) | Enforce verb phrases for functions and methods | ✅ | | | |
|
|
83
|
+
| [export-if-in-doubt](docs/rules/export-if-in-doubt.md) | All top-level const definitions, type definitions, and functions should be exported | | | | |
|
|
84
|
+
| [extract-global-constants](docs/rules/extract-global-constants.md) | Extract static constants and functions to the global scope when possible | ✅ | | | |
|
|
85
|
+
| [generic-starts-with-t](docs/rules/generic-starts-with-t.md) | Enforce TypeScript generic types to start with T | ✅ | | | |
|
|
86
|
+
| [global-const-style](docs/rules/global-const-style.md) | Enforce UPPER_SNAKE_CASE and as const for global static constants | ✅ | | 🔧 | |
|
|
87
|
+
| [no-async-array-filter](docs/rules/no-async-array-filter.md) | Disallow async callbacks in Array.filter() as they lead to incorrect filtering. Since async functions return Promises which are always truthy, the filter will keep all elements regardless of the async check's result. Use Promise.all() with map() first, then filter based on the resolved results. | ✅ | | | |
|
|
88
|
+
| [no-async-foreach](docs/rules/no-async-foreach.md) | Disallow Array.forEach with an async callback function as it does not wait for promises to resolve. This can lead to race conditions and unexpected behavior. Use a standard for...of loop for sequential execution or Promise.all with map for concurrent execution. | ✅ | | | |
|
|
89
|
+
| [no-class-instance-destructuring](docs/rules/no-class-instance-destructuring.md) | Disallow destructuring of class instances to prevent loss of `this` context | ✅ | | 🔧 | |
|
|
90
|
+
| [no-complex-cloud-params](docs/rules/no-complex-cloud-params.md) | Disallow passing complex objects to cloud functions | ✅ | | | |
|
|
91
|
+
| [no-compositing-layer-props](docs/rules/no-compositing-layer-props.md) | Warn when using CSS properties that trigger compositing layers, which can impact performance. Properties like transform, opacity, filter, and will-change create new GPU layers. While sometimes beneficial for animations, excessive layer creation can increase memory usage and hurt performance. Consider alternatives or explicitly document intentional layer promotion. | ✅ | | | |
|
|
92
|
+
| [no-conditional-literals-in-jsx](docs/rules/no-conditional-literals-in-jsx.md) | Disallow use of conditional literals in JSX code | ✅ | | | |
|
|
93
|
+
| [no-entire-object-hook-deps](docs/rules/no-entire-object-hook-deps.md) | Avoid using entire objects in React hook dependency arrays when only specific fields are used, as this can cause unnecessary re-renders. When a hook only uses obj.name but obj is in the deps array, any change to obj.age will trigger the hook. Use individual fields (obj.name) instead of the entire object. Requires TypeScript and `parserOptions.project` to be configured. | ✅ | | 🔧 | 💭 |
|
|
94
|
+
| [no-explicit-return-type](docs/rules/no-explicit-return-type.md) | Disallow explicit return type annotations on functions when TypeScript can infer them. This reduces code verbosity and maintenance burden while leveraging TypeScript's powerful type inference. Exceptions are made for type guard functions (using the `is` keyword), recursive functions, overloaded functions, interface methods, and abstract methods where explicit types improve clarity. | ✅ | | 🔧 | |
|
|
95
|
+
| [no-filter-without-return](docs/rules/no-filter-without-return.md) | Disallow Array.filter callbacks without an explicit return (if part of a block statement) | ✅ | | | |
|
|
96
|
+
| [no-firestore-object-arrays](docs/rules/no-firestore-object-arrays.md) | Disallow arrays of objects in Firestore type definitions to optimize performance and avoid unnecessary fetches | | ✅ | | |
|
|
97
|
+
| [no-jsx-in-hooks](docs/rules/no-jsx-in-hooks.md) | Prevent hooks from returning JSX | ✅ | | | |
|
|
98
|
+
| [no-jsx-whitespace-literal](docs/rules/no-jsx-whitespace-literal.md) | Disallow the use of {" "} elements in JSX code | ✅ | | | |
|
|
99
|
+
| [no-memoize-on-static](docs/rules/no-memoize-on-static.md) | Prevent using @Memoize() decorator on static methods | ✅ | | | |
|
|
100
|
+
| [no-misused-switch-case](docs/rules/no-misused-switch-case.md) | Prevent misuse of logical OR (\|\|) in switch case statements, which can lead to confusing and error-prone code. Instead of using OR operators in case expressions, use multiple case statements in sequence to handle multiple values. This improves code readability and follows the standard switch-case pattern. | ✅ | | | |
|
|
101
|
+
| [no-mixed-firestore-transactions](docs/rules/no-mixed-firestore-transactions.md) | Prevent mixing transactional and non-transactional Firestore operations within a transaction | ✅ | | | |
|
|
102
|
+
| [no-redundant-param-types](docs/rules/no-redundant-param-types.md) | Disallow redundant parameter type annotations | ✅ | | 🔧 | |
|
|
103
|
+
| [no-unpinned-dependencies](docs/rules/no-unpinned-dependencies.md) | Enforces pinned dependencies | ✅ | | 🔧 | |
|
|
104
|
+
| [no-unsafe-firestore-spread](docs/rules/no-unsafe-firestore-spread.md) | Prevent unsafe object/array spreads in Firestore updates | ✅ | | 🔧 | |
|
|
105
|
+
| [no-unused-props](docs/rules/no-unused-props.md) | Detect unused props in React component type definitions | ✅ | | 🔧 | |
|
|
106
|
+
| [no-useless-fragment](docs/rules/no-useless-fragment.md) | Prevent unnecessary use of React fragments | | | 🔧 | |
|
|
107
|
+
| [prefer-batch-operations](docs/rules/prefer-batch-operations.md) | Enforce using setAll() and overwriteAll() instead of multiple set() or overwrite() calls | ✅ | | 🔧 | |
|
|
108
|
+
| [prefer-fragment-shorthand](docs/rules/prefer-fragment-shorthand.md) | Prefer <> shorthand for <React.Fragment> | ✅ | | 🔧 | |
|
|
109
|
+
| [prefer-settings-object](docs/rules/prefer-settings-object.md) | Enforce using a settings object for functions with multiple parameters | ✅ | | 🔧 | |
|
|
110
|
+
| [prefer-type-over-interface](docs/rules/prefer-type-over-interface.md) | Prefer using type alias over interface | ✅ | | 🔧 | |
|
|
111
|
+
| [require-dynamic-firebase-imports](docs/rules/require-dynamic-firebase-imports.md) | Enforce dynamic imports for Firebase dependencies | ✅ | | 🔧 | |
|
|
112
|
+
| [require-https-error](docs/rules/require-https-error.md) | Enforce using proprietary HttpsError instead of throw new Error or firebase-admin HttpsError in functions/src | ✅ | | | |
|
|
113
|
+
| [require-image-optimized](docs/rules/require-image-optimized.md) | Enforce using ImageOptimized component instead of next/image or img tags | ✅ | | 🔧 | |
|
|
114
|
+
| [require-memo](docs/rules/require-memo.md) | React components must be memoized | ✅ | | 🔧 | |
|
|
115
|
+
| [require-usememo-object-literals](docs/rules/require-usememo-object-literals.md) | Enforce using useMemo for inline object/array literals passed as props to JSX components to prevent unnecessary re-renders. When object/array literals are defined inline in JSX, they create new references on every render, causing child components to re-render even if the values haven't changed. Wrap them in useMemo to maintain referential equality. | ✅ | | | |
|
|
116
|
+
| [semantic-function-prefixes](docs/rules/semantic-function-prefixes.md) | Enforce semantic function prefixes over generic ones like "get" and "update" | ✅ | | | |
|
|
117
|
+
| [sync-onwrite-name-func](docs/rules/sync-onwrite-name-func.md) | Ensure that the name field matches the func field in onWrite handlers | ✅ | | 🔧 | |
|
|
118
|
+
| [use-custom-link](docs/rules/use-custom-link.md) | Enforce using src/components/Link instead of next/link | ✅ | | 🔧 | |
|
|
119
|
+
| [use-custom-memo](docs/rules/use-custom-memo.md) | Enforce using src/util/memo instead of React memo | ✅ | | 🔧 | |
|
|
120
|
+
| [use-custom-router](docs/rules/use-custom-router.md) | Enforce using src/hooks/routing/useRouter instead of next/router | ✅ | | 🔧 | |
|
|
98
121
|
|
|
99
122
|
<!-- end auto-generated rules list -->
|
package/lib/index.js
CHANGED
|
@@ -56,10 +56,22 @@ const no_firestore_object_arrays_1 = require("./rules/no-firestore-object-arrays
|
|
|
56
56
|
const no_memoize_on_static_1 = require("./rules/no-memoize-on-static");
|
|
57
57
|
const no_unsafe_firestore_spread_1 = require("./rules/no-unsafe-firestore-spread");
|
|
58
58
|
const no_jsx_in_hooks_1 = require("./rules/no-jsx-in-hooks");
|
|
59
|
+
const enforce_assert_throws_1 = require("./rules/enforce-assert-throws");
|
|
60
|
+
const prefer_batch_operations_1 = require("./rules/prefer-batch-operations");
|
|
61
|
+
const no_complex_cloud_params_1 = require("./rules/no-complex-cloud-params");
|
|
62
|
+
const no_mixed_firestore_transactions_1 = require("./rules/no-mixed-firestore-transactions");
|
|
63
|
+
const enforce_firestore_facade_1 = require("./rules/enforce-firestore-facade");
|
|
64
|
+
const sync_onwrite_name_func_1 = require("./rules/sync-onwrite-name-func");
|
|
65
|
+
const prefer_clone_deep_1 = require("./rules/prefer-clone-deep");
|
|
66
|
+
const no_firestore_jest_mock_1 = require("./rules/no-firestore-jest-mock");
|
|
67
|
+
const no_mock_firebase_admin_1 = require("./rules/no-mock-firebase-admin");
|
|
68
|
+
const enforce_centralized_mock_firestore_1 = require("./rules/enforce-centralized-mock-firestore");
|
|
69
|
+
const require_hooks_default_params_1 = require("./rules/require-hooks-default-params");
|
|
70
|
+
const prefer_destructuring_no_class_1 = require("./rules/prefer-destructuring-no-class");
|
|
59
71
|
module.exports = {
|
|
60
72
|
meta: {
|
|
61
73
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
62
|
-
version: '1.
|
|
74
|
+
version: '1.7.0',
|
|
63
75
|
},
|
|
64
76
|
parseOptions: {
|
|
65
77
|
ecmaVersion: 2020,
|
|
@@ -121,6 +133,18 @@ module.exports = {
|
|
|
121
133
|
'@blumintinc/blumint/no-memoize-on-static': 'error',
|
|
122
134
|
'@blumintinc/blumint/no-unsafe-firestore-spread': 'error',
|
|
123
135
|
'@blumintinc/blumint/no-jsx-in-hooks': 'error',
|
|
136
|
+
'@blumintinc/blumint/enforce-assert-throws': 'error',
|
|
137
|
+
'@blumintinc/blumint/prefer-batch-operations': 'error',
|
|
138
|
+
'@blumintinc/blumint/no-complex-cloud-params': 'error',
|
|
139
|
+
'@blumintinc/blumint/no-mixed-firestore-transactions': 'error',
|
|
140
|
+
'@blumintinc/blumint/enforce-firestore-facade': 'error',
|
|
141
|
+
'@blumintinc/blumint/sync-onwrite-name-func': 'error',
|
|
142
|
+
'@blumintinc/blumint/prefer-clone-deep': 'error',
|
|
143
|
+
'@blumintinc/blumint/no-firestore-jest-mock': 'error',
|
|
144
|
+
'@blumintinc/blumint/no-mock-firebase-admin': 'error',
|
|
145
|
+
'@blumintinc/blumint/enforce-centralized-mock-firestore': 'error',
|
|
146
|
+
'@blumintinc/blumint/require-hooks-default-params': 'error',
|
|
147
|
+
'@blumintinc/blumint/prefer-destructuring-no-class': 'error',
|
|
124
148
|
},
|
|
125
149
|
},
|
|
126
150
|
},
|
|
@@ -178,6 +202,18 @@ module.exports = {
|
|
|
178
202
|
'no-memoize-on-static': no_memoize_on_static_1.noMemoizeOnStatic,
|
|
179
203
|
'no-unsafe-firestore-spread': no_unsafe_firestore_spread_1.noUnsafeFirestoreSpread,
|
|
180
204
|
'no-jsx-in-hooks': no_jsx_in_hooks_1.noJsxInHooks,
|
|
205
|
+
'enforce-assert-throws': enforce_assert_throws_1.enforceAssertThrows,
|
|
206
|
+
'prefer-batch-operations': prefer_batch_operations_1.preferBatchOperations,
|
|
207
|
+
'no-complex-cloud-params': no_complex_cloud_params_1.noComplexCloudParams,
|
|
208
|
+
'no-mixed-firestore-transactions': no_mixed_firestore_transactions_1.noMixedFirestoreTransactions,
|
|
209
|
+
'enforce-firestore-facade': enforce_firestore_facade_1.enforceFirestoreFacade,
|
|
210
|
+
'sync-onwrite-name-func': sync_onwrite_name_func_1.syncOnwriteNameFunc,
|
|
211
|
+
'prefer-clone-deep': prefer_clone_deep_1.preferCloneDeep,
|
|
212
|
+
'no-firestore-jest-mock': no_firestore_jest_mock_1.noFirestoreJestMock,
|
|
213
|
+
'no-mock-firebase-admin': no_mock_firebase_admin_1.noMockFirebaseAdmin,
|
|
214
|
+
'enforce-centralized-mock-firestore': enforce_centralized_mock_firestore_1.enforceCentralizedMockFirestore,
|
|
215
|
+
'require-hooks-default-params': require_hooks_default_params_1.requireHooksDefaultParams,
|
|
216
|
+
'prefer-destructuring-no-class': prefer_destructuring_no_class_1.preferDestructuringNoClass,
|
|
181
217
|
},
|
|
182
218
|
};
|
|
183
219
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const enforceAssertThrows: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"assertShouldThrow", [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enforceAssertThrows = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule_1 = require("../utils/createRule");
|
|
6
|
+
exports.enforceAssertThrows = (0, createRule_1.createRule)({
|
|
7
|
+
name: 'enforce-assert-throws',
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'problem',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'Enforce that functions with assert- prefix must throw an error',
|
|
12
|
+
recommended: 'error',
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
assertShouldThrow: 'Functions with assert- prefix must throw an error. Either rename the function or add a throw statement.',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
function isAssertionCall(node) {
|
|
22
|
+
if (node.type === utils_1.AST_NODE_TYPES.ExpressionStatement) {
|
|
23
|
+
const expression = node.expression;
|
|
24
|
+
if (expression.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
25
|
+
const callee = expression.callee;
|
|
26
|
+
if (callee.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
27
|
+
return callee.name.toLowerCase().startsWith('assert');
|
|
28
|
+
}
|
|
29
|
+
if (callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
30
|
+
const property = callee.property;
|
|
31
|
+
if (property.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
32
|
+
return property.name.toLowerCase().startsWith('assert');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function hasThrowStatement(node) {
|
|
40
|
+
let hasThrow = false;
|
|
41
|
+
function walk(node) {
|
|
42
|
+
if (node.type === utils_1.AST_NODE_TYPES.ThrowStatement) {
|
|
43
|
+
hasThrow = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Check for assertion function calls
|
|
47
|
+
if (isAssertionCall(node)) {
|
|
48
|
+
hasThrow = true;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Don't check throw statements in nested functions
|
|
52
|
+
if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
|
|
53
|
+
node.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
54
|
+
node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
55
|
+
if (node !== currentFunction) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Don't count throws in catch blocks that are just re-throwing
|
|
60
|
+
if (node.type === utils_1.AST_NODE_TYPES.CatchClause) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Handle BlockStatement specially
|
|
64
|
+
if (node.type === utils_1.AST_NODE_TYPES.BlockStatement) {
|
|
65
|
+
node.body.forEach(stmt => walk(stmt));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// Handle IfStatement specially
|
|
69
|
+
if (node.type === utils_1.AST_NODE_TYPES.IfStatement) {
|
|
70
|
+
walk(node.consequent);
|
|
71
|
+
if (node.alternate) {
|
|
72
|
+
walk(node.alternate);
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Handle other node types
|
|
77
|
+
for (const key of Object.keys(node)) {
|
|
78
|
+
const value = node[key];
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
value.forEach(item => {
|
|
81
|
+
if (item && typeof item === 'object' && !('parent' in item)) {
|
|
82
|
+
walk(item);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else if (value && typeof value === 'object' && !('parent' in value)) {
|
|
87
|
+
walk(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
walk(node);
|
|
92
|
+
return hasThrow;
|
|
93
|
+
}
|
|
94
|
+
let currentFunction = null;
|
|
95
|
+
function checkFunction(node) {
|
|
96
|
+
let functionName = '';
|
|
97
|
+
if (node.type === utils_1.AST_NODE_TYPES.MethodDefinition) {
|
|
98
|
+
functionName = node.key.type === utils_1.AST_NODE_TYPES.Identifier ? node.key.name : '';
|
|
99
|
+
}
|
|
100
|
+
else if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
101
|
+
functionName = node.id.name;
|
|
102
|
+
}
|
|
103
|
+
else if (node.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
104
|
+
node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
105
|
+
const parent = node.parent;
|
|
106
|
+
if (parent &&
|
|
107
|
+
parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
108
|
+
parent.id.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
109
|
+
functionName = parent.id.name;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (functionName.toLowerCase().startsWith('assert')) {
|
|
113
|
+
currentFunction = node;
|
|
114
|
+
const functionBody = node.type === utils_1.AST_NODE_TYPES.MethodDefinition ? node.value.body : node.body;
|
|
115
|
+
if (functionBody && !hasThrowStatement(functionBody)) {
|
|
116
|
+
context.report({
|
|
117
|
+
node,
|
|
118
|
+
messageId: 'assertShouldThrow',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
currentFunction = null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
FunctionDeclaration: checkFunction,
|
|
126
|
+
FunctionExpression: checkFunction,
|
|
127
|
+
ArrowFunctionExpression: checkFunction,
|
|
128
|
+
MethodDefinition: checkFunction,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=enforce-assert-throws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const enforceCentralizedMockFirestore: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useCentralizedMockFirestore", [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enforceCentralizedMockFirestore = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule_1 = require("../utils/createRule");
|
|
6
|
+
const MOCK_FIRESTORE_PATH = '../../../../../__mocks__/functions/src/config/mockFirestore';
|
|
7
|
+
exports.enforceCentralizedMockFirestore = (0, createRule_1.createRule)({
|
|
8
|
+
name: 'enforce-centralized-mock-firestore',
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'problem',
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Enforce usage of centralized mockFirestore from predefined location',
|
|
13
|
+
recommended: 'error',
|
|
14
|
+
},
|
|
15
|
+
fixable: 'code',
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: {
|
|
18
|
+
useCentralizedMockFirestore: 'Use the centralized mockFirestore from the predefined location instead of creating a new mock',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context) {
|
|
23
|
+
let hasCentralizedImport = false;
|
|
24
|
+
let mockFirestoreNodes = [];
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
if (node.source.value.endsWith(MOCK_FIRESTORE_PATH)) {
|
|
28
|
+
hasCentralizedImport = true;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
VariableDeclarator(node) {
|
|
32
|
+
if (node.id.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
33
|
+
node.id.name === 'mockFirestore') {
|
|
34
|
+
mockFirestoreNodes.push(node);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
'Program:exit'() {
|
|
38
|
+
if (!hasCentralizedImport && mockFirestoreNodes.length > 0) {
|
|
39
|
+
for (const node of mockFirestoreNodes) {
|
|
40
|
+
context.report({
|
|
41
|
+
node,
|
|
42
|
+
messageId: 'useCentralizedMockFirestore',
|
|
43
|
+
fix(fixer) {
|
|
44
|
+
const importFix = fixer.insertTextBefore(context.getSourceCode().ast.body[0], `import { mockFirestore } from '${MOCK_FIRESTORE_PATH}';\n\n`);
|
|
45
|
+
const declarationFix = fixer.remove(node.parent);
|
|
46
|
+
return [importFix, declarationFix];
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=enforce-centralized-mock-firestore.js.map
|
|
@@ -45,9 +45,10 @@ exports.enforceExportedFunctionTypes = (0, createRule_1.createRule)({
|
|
|
45
45
|
const typeParams = new Set();
|
|
46
46
|
let current = node;
|
|
47
47
|
while (current) {
|
|
48
|
-
// Handle type parameters in function declarations
|
|
48
|
+
// Handle type parameters in function declarations, arrow functions, and variable declarations
|
|
49
49
|
if (current.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
50
|
-
current.type === utils_1.AST_NODE_TYPES.FunctionDeclaration
|
|
50
|
+
current.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
|
|
51
|
+
current.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
|
|
51
52
|
if ('typeParameters' in current && current.typeParameters) {
|
|
52
53
|
current.typeParameters.params.forEach((param) => {
|
|
53
54
|
if (param.type === utils_1.AST_NODE_TYPES.TSTypeParameter) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
type MessageIds = 'noDirectGet' | 'noDirectSet' | 'noDirectUpdate' | 'noDirectDelete';
|
|
2
|
+
export declare const enforceFirestoreFacade: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<MessageIds, [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
|
|
3
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enforceFirestoreFacade = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const createRule_1 = require("../utils/createRule");
|
|
6
|
+
const FIRESTORE_METHODS = new Set(['get', 'set', 'update', 'delete']);
|
|
7
|
+
const isMemberExpression = (node) => {
|
|
8
|
+
return node.type === utils_1.AST_NODE_TYPES.MemberExpression;
|
|
9
|
+
};
|
|
10
|
+
const isFirestoreMethodCall = (node) => {
|
|
11
|
+
if (!isMemberExpression(node.callee))
|
|
12
|
+
return false;
|
|
13
|
+
const property = node.callee.property;
|
|
14
|
+
if (!isIdentifier(property) || !FIRESTORE_METHODS.has(property.name)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// Check if the method is called on a facade instance
|
|
18
|
+
const object = node.callee.object;
|
|
19
|
+
if (isIdentifier(object)) {
|
|
20
|
+
const name = object.name;
|
|
21
|
+
// Skip if it's a facade instance
|
|
22
|
+
if (name.includes('Fetcher') || name.includes('Setter') || name.includes('Tx')) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// Check for batch or transaction
|
|
26
|
+
if (/batch|transaction/i.test(name)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Check if it's a Firestore reference
|
|
31
|
+
let current = object;
|
|
32
|
+
let foundDocOrCollection = false;
|
|
33
|
+
while (current) {
|
|
34
|
+
if (isCallExpression(current)) {
|
|
35
|
+
const callee = current.callee;
|
|
36
|
+
if (isMemberExpression(callee)) {
|
|
37
|
+
const property = callee.property;
|
|
38
|
+
if (isIdentifier(property) && (property.name === 'doc' || property.name === 'collection')) {
|
|
39
|
+
foundDocOrCollection = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (isMemberExpression(current)) {
|
|
45
|
+
current = current.object;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// If we haven't found a doc/collection call yet, check if the object is a variable
|
|
52
|
+
if (!foundDocOrCollection && isIdentifier(object)) {
|
|
53
|
+
const name = object.name;
|
|
54
|
+
// If the variable name contains 'doc' or 'ref', it's likely a Firestore reference
|
|
55
|
+
if (name.toLowerCase().includes('doc') || name.toLowerCase().includes('ref')) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return foundDocOrCollection;
|
|
60
|
+
};
|
|
61
|
+
const isCallExpression = (node) => {
|
|
62
|
+
return node.type === utils_1.AST_NODE_TYPES.CallExpression;
|
|
63
|
+
};
|
|
64
|
+
const isIdentifier = (node) => {
|
|
65
|
+
return node.type === utils_1.AST_NODE_TYPES.Identifier;
|
|
66
|
+
};
|
|
67
|
+
exports.enforceFirestoreFacade = (0, createRule_1.createRule)({
|
|
68
|
+
name: 'enforce-firestore-facade',
|
|
69
|
+
meta: {
|
|
70
|
+
type: 'problem',
|
|
71
|
+
docs: {
|
|
72
|
+
description: 'Enforce usage of Firestore facades instead of direct Firestore methods',
|
|
73
|
+
recommended: 'error',
|
|
74
|
+
},
|
|
75
|
+
schema: [],
|
|
76
|
+
messages: {
|
|
77
|
+
noDirectGet: 'Use FirestoreFetcher or FirestoreDocFetcher instead of direct .get() calls',
|
|
78
|
+
noDirectSet: 'Use DocSetter or DocSetterTransaction instead of direct .set() calls',
|
|
79
|
+
noDirectUpdate: 'Use DocSetter or DocSetterTransaction instead of direct .update() calls',
|
|
80
|
+
noDirectDelete: 'Use DocSetter or DocSetterTransaction instead of direct .delete() calls',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
defaultOptions: [],
|
|
84
|
+
create(context) {
|
|
85
|
+
return {
|
|
86
|
+
CallExpression(node) {
|
|
87
|
+
if (!isFirestoreMethodCall(node))
|
|
88
|
+
return;
|
|
89
|
+
const callee = node.callee;
|
|
90
|
+
if (!isMemberExpression(callee))
|
|
91
|
+
return;
|
|
92
|
+
const property = callee.property;
|
|
93
|
+
if (!isIdentifier(property))
|
|
94
|
+
return;
|
|
95
|
+
// Report appropriate error based on method
|
|
96
|
+
switch (property.name) {
|
|
97
|
+
case 'get':
|
|
98
|
+
context.report({
|
|
99
|
+
node,
|
|
100
|
+
messageId: 'noDirectGet',
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
case 'set':
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
messageId: 'noDirectSet',
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
case 'update':
|
|
110
|
+
context.report({
|
|
111
|
+
node,
|
|
112
|
+
messageId: 'noDirectUpdate',
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
case 'delete':
|
|
116
|
+
context.report({
|
|
117
|
+
node,
|
|
118
|
+
messageId: 'noDirectDelete',
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=enforce-firestore-facade.js.map
|