@blumintinc/eslint-plugin-blumint 1.11.0 → 1.11.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 CHANGED
@@ -15,6 +15,7 @@ const enforce_mui_rounded_icons_1 = require("./rules/enforce-mui-rounded-icons")
15
15
  const enforce_react_type_naming_1 = require("./rules/enforce-react-type-naming");
16
16
  const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
17
17
  const extract_global_constants_1 = require("./rules/extract-global-constants");
18
+ const enforce_global_constants_1 = require("./rules/enforce-global-constants");
18
19
  const generic_starts_with_t_1 = require("./rules/generic-starts-with-t");
19
20
  const global_const_style_1 = __importDefault(require("./rules/global-const-style"));
20
21
  const no_async_array_filter_1 = require("./rules/no-async-array-filter");
@@ -105,7 +106,7 @@ const enforce_boolean_naming_prefixes_1 = require("./rules/enforce-boolean-namin
105
106
  module.exports = {
106
107
  meta: {
107
108
  name: '@blumintinc/eslint-plugin-blumint',
108
- version: '1.11.0',
109
+ version: '1.11.1',
109
110
  },
110
111
  parseOptions: {
111
112
  ecmaVersion: 2020,
@@ -130,6 +131,7 @@ module.exports = {
130
131
  '@blumintinc/blumint/enforce-react-type-naming': 'error',
131
132
  // '@blumintinc/blumint/export-if-in-doubt': 'warn',
132
133
  '@blumintinc/blumint/extract-global-constants': 'error',
134
+ '@blumintinc/blumint/enforce-global-constants': 'error',
133
135
  '@blumintinc/blumint/generic-starts-with-t': 'error',
134
136
  '@blumintinc/blumint/global-const-style': 'error',
135
137
  '@blumintinc/blumint/no-async-array-filter': 'error',
@@ -236,6 +238,7 @@ module.exports = {
236
238
  'enforce-mui-rounded-icons': enforce_mui_rounded_icons_1.enforceMuiRoundedIcons,
237
239
  'export-if-in-doubt': export_if_in_doubt_1.exportIfInDoubt,
238
240
  'extract-global-constants': extract_global_constants_1.extractGlobalConstants,
241
+ 'enforce-global-constants': enforce_global_constants_1.enforceGlobalConstants,
239
242
  'generic-starts-with-t': generic_starts_with_t_1.genericStartsWithT,
240
243
  'global-const-style': global_const_style_1.default,
241
244
  'no-async-array-filter': no_async_array_filter_1.noAsyncArrayFilter,
@@ -0,0 +1 @@
1
+ export declare const enforceGlobalConstants: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"useGlobalConstant", [], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceGlobalConstants = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const createRule_1 = require("../utils/createRule");
6
+ exports.enforceGlobalConstants = (0, createRule_1.createRule)({
7
+ name: 'enforce-global-constants',
8
+ meta: {
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Enforce using global static constants instead of useMemo with empty dependency arrays for object literals',
12
+ recommended: 'error',
13
+ },
14
+ schema: [],
15
+ messages: {
16
+ useGlobalConstant: 'Use a global static constant instead of useMemo with an empty dependency array for object literals',
17
+ },
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ return {
22
+ CallExpression(node) {
23
+ // Check if it's a useMemo call
24
+ if (node.callee.type !== utils_1.AST_NODE_TYPES.Identifier ||
25
+ node.callee.name !== 'useMemo') {
26
+ return;
27
+ }
28
+ // Check if it has exactly two arguments
29
+ if (node.arguments.length !== 2) {
30
+ return;
31
+ }
32
+ // Check if the second argument is an empty array
33
+ const depsArray = node.arguments[1];
34
+ if (depsArray.type !== utils_1.AST_NODE_TYPES.ArrayExpression ||
35
+ depsArray.elements.length !== 0) {
36
+ return;
37
+ }
38
+ // Check if the first argument is an arrow function
39
+ const callback = node.arguments[0];
40
+ if (callback.type !== utils_1.AST_NODE_TYPES.ArrowFunctionExpression) {
41
+ return;
42
+ }
43
+ // Check if the arrow function body is a block statement with a return statement
44
+ // or a direct expression (implicit return)
45
+ let returnValue = null;
46
+ if (callback.body.type === utils_1.AST_NODE_TYPES.BlockStatement) {
47
+ // If it's a block, find the return statement
48
+ const returnStatement = callback.body.body.find((stmt) => stmt.type === utils_1.AST_NODE_TYPES.ReturnStatement);
49
+ if (!returnStatement || !returnStatement.argument) {
50
+ return;
51
+ }
52
+ returnValue = returnStatement.argument;
53
+ }
54
+ else {
55
+ // If it's an expression (implicit return)
56
+ returnValue = callback.body;
57
+ }
58
+ // Handle 'as const' type assertions
59
+ let actualReturnValue = returnValue;
60
+ if (returnValue.type === utils_1.AST_NODE_TYPES.TSAsExpression) {
61
+ actualReturnValue = returnValue.expression;
62
+ }
63
+ // Check if the return value is an object literal or an array of object literals
64
+ if (actualReturnValue.type === utils_1.AST_NODE_TYPES.ObjectExpression ||
65
+ (actualReturnValue.type === utils_1.AST_NODE_TYPES.ArrayExpression &&
66
+ actualReturnValue.elements.some((element) => element !== null &&
67
+ element.type === utils_1.AST_NODE_TYPES.ObjectExpression))) {
68
+ context.report({
69
+ node,
70
+ messageId: 'useGlobalConstant',
71
+ });
72
+ }
73
+ },
74
+ };
75
+ },
76
+ });
77
+ //# sourceMappingURL=enforce-global-constants.js.map
@@ -31,7 +31,7 @@ const TYPE_MARKERS = [
31
31
  ...COMMON_TYPES,
32
32
  'Class',
33
33
  'Interface',
34
- 'Type',
34
+ //'Type', people like to use 'type' as a general purpose noun
35
35
  'Enum',
36
36
  ];
37
37
  // Allowed descriptive suffixes that should not be flagged as Hungarian notation
@@ -168,9 +168,21 @@ exports.noTypeAssertionReturns = (0, createRule_1.createRule)({
168
168
  return true;
169
169
  }
170
170
  // Allow type assertions as arguments to constructors
171
- if (node.parent?.type === utils_1.AST_NODE_TYPES.NewExpression) {
171
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.NewExpression ||
172
+ (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
173
+ node.parent.parent?.type === utils_1.AST_NODE_TYPES.NewExpression)) {
172
174
  return true;
173
175
  }
176
+ // Allow type assertions as arguments to constructor calls
177
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
178
+ let current = node.parent;
179
+ while (current?.parent) {
180
+ if (current.parent.type === utils_1.AST_NODE_TYPES.NewExpression) {
181
+ return true;
182
+ }
183
+ current = current.parent;
184
+ }
185
+ }
174
186
  // Allow type assertions in JSX attributes/props or object properties
175
187
  if (isInsideJSXAttributeOrObjectProperty(node)) {
176
188
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "Custom eslint rules for use within BluMint",
5
5
  "author": {
6
6
  "name": "Brodie McGuire",