@agilebot/eslint-plugin 0.8.0 → 0.8.2

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/dist/index.js CHANGED
@@ -1,17 +1,18 @@
1
- /**
2
- * @license @agilebot/eslint-plugin v0.8.0
3
- *
4
- * Copyright (c) Agilebot, Inc. and its affiliates.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
1
+ /**
2
+ * @license @agilebot/eslint-plugin v0.8.2
3
+ *
4
+ * Copyright (c) Agilebot, Inc. and its affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
9
  'use strict';
10
10
 
11
11
  var utils = require('@typescript-eslint/utils');
12
12
  var fs = require('node:fs');
13
13
  var path = require('node:path');
14
14
  var eslintUtils = require('@agilebot/eslint-utils');
15
+ var Components = require('eslint-plugin-react/lib/util/Components.js');
15
16
 
16
17
  function _interopNamespaceDefault(e) {
17
18
  var n = Object.create(null);
@@ -32,15 +33,16 @@ function _interopNamespaceDefault(e) {
32
33
 
33
34
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
34
35
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
36
+ var Components__namespace = /*#__PURE__*/_interopNamespaceDefault(Components);
35
37
 
36
38
  const docBaseUrl = 'https://github.com/sh-agilebot/frontend-toolkit/blob/master/packages/eslint-plugin/src/rules/';
37
39
  const hasDocs = typeof ["enforce-mui-icon-alias","intl-id-missing","intl-id-prefix","intl-no-default","react-better-exhaustive-deps"] !== 'undefined' ?
38
40
  ["enforce-mui-icon-alias","intl-id-missing","intl-id-prefix","intl-no-default","react-better-exhaustive-deps"] : [];
39
41
  const createRule = utils.ESLintUtils.RuleCreator(name => hasDocs.includes(name) ? "".concat(docBaseUrl).concat(name, ".md") : "".concat(docBaseUrl).concat(name, ".test.js"));
40
42
 
41
- const RULE_NAME$j = 'enforce-mui-icon-alias';
43
+ const RULE_NAME$h = 'enforce-mui-icon-alias';
42
44
  var enforceMuiIconAlias = createRule({
43
- name: RULE_NAME$j,
45
+ name: RULE_NAME$h,
44
46
  meta: {
45
47
  type: 'problem',
46
48
  docs: {
@@ -61,7 +63,7 @@ var enforceMuiIconAlias = createRule({
61
63
  return;
62
64
  }
63
65
  for (const specifier of node.specifiers) {
64
- if (specifier.type !== 'ImportSpecifier') {
66
+ if (specifier.type !== utils.AST_NODE_TYPES.ImportSpecifier) {
65
67
  return;
66
68
  }
67
69
  if (specifier.imported.name === specifier.local.name || !specifier.local.name.endsWith('Icon')) {
@@ -84,9 +86,9 @@ function getSetting(context, name) {
84
86
  return context.settings["agilebot/".concat(name)];
85
87
  }
86
88
 
87
- const RULE_NAME$i = 'import-monorepo';
89
+ const RULE_NAME$g = 'import-monorepo';
88
90
  var importMonorepo = createRule({
89
- name: RULE_NAME$i,
91
+ name: RULE_NAME$g,
90
92
  meta: {
91
93
  type: 'problem',
92
94
  docs: {
@@ -134,25 +136,25 @@ var importMonorepo = createRule({
134
136
  });
135
137
 
136
138
  function findFormatMessageAttrNode(node, attrName) {
137
- if (node.type === 'CallExpression' && (node.callee.name === 'formatMessage' || node.callee.name === '$t') && node.arguments.length > 0 && node.arguments[0].properties) {
139
+ if (node.type === utils.AST_NODE_TYPES.CallExpression && (node.callee.name === 'formatMessage' || node.callee.name === '$t') && node.arguments.length > 0 && node.arguments[0].properties) {
138
140
  return node.arguments[0].properties.find(a => a.key && a.key.name === attrName);
139
141
  }
140
- if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && (node.callee.object.name === 'intl' || node.callee.object.name && node.callee.object.name.endsWith('Intl')) && (node.callee.property.name === 'formatMessage' || node.callee.property.name === '$t')) {
142
+ if (node.type === utils.AST_NODE_TYPES.CallExpression && node.callee.type === utils.AST_NODE_TYPES.MemberExpression && (node.callee.object.name === 'intl' || node.callee.object.name && node.callee.object.name.endsWith('Intl')) && (node.callee.property.name === 'formatMessage' || node.callee.property.name === '$t')) {
141
143
  return node.arguments[0].properties.find(a => a.key && a.key.name === attrName);
142
144
  }
143
145
  }
144
146
  function findFormattedMessageAttrNode(node, attrName) {
145
- if (node.type === 'JSXIdentifier' && node.name === 'FormattedMessage' && node.parent && node.parent.type === 'JSXOpeningElement') {
147
+ if (node.type === utils.AST_NODE_TYPES.JSXIdentifier && node.name === 'FormattedMessage' && node.parent && node.parent.type === utils.AST_NODE_TYPES.JSXOpeningElement) {
146
148
  return node.parent.attributes.find(a => a.name && a.name.name === attrName);
147
149
  }
148
150
  }
149
151
  function findAttrNodeInDefineMessages(node, attrName) {
150
- if (node.type === 'Property' && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.parent && node.parent.parent.parent.parent.type === 'CallExpression' && node.parent.parent.parent.parent.callee.name === 'defineMessages') {
152
+ if (node.type === 'Property' && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.parent && node.parent.parent.parent.parent.type === utils.AST_NODE_TYPES.CallExpression && node.parent.parent.parent.parent.callee.name === 'defineMessages') {
151
153
  return node;
152
154
  }
153
155
  }
154
156
  function findAttrNodeInDefineMessage(node, attrName) {
155
- if (node.type === 'Property' && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.type === 'CallExpression' && node.parent.parent.callee.name === 'defineMessage') {
157
+ if (node.type === 'Property' && node.key.name === attrName && node.parent && node.parent.parent && node.parent.parent.type === utils.AST_NODE_TYPES.CallExpression && node.parent.parent.callee.name === 'defineMessage') {
156
158
  return node;
157
159
  }
158
160
  }
@@ -201,9 +203,9 @@ function getIntlIds(context) {
201
203
  return results;
202
204
  }
203
205
 
204
- const RULE_NAME$h = 'intl-id-missing';
206
+ const RULE_NAME$f = 'intl-id-missing';
205
207
  var intlIdMissing = createRule({
206
- name: RULE_NAME$h,
208
+ name: RULE_NAME$f,
207
209
  meta: {
208
210
  type: 'problem',
209
211
  docs: {
@@ -251,13 +253,13 @@ var intlIdMissing = createRule({
251
253
  }
252
254
  }
253
255
  function processAttrNode(node) {
254
- if (node.value.type === 'Literal') {
256
+ if (node.value.type === utils.AST_NODE_TYPES.Literal) {
255
257
  return processLiteral(node.value);
256
258
  }
257
- if (node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'TemplateLiteral') {
259
+ if (node.value.type === utils.AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === utils.AST_NODE_TYPES.TemplateLiteral) {
258
260
  return processTemplateLiteral(node.value.expression);
259
261
  }
260
- if (node.value.type === 'TemplateLiteral') {
262
+ if (node.value.type === utils.AST_NODE_TYPES.TemplateLiteral) {
261
263
  return processTemplateLiteral(node.value);
262
264
  }
263
265
  context.report({
@@ -291,9 +293,9 @@ var intlIdMissing = createRule({
291
293
  }
292
294
  });
293
295
 
294
- const RULE_NAME$g = 'intl-id-naming';
296
+ const RULE_NAME$e = 'intl-id-naming';
295
297
  var intlIdNaming = createRule({
296
- name: RULE_NAME$g,
298
+ name: RULE_NAME$e,
297
299
  meta: {
298
300
  type: 'problem',
299
301
  docs: {
@@ -353,13 +355,13 @@ var intlIdNaming = createRule({
353
355
  report(node, displayStr);
354
356
  }
355
357
  function processAttrNode(node) {
356
- if (node.value.type === 'Literal') {
358
+ if (node.value.type === utils.AST_NODE_TYPES.Literal) {
357
359
  return processLiteral(node.value);
358
360
  }
359
- if (node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'TemplateLiteral') {
361
+ if (node.value.type === utils.AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === utils.AST_NODE_TYPES.TemplateLiteral) {
360
362
  return processTemplateLiteral(node.value.expression);
361
363
  }
362
- if (node.value.type === 'TemplateLiteral') {
364
+ if (node.value.type === utils.AST_NODE_TYPES.TemplateLiteral) {
363
365
  return processTemplateLiteral(node.value);
364
366
  }
365
367
  }
@@ -386,9 +388,9 @@ var intlIdNaming = createRule({
386
388
  }
387
389
  });
388
390
 
389
- const RULE_NAME$f = 'intl-id-prefix';
391
+ const RULE_NAME$d = 'intl-id-prefix';
390
392
  var intlIdPrefix = createRule({
391
- name: RULE_NAME$f,
393
+ name: RULE_NAME$d,
392
394
  meta: {
393
395
  type: 'problem',
394
396
  docs: {
@@ -429,13 +431,13 @@ var intlIdPrefix = createRule({
429
431
  report(node, displayStr);
430
432
  }
431
433
  function processAttrNode(node) {
432
- if (node.value.type === 'Literal') {
434
+ if (node.value.type === utils.AST_NODE_TYPES.Literal) {
433
435
  return processLiteral(node.value);
434
436
  }
435
- if (node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'TemplateLiteral') {
437
+ if (node.value.type === utils.AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === utils.AST_NODE_TYPES.TemplateLiteral) {
436
438
  return processTemplateLiteral(node.value.expression);
437
439
  }
438
- if (node.value.type === 'TemplateLiteral') {
440
+ if (node.value.type === utils.AST_NODE_TYPES.TemplateLiteral) {
439
441
  return processTemplateLiteral(node.value);
440
442
  }
441
443
  }
@@ -462,10 +464,10 @@ var intlIdPrefix = createRule({
462
464
  }
463
465
  });
464
466
 
465
- const RULE_NAME$e = 'intl-id-unused';
467
+ const RULE_NAME$c = 'intl-id-unused';
466
468
  const usedIds = new Map();
467
469
  var intlIdUnused = createRule({
468
- name: RULE_NAME$e,
470
+ name: RULE_NAME$c,
469
471
  meta: {
470
472
  type: 'problem',
471
473
  docs: {
@@ -503,13 +505,13 @@ var intlIdUnused = createRule({
503
505
  if (isTemplateTranslated(re)) ;
504
506
  }
505
507
  function processAttrNode(node) {
506
- if (node.value.type === 'Literal') {
508
+ if (node.value.type === utils.AST_NODE_TYPES.Literal) {
507
509
  return processLiteral(node.value);
508
510
  }
509
- if (node.value.type === 'JSXExpressionContainer' && node.value.expression.type === 'TemplateLiteral') {
511
+ if (node.value.type === utils.AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === utils.AST_NODE_TYPES.TemplateLiteral) {
510
512
  return processTemplateLiteral(node.value.expression);
511
513
  }
512
- if (node.value.type === 'TemplateLiteral') {
514
+ if (node.value.type === utils.AST_NODE_TYPES.TemplateLiteral) {
513
515
  return processTemplateLiteral(node.value);
514
516
  }
515
517
  }
@@ -541,9 +543,9 @@ var intlIdUnused = createRule({
541
543
  }
542
544
  });
543
545
 
544
- const RULE_NAME$d = 'intl-no-default';
546
+ const RULE_NAME$b = 'intl-no-default';
545
547
  var intlNoDefault = createRule({
546
- name: RULE_NAME$d,
548
+ name: RULE_NAME$b,
547
549
  meta: {
548
550
  type: 'problem',
549
551
  docs: {
@@ -585,9 +587,9 @@ var intlNoDefault = createRule({
585
587
  }
586
588
  });
587
589
 
588
- const RULE_NAME$c = 'no-async-array-methods';
590
+ const RULE_NAME$a = 'no-async-array-methods';
589
591
  var noAsyncArrayMethods = createRule({
590
- name: RULE_NAME$c,
592
+ name: RULE_NAME$a,
591
593
  meta: {
592
594
  type: 'problem',
593
595
  docs: {
@@ -612,7 +614,7 @@ var noAsyncArrayMethods = createRule({
612
614
  }
613
615
  if (notAllowedArrayMethods.includes(callee.property.name)) {
614
616
  const functionArguments = node.expression.arguments.find(n => {
615
- return ['ArrowFunctionExpression', 'FunctionExpression'].includes(n.type);
617
+ return [utils.AST_NODE_TYPES.ArrowFunctionExpression, utils.AST_NODE_TYPES.FunctionExpression].includes(n.type);
616
618
  });
617
619
  if (functionArguments && functionArguments.async) {
618
620
  context.report({
@@ -629,9 +631,9 @@ var noAsyncArrayMethods = createRule({
629
631
  }
630
632
  });
631
633
 
632
- const RULE_NAME$b = 'no-extends-error';
634
+ const RULE_NAME$9 = 'no-extends-error';
633
635
  var noExtendsError = createRule({
634
- name: RULE_NAME$b,
636
+ name: RULE_NAME$9,
635
637
  meta: {
636
638
  type: 'problem',
637
639
  docs: {
@@ -647,7 +649,7 @@ var noExtendsError = createRule({
647
649
  create(context) {
648
650
  return {
649
651
  ClassDeclaration(node) {
650
- if (node.superClass && node.superClass.type === 'Identifier' && node.superClass.name === 'Error') {
652
+ if (node.superClass && node.superClass.type === utils.AST_NODE_TYPES.Identifier && node.superClass.name === 'Error') {
651
653
  context.report({
652
654
  node: node.superClass,
653
655
  messageId: 'noExtendsError'
@@ -658,9 +660,9 @@ var noExtendsError = createRule({
658
660
  }
659
661
  });
660
662
 
661
- const RULE_NAME$a = 'no-import-css';
663
+ const RULE_NAME$8 = 'no-import-css';
662
664
  var noImportCss = createRule({
663
- name: RULE_NAME$a,
665
+ name: RULE_NAME$8,
664
666
  meta: {
665
667
  type: 'problem',
666
668
  docs: {
@@ -691,9 +693,9 @@ var noImportCss = createRule({
691
693
  }
692
694
  });
693
695
 
694
- const RULE_NAME$9 = 'no-then-catch-finally';
696
+ const RULE_NAME$7 = 'no-then-catch-finally';
695
697
  var noThenCatchFinally = createRule({
696
- name: RULE_NAME$9,
698
+ name: RULE_NAME$7,
697
699
  meta: {
698
700
  type: 'suggestion',
699
701
  docs: {
@@ -731,7 +733,7 @@ var noThenCatchFinally = createRule({
731
733
  return node.property && (node.property.name === 'then' || node.property.name === 'catch' || node.property.name === 'finally');
732
734
  }
733
735
  return {
734
- 'CallExpression > MemberExpression.callee'(node) {
736
+ ["".concat(utils.AST_NODE_TYPES.CallExpression, " > ").concat(utils.AST_NODE_TYPES.MemberExpression, ".callee")]: node => {
735
737
  if (isTopLevelScoped(node)) {
736
738
  return;
737
739
  }
@@ -739,7 +741,7 @@ var noThenCatchFinally = createRule({
739
741
  return;
740
742
  }
741
743
  const callExpression = node.object;
742
- if (callExpression.type === 'CallExpression' && callExpression.callee.type === 'Identifier' && restrictedFunctions.includes(callExpression.callee.name)) {
744
+ if (callExpression.type === utils.AST_NODE_TYPES.CallExpression && callExpression.callee.type === utils.AST_NODE_TYPES.Identifier && restrictedFunctions.includes(callExpression.callee.name)) {
743
745
  context.report({
744
746
  node: node.property,
745
747
  messageId: 'forbiddenThenCatchFinally',
@@ -753,9 +755,9 @@ var noThenCatchFinally = createRule({
753
755
  }
754
756
  });
755
757
 
756
- const RULE_NAME$8 = 'no-unnecessary-template-literals';
758
+ const RULE_NAME$6 = 'no-unnecessary-template-literals';
757
759
  var noUnnecessaryTemplateLiterals = createRule({
758
- name: RULE_NAME$8,
760
+ name: RULE_NAME$6,
759
761
  meta: {
760
762
  type: 'problem',
761
763
  docs: {
@@ -2054,10 +2056,9 @@ function isUseEffectEventIdentifier(node) {
2054
2056
  return false;
2055
2057
  }
2056
2058
 
2057
- const Components = require('eslint-plugin-react/lib/util/Components');
2058
- const RULE_NAME$7 = 'react-hook-use-ref';
2059
+ const RULE_NAME$5 = 'react-hook-use-ref';
2059
2060
  var reactHookUseRef = createRule({
2060
- name: RULE_NAME$7,
2061
+ name: RULE_NAME$5,
2061
2062
  meta: {
2062
2063
  type: 'suggestion',
2063
2064
  docs: {
@@ -2071,13 +2072,13 @@ var reactHookUseRef = createRule({
2071
2072
  }
2072
2073
  },
2073
2074
  defaultOptions: [],
2074
- create: Components.detect((context, component, util) => ({
2075
+ create: Components__namespace["default"].detect((context, component, util) => ({
2075
2076
  CallExpression(node) {
2076
- const isImmediateReturn = node.parent && node.parent.type === 'ReturnStatement';
2077
+ const isImmediateReturn = node.parent && node.parent.type === utils.AST_NODE_TYPES.ReturnStatement;
2077
2078
  if (isImmediateReturn || !util.isReactHookCall(node, ['useRef'])) {
2078
2079
  return;
2079
2080
  }
2080
- if (node.parent.id.type !== 'Identifier') {
2081
+ if (node.parent.id.type !== utils.AST_NODE_TYPES.Identifier) {
2081
2082
  return;
2082
2083
  }
2083
2084
  const variable = node.parent.id.name;
@@ -2091,94 +2092,9 @@ var reactHookUseRef = createRule({
2091
2092
  }))
2092
2093
  });
2093
2094
 
2094
- const RULE_NAME$6 = 'react-prefer-named-property-access';
2095
- function* updateImportStatement(context, fixer, key) {
2096
- const sourceCode = context.sourceCode;
2097
- const importNode = sourceCode.ast.body.find(node => node.type === 'ImportDeclaration' && node.source.value === 'react');
2098
- if (!importNode) {
2099
- yield fixer.insertTextBefore(sourceCode.ast.body[0], "import { ".concat(key, " } from 'react';\n"));
2100
- return;
2101
- }
2102
- if (importNode.specifiers.length === 1 && importNode.specifiers[0].type === 'ImportDefaultSpecifier') {
2103
- yield fixer.insertTextAfter(importNode.specifiers[0], ", { ".concat(key, " }"));
2104
- return;
2105
- }
2106
- const alreadyImportedKeys = importNode.specifiers.filter(specifier => specifier.type === 'ImportSpecifier').map(specifier => specifier.imported.name);
2107
- if (alreadyImportedKeys.includes(key)) {
2108
- return;
2109
- }
2110
- yield fixer.insertTextAfter([...importNode.specifiers].pop(), ", ".concat(key));
2111
- }
2112
- var reactPreferNamedPropertyAccess = createRule({
2113
- name: RULE_NAME$6,
2114
- meta: {
2115
- type: 'problem',
2116
- fixable: 'code',
2117
- docs: {
2118
- description: 'Enforce importing each member of React namespace separately instead of accessing them through React namespace',
2119
- recommended: 'recommended'
2120
- },
2121
- messages: {
2122
- illegalReactPropertyAccess: 'Illegal React property access: {{name}}. Use named import instead.',
2123
- disallowImportReactEvent: 'Disallow importing React event types to avoid conflicts with global event types.'
2124
- },
2125
- schema: []
2126
- },
2127
- defaultOptions: [],
2128
- create(context) {
2129
- return {
2130
- TSQualifiedName(node) {
2131
- if ('name' in node.left && node.left.name !== 'React' || 'name' in node.right && node.right.name.endsWith('Event')) {
2132
- return;
2133
- }
2134
- context.report({
2135
- node,
2136
- messageId: 'illegalReactPropertyAccess',
2137
- data: {
2138
- name: node.right.name
2139
- },
2140
- *fix(fixer) {
2141
- yield fixer.replaceText(node, node.right.name);
2142
- yield* updateImportStatement(context, fixer, node.right.name);
2143
- }
2144
- });
2145
- },
2146
- MemberExpression(node) {
2147
- if (node.object.name !== 'React') {
2148
- return;
2149
- }
2150
- context.report({
2151
- node,
2152
- messageId: 'illegalReactPropertyAccess',
2153
- data: {
2154
- name: node.property.name
2155
- },
2156
- *fix(fixer) {
2157
- yield fixer.replaceText(node, node.property.name);
2158
- yield* updateImportStatement(context, fixer, node.property.name);
2159
- }
2160
- });
2161
- },
2162
- ImportDeclaration(node) {
2163
- if (node.source.value !== 'react' && node.source.value !== 'preact') {
2164
- return;
2165
- }
2166
- node.specifiers.forEach(specifier => {
2167
- if (specifier.type === 'ImportSpecifier' && specifier.imported.name && specifier.imported.name.endsWith('Event')) {
2168
- context.report({
2169
- node: specifier,
2170
- messageId: 'disallowImportReactEvent'
2171
- });
2172
- }
2173
- });
2174
- }
2175
- };
2176
- }
2177
- });
2178
-
2179
- const RULE_NAME$5 = 'react-prefer-sx-prop';
2095
+ const RULE_NAME$4 = 'react-prefer-sx-prop';
2180
2096
  var reactPreferSxProp = createRule({
2181
- name: RULE_NAME$5,
2097
+ name: RULE_NAME$4,
2182
2098
  meta: {
2183
2099
  type: 'problem',
2184
2100
  docs: {
@@ -2249,13 +2165,13 @@ var reactPreferSxProp = createRule({
2249
2165
  });
2250
2166
 
2251
2167
  function getBasicIdentifier(node) {
2252
- if (node.type === 'Identifier') {
2168
+ if (node.type === utils.AST_NODE_TYPES.Identifier) {
2253
2169
  return node.name;
2254
2170
  }
2255
- if (node.type === 'Literal') {
2171
+ if (node.type === utils.AST_NODE_TYPES.Literal) {
2256
2172
  return node.value;
2257
2173
  }
2258
- if (node.type === 'TemplateLiteral') {
2174
+ if (node.type === utils.AST_NODE_TYPES.TemplateLiteral) {
2259
2175
  if (node.expressions.length > 0) {
2260
2176
  return null;
2261
2177
  }
@@ -2265,15 +2181,15 @@ function getBasicIdentifier(node) {
2265
2181
  }
2266
2182
  function getBaseIdentifier(node) {
2267
2183
  switch (node.type) {
2268
- case 'Identifier':
2184
+ case utils.AST_NODE_TYPES.Identifier:
2269
2185
  {
2270
2186
  return node;
2271
2187
  }
2272
- case 'CallExpression':
2188
+ case utils.AST_NODE_TYPES.CallExpression:
2273
2189
  {
2274
2190
  return getBaseIdentifier(node.callee);
2275
2191
  }
2276
- case 'MemberExpression':
2192
+ case utils.AST_NODE_TYPES.MemberExpression:
2277
2193
  {
2278
2194
  return getBaseIdentifier(node.object);
2279
2195
  }
@@ -2282,7 +2198,7 @@ function getBaseIdentifier(node) {
2282
2198
  }
2283
2199
  function getStyesObj(node) {
2284
2200
  const isMakeStyles = node.callee.name === 'makeStyles';
2285
- const isModernApi = node.callee.type === 'MemberExpression' && node.callee.property.name === 'create' && getBaseIdentifier(node.callee.object) && getBaseIdentifier(node.callee.object).name === 'tss';
2201
+ const isModernApi = node.callee.type === utils.AST_NODE_TYPES.MemberExpression && node.callee.property.name === 'create' && getBaseIdentifier(node.callee.object) && getBaseIdentifier(node.callee.object).name === 'tss';
2286
2202
  if (!isMakeStyles && !isModernApi) {
2287
2203
  return;
2288
2204
  }
@@ -2298,21 +2214,21 @@ function getStyesObj(node) {
2298
2214
  return;
2299
2215
  }
2300
2216
  switch (styles.type) {
2301
- case 'ObjectExpression':
2217
+ case utils.AST_NODE_TYPES.ObjectExpression:
2302
2218
  return styles;
2303
- case 'ArrowFunctionExpression':
2219
+ case utils.AST_NODE_TYPES.ArrowFunctionExpression:
2304
2220
  {
2305
2221
  const {
2306
2222
  body
2307
2223
  } = styles;
2308
2224
  switch (body.type) {
2309
- case 'ObjectExpression':
2225
+ case utils.AST_NODE_TYPES.ObjectExpression:
2310
2226
  return body;
2311
- case 'BlockStatement':
2227
+ case utils.AST_NODE_TYPES.BlockStatement:
2312
2228
  {
2313
2229
  let stylesObj;
2314
2230
  body.body.forEach(bodyNode => {
2315
- if (bodyNode.type === 'ReturnStatement' && bodyNode.argument.type === 'ObjectExpression') {
2231
+ if (bodyNode.type === utils.AST_NODE_TYPES.ReturnStatement && bodyNode.argument.type === utils.AST_NODE_TYPES.ObjectExpression) {
2316
2232
  stylesObj = bodyNode.argument;
2317
2233
  }
2318
2234
  });
@@ -2324,10 +2240,10 @@ function getStyesObj(node) {
2324
2240
  }
2325
2241
  }
2326
2242
  function loopStylesObj(node, callback) {
2327
- if (node && node.type === 'ObjectExpression') {
2243
+ if (node && node.type === utils.AST_NODE_TYPES.ObjectExpression) {
2328
2244
  node.properties.forEach(property => {
2329
- if (property.type === 'Property' && property.value) {
2330
- if (property.value.type === 'ObjectExpression') {
2245
+ if (property.type === utils.AST_NODE_TYPES.Property && property.value) {
2246
+ if (property.value.type === utils.AST_NODE_TYPES.ObjectExpression) {
2331
2247
  loopStylesObj(property.value, callback);
2332
2248
  } else {
2333
2249
  callback(property.value);
@@ -2337,9 +2253,9 @@ function loopStylesObj(node, callback) {
2337
2253
  }
2338
2254
  }
2339
2255
 
2340
- const RULE_NAME$4 = 'tss-class-naming';
2256
+ const RULE_NAME$3 = 'tss-class-naming';
2341
2257
  var tssClassNaming = createRule({
2342
- name: RULE_NAME$4,
2258
+ name: RULE_NAME$3,
2343
2259
  meta: {
2344
2260
  type: 'problem',
2345
2261
  docs: {
@@ -2363,7 +2279,7 @@ var tssClassNaming = createRule({
2363
2279
  if (property.computed) {
2364
2280
  return;
2365
2281
  }
2366
- if (property.type === 'ExperimentalSpreadProperty' || property.type === 'SpreadElement') {
2282
+ if (property.type === 'ExperimentalSpreadProperty' || property.type === utils.AST_NODE_TYPES.SpreadElement) {
2367
2283
  return;
2368
2284
  }
2369
2285
  const className = property.key.value || property.key.name;
@@ -2533,9 +2449,9 @@ var colors = {
2533
2449
  yellowgreen: [154, 205, 50]
2534
2450
  };
2535
2451
 
2536
- const RULE_NAME$3 = 'tss-no-color-name';
2452
+ const RULE_NAME$2 = 'tss-no-color-name';
2537
2453
  var tssNoColorName = createRule({
2538
- name: RULE_NAME$3,
2454
+ name: RULE_NAME$2,
2539
2455
  meta: {
2540
2456
  type: 'suggestion',
2541
2457
  docs: {
@@ -2556,7 +2472,7 @@ var tssNoColorName = createRule({
2556
2472
  return;
2557
2473
  }
2558
2474
  function checkColorLiteral(value) {
2559
- if (value.type === 'Literal' && typeof value.value === 'string' && Object.keys(colors).includes(value.value.toLowerCase())) {
2475
+ if (value.type === utils.AST_NODE_TYPES.Literal && typeof value.value === 'string' && Object.keys(colors).includes(value.value.toLowerCase())) {
2560
2476
  context.report({
2561
2477
  node: value,
2562
2478
  messageId: 'disallowColorName'
@@ -2569,9 +2485,9 @@ var tssNoColorName = createRule({
2569
2485
  }
2570
2486
  });
2571
2487
 
2572
- const RULE_NAME$2 = 'tss-no-color-value';
2488
+ const RULE_NAME$1 = 'tss-no-color-value';
2573
2489
  var tssNoColorValue = createRule({
2574
- name: RULE_NAME$2,
2490
+ name: RULE_NAME$1,
2575
2491
  meta: {
2576
2492
  type: 'problem',
2577
2493
  docs: {
@@ -2592,7 +2508,7 @@ var tssNoColorValue = createRule({
2592
2508
  return;
2593
2509
  }
2594
2510
  function checkColorLiteral(value) {
2595
- if (value.type === 'Literal' && typeof value.value === 'string') {
2511
+ if (value.type === utils.AST_NODE_TYPES.Literal && typeof value.value === 'string') {
2596
2512
  const colorCodePattern = /#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgb\?\(\s*(\d{1,3}\s*,\s*){2}\d{1,3}(?:\s*,\s*\d*(?:\.\d+)?)?\s*\)/g;
2597
2513
  if (colorCodePattern.test(value.value)) {
2598
2514
  context.report({
@@ -2608,9 +2524,9 @@ var tssNoColorValue = createRule({
2608
2524
  }
2609
2525
  });
2610
2526
 
2611
- const RULE_NAME$1 = 'tss-unused-classes';
2527
+ const RULE_NAME = 'tss-unused-classes';
2612
2528
  var tssUnusedClasses = createRule({
2613
- name: RULE_NAME$1,
2529
+ name: RULE_NAME,
2614
2530
  meta: {
2615
2531
  type: 'suggestion',
2616
2532
  docs: {
@@ -2636,14 +2552,14 @@ var tssUnusedClasses = createRule({
2636
2552
  if (property.computed) {
2637
2553
  return;
2638
2554
  }
2639
- if (property.type === 'ExperimentalSpreadProperty' || property.type === 'SpreadElement') {
2555
+ if (property.type === 'ExperimentalSpreadProperty' || property.type === utils.AST_NODE_TYPES.SpreadElement) {
2640
2556
  return;
2641
2557
  }
2642
2558
  definedClasses[property.key.value || property.key.name] = property;
2643
2559
  });
2644
2560
  },
2645
2561
  MemberExpression(node) {
2646
- if (node.object.type === 'Identifier' && node.object.name === 'classes') {
2562
+ if (node.object.type === utils.AST_NODE_TYPES.Identifier && node.object.name === 'classes') {
2647
2563
  const whichClass = getBasicIdentifier(node.property);
2648
2564
  if (whichClass) {
2649
2565
  usedClasses[whichClass] = true;
@@ -2660,22 +2576,22 @@ var tssUnusedClasses = createRule({
2660
2576
  const {
2661
2577
  parent
2662
2578
  } = node;
2663
- if (parent.type !== 'MemberExpression') {
2579
+ if (parent.type !== utils.AST_NODE_TYPES.MemberExpression) {
2664
2580
  return;
2665
2581
  }
2666
2582
  if (
2667
2583
  node.object.object &&
2668
- node.object.object.type !== 'ThisExpression') {
2584
+ node.object.object.type !== utils.AST_NODE_TYPES.ThisExpression) {
2669
2585
  return;
2670
2586
  }
2671
2587
  const propsIdentifier = getBasicIdentifier(parent.object);
2672
2588
  if (propsIdentifier && propsIdentifier !== 'props') {
2673
2589
  return;
2674
2590
  }
2675
- if (!propsIdentifier && parent.object.type !== 'MemberExpression') {
2591
+ if (!propsIdentifier && parent.object.type !== utils.AST_NODE_TYPES.MemberExpression) {
2676
2592
  return;
2677
2593
  }
2678
- if (parent.parent.type === 'MemberExpression') {
2594
+ if (parent.parent.type === utils.AST_NODE_TYPES.MemberExpression) {
2679
2595
  return;
2680
2596
  }
2681
2597
  const parentClassIdentifier = getBasicIdentifier(parent.property);
@@ -2700,254 +2616,6 @@ var tssUnusedClasses = createRule({
2700
2616
  }
2701
2617
  });
2702
2618
 
2703
- const RULE_NAME = 'var-naming';
2704
- const reactGlobalFuncs = new Set(['createContext', 'forwardRef', 'lazy', 'memo', 'combineProviders']);
2705
- const reactFCTypes = new Set(['FC', 'FunctionComponent', 'VFC', 'VoidFunctionComponent']);
2706
- const defaultExcludeTypes = ['StoryObj', 'StoryFn'];
2707
- const defaultExcludeNames = ['^(__dirname|__filename)$', '(.*)Event$'];
2708
- var varNaming = createRule({
2709
- name: RULE_NAME,
2710
- meta: {
2711
- type: 'problem',
2712
- docs: {
2713
- description: 'Enforce variable and function naming convention',
2714
- recommended: 'recommended'
2715
- },
2716
- schema: [{
2717
- type: 'object',
2718
- properties: {
2719
- funcFormat: {
2720
- type: 'array',
2721
- items: {
2722
- "enum": ['camelCase', 'PascalCase', 'UPPER_CASE']
2723
- }
2724
- },
2725
- varFormat: {
2726
- type: 'array',
2727
- items: {
2728
- "enum": ['camelCase', 'PascalCase', 'UPPER_CASE']
2729
- }
2730
- },
2731
- excludeNames: {
2732
- type: 'array',
2733
- items: {
2734
- type: 'string'
2735
- }
2736
- },
2737
- excludeFuncs: {
2738
- type: 'array',
2739
- items: {
2740
- type: 'string'
2741
- }
2742
- },
2743
- excludeTypes: {
2744
- type: 'array',
2745
- items: {
2746
- type: 'string'
2747
- }
2748
- }
2749
- }
2750
- }],
2751
- messages: {
2752
- invalidFuncNaming: 'Invalid function naming for non-React component, expected {{formats}}',
2753
- invalidReactFCNaming: 'Invalid naming convention for React functional component, expected PascalCase',
2754
- invalidVarNaming: 'Invalid variable naming, expected {{formats}}'
2755
- }
2756
- },
2757
- defaultOptions: [],
2758
- create(context) {
2759
- if (!context.options[0]) {
2760
- context.options[0] = {};
2761
- }
2762
- const funcFormat = context.options[0].funcFormat || ['camelCase'];
2763
- const varFormat = context.options[0].varFormat || ['camelCase', 'UPPER_CASE'];
2764
- let excludeNames = context.options[0].excludeNames || [];
2765
- excludeNames = [...defaultExcludeNames, ...excludeNames];
2766
- const excludeFuncs = context.options[0].excludeFuncs || [];
2767
- let excludeTypes = context.options[0].excludeTypes || [];
2768
- excludeTypes = [...defaultExcludeTypes, ...excludeTypes];
2769
- function validate(type, {
2770
- node,
2771
- name
2772
- }) {
2773
- let isPass = false;
2774
- let formats;
2775
- let messageId;
2776
- switch (type) {
2777
- case 'func':
2778
- formats = funcFormat;
2779
- messageId = 'invalidFuncNaming';
2780
- break;
2781
- case 'var':
2782
- formats = varFormat;
2783
- messageId = 'invalidVarNaming';
2784
- break;
2785
- }
2786
- for (const format of formats) {
2787
- switch (format) {
2788
- case 'camelCase':
2789
- if (eslintUtils.isCamelCase(name)) {
2790
- isPass = true;
2791
- }
2792
- break;
2793
- case 'PascalCase':
2794
- if (eslintUtils.isPascalCase(name)) {
2795
- isPass = true;
2796
- }
2797
- break;
2798
- case 'UPPER_CASE':
2799
- if (eslintUtils.isUpperCase(name)) {
2800
- isPass = true;
2801
- }
2802
- break;
2803
- }
2804
- }
2805
- if (!isPass) {
2806
- context.report({
2807
- node: node,
2808
- messageId: messageId,
2809
- data: {
2810
- formats: formats.join(', ')
2811
- }
2812
- });
2813
- }
2814
- }
2815
- function checkJSXElement(node) {
2816
- if (!node) {
2817
- return false;
2818
- }
2819
- if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
2820
- return true;
2821
- }
2822
- if (node.type === 'BlockStatement') {
2823
- for (const statement of node.body) {
2824
- if (statement.type === 'ReturnStatement') {
2825
- if (checkJSXElement(statement.argument)) {
2826
- return true;
2827
- }
2828
- } else if (checkJSXElement(statement)) {
2829
- return true;
2830
- }
2831
- }
2832
- }
2833
- if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
2834
- return checkJSXElement(node.body);
2835
- }
2836
- return false;
2837
- }
2838
- function getTypeReference(node) {
2839
- if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
2840
- const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
2841
- if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
2842
- const typeName = typeAnnotation.typeName.name;
2843
- const typeNameLast = typeName.split('.').pop();
2844
- return typeNameLast;
2845
- }
2846
- }
2847
- }
2848
- return {
2849
- FunctionDeclaration(node) {
2850
- if (node.type === 'FunctionDeclaration' && node.id) {
2851
- const fnName = node.id.name;
2852
- const isReactComponent = checkJSXElement(node.body);
2853
- if (!isReactComponent) {
2854
- validate('func', {
2855
- node,
2856
- name: fnName
2857
- });
2858
- }
2859
- }
2860
- },
2861
- VariableDeclarator(node) {
2862
- if (node.id && node.init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(node.init.type)) {
2863
- const fnName = node.id.name;
2864
- let isReactComponent = checkJSXElement(node.init.body);
2865
- const typeName = getTypeReference(node);
2866
- if (typeName && reactFCTypes.has(typeName)) {
2867
- isReactComponent = true;
2868
- }
2869
- if (!isReactComponent) {
2870
- validate('func', {
2871
- node,
2872
- name: fnName
2873
- });
2874
- }
2875
- } else if (node.id && node.init && node.init.type === 'LogicalExpression') {
2876
- const varName = node.id.name;
2877
- const parts = [node.init.left, node.init.right];
2878
- let partIsReactComponent = false;
2879
- for (const part of parts) {
2880
- if (['FunctionExpression', 'ArrowFunctionExpression'].includes(part.type)) {
2881
- const isReactComponent = checkJSXElement(part.body);
2882
- if (isReactComponent) {
2883
- partIsReactComponent = true;
2884
- }
2885
- }
2886
- }
2887
- if (!partIsReactComponent) {
2888
- validate('var', {
2889
- node,
2890
- name: varName
2891
- });
2892
- }
2893
- } else if (node.id) {
2894
- const varName = node.id.name;
2895
- for (const excludeRegex of excludeNames) {
2896
- if (new RegExp(excludeRegex).test(varName)) {
2897
- return;
2898
- }
2899
- }
2900
- const typeName = getTypeReference(node);
2901
- if (typeName) {
2902
- for (const excludeRegex of excludeTypes) {
2903
- if (new RegExp(excludeRegex).test(typeName)) {
2904
- return;
2905
- }
2906
- }
2907
- }
2908
- if (node.id.parent && node.id.parent.init) {
2909
- let calleeName;
2910
- let shouldCheckReact = false;
2911
- let initNode;
2912
- if (node.id.parent.init.type === 'CallExpression') {
2913
- initNode = node.id.parent.init;
2914
- } else if (node.id.parent.init.type === 'TSAsExpression' && node.id.parent.init.expression && node.id.parent.init.expression.callee) {
2915
- initNode = node.id.parent.init.expression;
2916
- }
2917
- if (initNode) {
2918
- shouldCheckReact = true;
2919
- if (initNode.callee.type === 'Identifier') {
2920
- calleeName = initNode.callee.name;
2921
- } else if (initNode.callee.type === 'MemberExpression') {
2922
- calleeName = initNode.callee.property.name;
2923
- }
2924
- }
2925
- if (calleeName) {
2926
- for (const excludeRegex of excludeFuncs) {
2927
- if (new RegExp(excludeRegex).test(calleeName)) {
2928
- return;
2929
- }
2930
- }
2931
- }
2932
- if (shouldCheckReact) {
2933
- if (!calleeName) {
2934
- return;
2935
- }
2936
- if (reactGlobalFuncs.has(calleeName) || reactGlobalFuncs.has(calleeName.split('.').pop())) {
2937
- return;
2938
- }
2939
- }
2940
- }
2941
- validate('var', {
2942
- node,
2943
- name: varName
2944
- });
2945
- }
2946
- }
2947
- };
2948
- }
2949
- });
2950
-
2951
2619
  var ruleFiles = /*#__PURE__*/Object.freeze({
2952
2620
  __proto__: null,
2953
2621
  rules_enforce_mui_icon_alias: enforceMuiIconAlias,
@@ -2964,13 +2632,11 @@ var ruleFiles = /*#__PURE__*/Object.freeze({
2964
2632
  rules_no_unnecessary_template_literals: noUnnecessaryTemplateLiterals,
2965
2633
  rules_react_better_exhaustive_deps: reactBetterExhaustiveDeps,
2966
2634
  rules_react_hook_use_ref: reactHookUseRef,
2967
- rules_react_prefer_named_property_access: reactPreferNamedPropertyAccess,
2968
2635
  rules_react_prefer_sx_prop: reactPreferSxProp,
2969
2636
  rules_tss_class_naming: tssClassNaming,
2970
2637
  rules_tss_no_color_name: tssNoColorName,
2971
2638
  rules_tss_no_color_value: tssNoColorValue,
2972
- rules_tss_unused_classes: tssUnusedClasses,
2973
- rules_var_naming: varNaming
2639
+ rules_tss_unused_classes: tssUnusedClasses
2974
2640
  });
2975
2641
 
2976
2642
  const plugin = {