eslint-plugin-nima 1.2.4 → 1.2.6

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.
Files changed (227) hide show
  1. package/README.md +18 -18
  2. package/dist/constants/boolean-prefixes.js.map +1 -1
  3. package/dist/constants/consoles.js.map +1 -1
  4. package/dist/constants/hooks.js.map +1 -1
  5. package/dist/index.d.ts +25 -24
  6. package/dist/index.js +13 -57
  7. package/dist/index.js.map +1 -1
  8. package/dist/{models/boolean-naming-convention.model.d.ts → rules/boolean-naming-convention/config.d.ts} +11 -0
  9. package/dist/rules/boolean-naming-convention/config.js +70 -0
  10. package/dist/rules/boolean-naming-convention/config.js.map +1 -0
  11. package/dist/rules/boolean-naming-convention/create.d.ts +11 -0
  12. package/dist/rules/boolean-naming-convention/create.js +415 -0
  13. package/dist/rules/boolean-naming-convention/create.js.map +1 -0
  14. package/dist/rules/boolean-naming-convention/index.d.ts +2 -0
  15. package/dist/rules/boolean-naming-convention/index.js +22 -0
  16. package/dist/rules/boolean-naming-convention/index.js.map +1 -0
  17. package/dist/rules/{restrict-imports.d.ts → boolean-naming-convention/rule.d.ts} +2 -2
  18. package/dist/rules/boolean-naming-convention/rule.js +14 -0
  19. package/dist/rules/boolean-naming-convention/rule.js.map +1 -0
  20. package/dist/rules/index.d.ts +12 -0
  21. package/dist/rules/index.js +49 -0
  22. package/dist/rules/index.js.map +1 -0
  23. package/dist/rules/no-handler-suffix/config.d.ts +14 -0
  24. package/dist/rules/no-handler-suffix/config.js +23 -0
  25. package/dist/rules/no-handler-suffix/config.js.map +1 -0
  26. package/dist/rules/no-handler-suffix/create.d.ts +8 -0
  27. package/dist/rules/no-handler-suffix/create.js +71 -0
  28. package/dist/rules/no-handler-suffix/create.js.map +1 -0
  29. package/dist/rules/no-handler-suffix/index.d.ts +2 -0
  30. package/dist/rules/no-handler-suffix/index.js +22 -0
  31. package/dist/rules/no-handler-suffix/index.js.map +1 -0
  32. package/dist/rules/{no-handler-suffix.d.ts → no-handler-suffix/rule.d.ts} +2 -2
  33. package/dist/rules/no-handler-suffix/rule.js +14 -0
  34. package/dist/rules/no-handler-suffix/rule.js.map +1 -0
  35. package/dist/rules/no-objects-in-deps/config.d.ts +14 -0
  36. package/dist/rules/no-objects-in-deps/config.js +22 -0
  37. package/dist/rules/no-objects-in-deps/config.js.map +1 -0
  38. package/dist/rules/no-objects-in-deps/create.d.ts +6 -0
  39. package/dist/rules/no-objects-in-deps/create.js +124 -0
  40. package/dist/rules/no-objects-in-deps/create.js.map +1 -0
  41. package/dist/rules/no-objects-in-deps/index.d.ts +2 -0
  42. package/dist/rules/no-objects-in-deps/index.js +22 -0
  43. package/dist/rules/no-objects-in-deps/index.js.map +1 -0
  44. package/dist/rules/{no-objects-in-deps.d.ts → no-objects-in-deps/rule.d.ts} +2 -2
  45. package/dist/rules/no-objects-in-deps/rule.js +14 -0
  46. package/dist/rules/no-objects-in-deps/rule.js.map +1 -0
  47. package/dist/rules/params-naming-convention/config.d.ts +21 -0
  48. package/dist/rules/params-naming-convention/config.js +55 -0
  49. package/dist/rules/params-naming-convention/config.js.map +1 -0
  50. package/dist/rules/params-naming-convention/create.d.ts +6 -0
  51. package/dist/rules/params-naming-convention/create.js +49 -0
  52. package/dist/rules/params-naming-convention/create.js.map +1 -0
  53. package/dist/rules/params-naming-convention/index.d.ts +2 -0
  54. package/dist/rules/params-naming-convention/index.js +22 -0
  55. package/dist/rules/params-naming-convention/index.js.map +1 -0
  56. package/dist/rules/{prefer-react-fc.d.ts → params-naming-convention/rule.d.ts} +2 -2
  57. package/dist/rules/params-naming-convention/rule.js +14 -0
  58. package/dist/rules/params-naming-convention/rule.js.map +1 -0
  59. package/dist/{models/prefer-arrow-functions.model.d.ts → rules/prefer-arrow-functions/config.d.ts} +10 -0
  60. package/dist/rules/prefer-arrow-functions/config.js +67 -0
  61. package/dist/rules/prefer-arrow-functions/config.js.map +1 -0
  62. package/dist/rules/prefer-arrow-functions/create.d.ts +9 -0
  63. package/dist/rules/prefer-arrow-functions/create.js +150 -0
  64. package/dist/rules/prefer-arrow-functions/create.js.map +1 -0
  65. package/dist/rules/prefer-arrow-functions/index.d.ts +2 -0
  66. package/dist/rules/prefer-arrow-functions/index.js +22 -0
  67. package/dist/rules/prefer-arrow-functions/index.js.map +1 -0
  68. package/dist/rules/{restrict-function-usage.d.ts → prefer-arrow-functions/rule.d.ts} +2 -2
  69. package/dist/rules/prefer-arrow-functions/rule.js +14 -0
  70. package/dist/rules/prefer-arrow-functions/rule.js.map +1 -0
  71. package/dist/rules/prefer-export-under-component/config.d.ts +14 -0
  72. package/dist/rules/prefer-export-under-component/config.js +23 -0
  73. package/dist/rules/prefer-export-under-component/config.js.map +1 -0
  74. package/dist/rules/prefer-export-under-component/create.d.ts +8 -0
  75. package/dist/rules/prefer-export-under-component/create.js +99 -0
  76. package/dist/rules/prefer-export-under-component/create.js.map +1 -0
  77. package/dist/rules/prefer-export-under-component/index.d.ts +2 -0
  78. package/dist/rules/prefer-export-under-component/index.js +22 -0
  79. package/dist/rules/prefer-export-under-component/index.js.map +1 -0
  80. package/dist/rules/{prefer-react-with-hooks.d.ts → prefer-export-under-component/rule.d.ts} +2 -2
  81. package/dist/rules/prefer-export-under-component/rule.js +14 -0
  82. package/dist/rules/prefer-export-under-component/rule.js.map +1 -0
  83. package/dist/rules/prefer-react-fc/config.d.ts +19 -0
  84. package/dist/rules/prefer-react-fc/config.js +43 -0
  85. package/dist/rules/prefer-react-fc/config.js.map +1 -0
  86. package/dist/rules/prefer-react-fc/create.d.ts +8 -0
  87. package/dist/rules/prefer-react-fc/create.js +166 -0
  88. package/dist/rules/prefer-react-fc/create.js.map +1 -0
  89. package/dist/rules/prefer-react-fc/index.d.ts +2 -0
  90. package/dist/rules/prefer-react-fc/index.js +22 -0
  91. package/dist/rules/prefer-react-fc/index.js.map +1 -0
  92. package/dist/rules/{prefer-arrow-functions.d.ts → prefer-react-fc/rule.d.ts} +2 -2
  93. package/dist/rules/prefer-react-fc/rule.js +14 -0
  94. package/dist/rules/prefer-react-fc/rule.js.map +1 -0
  95. package/dist/rules/prefer-react-with-hooks/config.d.ts +15 -0
  96. package/dist/rules/prefer-react-with-hooks/config.js +25 -0
  97. package/dist/rules/prefer-react-with-hooks/config.js.map +1 -0
  98. package/dist/rules/prefer-react-with-hooks/create.d.ts +7 -0
  99. package/dist/rules/prefer-react-with-hooks/create.js +188 -0
  100. package/dist/rules/prefer-react-with-hooks/create.js.map +1 -0
  101. package/dist/rules/prefer-react-with-hooks/index.d.ts +2 -0
  102. package/dist/rules/prefer-react-with-hooks/index.js +22 -0
  103. package/dist/rules/prefer-react-with-hooks/index.js.map +1 -0
  104. package/dist/rules/{prefer-export-under-component.d.ts → prefer-react-with-hooks/rule.d.ts} +2 -2
  105. package/dist/rules/prefer-react-with-hooks/rule.js +14 -0
  106. package/dist/rules/prefer-react-with-hooks/rule.js.map +1 -0
  107. package/dist/rules/prefer-void-for-optional-param/config.d.ts +15 -0
  108. package/dist/rules/prefer-void-for-optional-param/config.js +25 -0
  109. package/dist/rules/prefer-void-for-optional-param/config.js.map +1 -0
  110. package/dist/rules/prefer-void-for-optional-param/create.d.ts +8 -0
  111. package/dist/rules/prefer-void-for-optional-param/create.js +188 -0
  112. package/dist/rules/prefer-void-for-optional-param/create.js.map +1 -0
  113. package/dist/rules/prefer-void-for-optional-param/index.d.ts +2 -0
  114. package/dist/rules/prefer-void-for-optional-param/index.js +22 -0
  115. package/dist/rules/prefer-void-for-optional-param/index.js.map +1 -0
  116. package/dist/rules/prefer-void-for-optional-param/rule.d.ts +5 -0
  117. package/dist/rules/prefer-void-for-optional-param/rule.js +14 -0
  118. package/dist/rules/prefer-void-for-optional-param/rule.js.map +1 -0
  119. package/dist/rules/restrict-console-methods/config.d.ts +18 -0
  120. package/dist/rules/restrict-console-methods/config.js +38 -0
  121. package/dist/rules/restrict-console-methods/config.js.map +1 -0
  122. package/dist/rules/restrict-console-methods/create.d.ts +6 -0
  123. package/dist/rules/restrict-console-methods/create.js +34 -0
  124. package/dist/rules/restrict-console-methods/create.js.map +1 -0
  125. package/dist/rules/restrict-console-methods/index.d.ts +2 -0
  126. package/dist/rules/restrict-console-methods/index.js +22 -0
  127. package/dist/rules/restrict-console-methods/index.js.map +1 -0
  128. package/dist/rules/restrict-console-methods/rule.d.ts +5 -0
  129. package/dist/rules/restrict-console-methods/rule.js +14 -0
  130. package/dist/rules/restrict-console-methods/rule.js.map +1 -0
  131. package/dist/rules/restrict-function-usage/config.d.ts +21 -0
  132. package/dist/rules/restrict-function-usage/config.js +62 -0
  133. package/dist/rules/restrict-function-usage/config.js.map +1 -0
  134. package/dist/rules/restrict-function-usage/create.d.ts +6 -0
  135. package/dist/rules/restrict-function-usage/create.js +76 -0
  136. package/dist/rules/restrict-function-usage/create.js.map +1 -0
  137. package/dist/rules/restrict-function-usage/index.d.ts +2 -0
  138. package/dist/rules/restrict-function-usage/index.js +22 -0
  139. package/dist/rules/restrict-function-usage/index.js.map +1 -0
  140. package/dist/rules/restrict-function-usage/rule.d.ts +5 -0
  141. package/dist/rules/restrict-function-usage/rule.js +14 -0
  142. package/dist/rules/restrict-function-usage/rule.js.map +1 -0
  143. package/dist/rules/restrict-imports/config.d.ts +22 -0
  144. package/dist/rules/restrict-imports/config.js +69 -0
  145. package/dist/rules/restrict-imports/config.js.map +1 -0
  146. package/dist/rules/restrict-imports/create.d.ts +6 -0
  147. package/dist/rules/restrict-imports/create.js +92 -0
  148. package/dist/rules/restrict-imports/create.js.map +1 -0
  149. package/dist/rules/restrict-imports/index.d.ts +2 -0
  150. package/dist/rules/restrict-imports/index.js +22 -0
  151. package/dist/rules/restrict-imports/index.js.map +1 -0
  152. package/dist/rules/restrict-imports/rule.d.ts +5 -0
  153. package/dist/rules/restrict-imports/rule.js +14 -0
  154. package/dist/rules/restrict-imports/rule.js.map +1 -0
  155. package/dist/utility/core.js.map +1 -1
  156. package/dist/utility/file-helpers.d.ts +6 -0
  157. package/dist/utility/file-helpers.js +32 -0
  158. package/dist/utility/file-helpers.js.map +1 -0
  159. package/dist/utility/function-helpers.d.ts +4 -4
  160. package/dist/utility/function-helpers.js +17 -15
  161. package/dist/utility/function-helpers.js.map +1 -1
  162. package/dist/utility/type-helpers.d.ts +4 -1
  163. package/dist/utility/type-helpers.js +6 -4
  164. package/dist/utility/type-helpers.js.map +1 -1
  165. package/package.json +75 -73
  166. package/dist/models/boolean-naming-convention.model.js +0 -11
  167. package/dist/models/boolean-naming-convention.model.js.map +0 -1
  168. package/dist/models/no-handler-suffix.model.d.ts +0 -4
  169. package/dist/models/no-handler-suffix.model.js +0 -8
  170. package/dist/models/no-handler-suffix.model.js.map +0 -1
  171. package/dist/models/no-objects-in-deps.model.d.ts +0 -4
  172. package/dist/models/no-objects-in-deps.model.js +0 -8
  173. package/dist/models/no-objects-in-deps.model.js.map +0 -1
  174. package/dist/models/params-naming-convention.model.d.ts +0 -11
  175. package/dist/models/params-naming-convention.model.js +0 -8
  176. package/dist/models/params-naming-convention.model.js.map +0 -1
  177. package/dist/models/prefer-arrow-functions.model.js +0 -10
  178. package/dist/models/prefer-arrow-functions.model.js.map +0 -1
  179. package/dist/models/prefer-export-under-component.model.d.ts +0 -4
  180. package/dist/models/prefer-export-under-component.model.js +0 -8
  181. package/dist/models/prefer-export-under-component.model.js.map +0 -1
  182. package/dist/models/prefer-react-fc.model.d.ts +0 -9
  183. package/dist/models/prefer-react-fc.model.js +0 -8
  184. package/dist/models/prefer-react-fc.model.js.map +0 -1
  185. package/dist/models/prefer-react-with-hooks.model.d.ts +0 -5
  186. package/dist/models/prefer-react-with-hooks.model.js +0 -9
  187. package/dist/models/prefer-react-with-hooks.model.js.map +0 -1
  188. package/dist/models/prefer-void-for-optional-param.model.d.ts +0 -5
  189. package/dist/models/prefer-void-for-optional-param.model.js +0 -9
  190. package/dist/models/prefer-void-for-optional-param.model.js.map +0 -1
  191. package/dist/models/restrict-console-methods.model.d.ts +0 -8
  192. package/dist/models/restrict-console-methods.model.js +0 -8
  193. package/dist/models/restrict-console-methods.model.js.map +0 -1
  194. package/dist/models/restrict-function-usage.model.d.ts +0 -11
  195. package/dist/models/restrict-function-usage.model.js +0 -8
  196. package/dist/models/restrict-function-usage.model.js.map +0 -1
  197. package/dist/models/restrict-imports.model.d.ts +0 -12
  198. package/dist/models/restrict-imports.model.js +0 -8
  199. package/dist/models/restrict-imports.model.js.map +0 -1
  200. package/dist/rules/boolean-naming-convention.d.ts +0 -5
  201. package/dist/rules/boolean-naming-convention.js +0 -379
  202. package/dist/rules/boolean-naming-convention.js.map +0 -1
  203. package/dist/rules/no-handler-suffix.js +0 -89
  204. package/dist/rules/no-handler-suffix.js.map +0 -1
  205. package/dist/rules/no-objects-in-deps.js +0 -90
  206. package/dist/rules/no-objects-in-deps.js.map +0 -1
  207. package/dist/rules/params-naming-convention.d.ts +0 -5
  208. package/dist/rules/params-naming-convention.js +0 -95
  209. package/dist/rules/params-naming-convention.js.map +0 -1
  210. package/dist/rules/prefer-arrow-functions.js +0 -208
  211. package/dist/rules/prefer-arrow-functions.js.map +0 -1
  212. package/dist/rules/prefer-export-under-component.js +0 -113
  213. package/dist/rules/prefer-export-under-component.js.map +0 -1
  214. package/dist/rules/prefer-react-fc.js +0 -204
  215. package/dist/rules/prefer-react-fc.js.map +0 -1
  216. package/dist/rules/prefer-react-with-hooks.js +0 -185
  217. package/dist/rules/prefer-react-with-hooks.js.map +0 -1
  218. package/dist/rules/prefer-void-for-optional-param.d.ts +0 -6
  219. package/dist/rules/prefer-void-for-optional-param.js +0 -188
  220. package/dist/rules/prefer-void-for-optional-param.js.map +0 -1
  221. package/dist/rules/restrict-console-methods.d.ts +0 -5
  222. package/dist/rules/restrict-console-methods.js +0 -66
  223. package/dist/rules/restrict-console-methods.js.map +0 -1
  224. package/dist/rules/restrict-function-usage.js +0 -121
  225. package/dist/rules/restrict-function-usage.js.map +0 -1
  226. package/dist/rules/restrict-imports.js +0 -135
  227. package/dist/rules/restrict-imports.js.map +0 -1
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const function_helpers_1 = require("../../utility/function-helpers");
6
+ const config_1 = require("./config");
7
+ const create = (context) => {
8
+ const isReactComponent = (node) => {
9
+ const fnName = (0, function_helpers_1.getFunctionName)(node);
10
+ if (!fnName || !(0, function_helpers_1.isComponentFunction)(fnName)) {
11
+ return;
12
+ }
13
+ return hasJSXReturn(node);
14
+ };
15
+ const hasJSXReturn = (node) => {
16
+ if (!node.body) {
17
+ return false;
18
+ }
19
+ return node.body.type === utils_1.AST_NODE_TYPES.BlockStatement
20
+ ? checkBlockForJSX(node.body)
21
+ : isJSXExpression(node.body);
22
+ };
23
+ const checkBlockForJSX = (block) => {
24
+ for (const statement of block.body) {
25
+ if (statement.type === utils_1.AST_NODE_TYPES.ReturnStatement &&
26
+ statement.argument &&
27
+ isJSXExpression(statement.argument)) {
28
+ return true;
29
+ }
30
+ if (statement.type === utils_1.AST_NODE_TYPES.IfStatement) {
31
+ if (statement.consequent.type ===
32
+ utils_1.AST_NODE_TYPES.BlockStatement &&
33
+ checkBlockForJSX(statement.consequent)) {
34
+ return true;
35
+ }
36
+ if (statement.alternate?.type ===
37
+ utils_1.AST_NODE_TYPES.BlockStatement &&
38
+ checkBlockForJSX(statement.alternate)) {
39
+ return true;
40
+ }
41
+ }
42
+ }
43
+ return false;
44
+ };
45
+ const isJSXExpression = (node) => {
46
+ return (node.type === utils_1.AST_NODE_TYPES.JSXElement ||
47
+ node.type === utils_1.AST_NODE_TYPES.JSXFragment ||
48
+ (node.type === utils_1.AST_NODE_TYPES.ConditionalExpression &&
49
+ (isJSXExpression(node.consequent) ||
50
+ isJSXExpression(node.alternate))) ||
51
+ (node.type === utils_1.AST_NODE_TYPES.LogicalExpression &&
52
+ isJSXExpression(node.right)));
53
+ };
54
+ const hasReactFCAnnotation = (node) => {
55
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
56
+ node.parent.id.type === utils_1.AST_NODE_TYPES.Identifier &&
57
+ node.parent.id.typeAnnotation) {
58
+ const typeAnnotation = node.parent.id.typeAnnotation.typeAnnotation;
59
+ return containsReactFCType(typeAnnotation);
60
+ }
61
+ if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration &&
62
+ node.returnType) {
63
+ return containsReactFCType(node.returnType.typeAnnotation);
64
+ }
65
+ return false;
66
+ };
67
+ const hasCustomComponentTypeAnnotation = (node) => {
68
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
69
+ node.parent.id.type === utils_1.AST_NODE_TYPES.Identifier &&
70
+ node.parent.id.typeAnnotation) {
71
+ const typeAnnotation = node.parent.id.typeAnnotation.typeAnnotation;
72
+ return hasCustomComponentType(typeAnnotation);
73
+ }
74
+ if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration &&
75
+ node.returnType) {
76
+ return hasCustomComponentType(node.returnType.typeAnnotation);
77
+ }
78
+ return false;
79
+ };
80
+ const hasCustomComponentType = (typeNode) => {
81
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
82
+ return typeNode.types.some((type) => isCustomComponentType(type));
83
+ }
84
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSUnionType) {
85
+ return typeNode.types.some((type) => isCustomComponentType(type));
86
+ }
87
+ return isCustomComponentType(typeNode);
88
+ };
89
+ const isCustomComponentType = (typeNode) => {
90
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference) {
91
+ const typeName = typeNode.typeName;
92
+ if (typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName) {
93
+ return true;
94
+ }
95
+ if (typeName.type === utils_1.AST_NODE_TYPES.Identifier) {
96
+ const name = typeName.name;
97
+ if (name === "FC" || name === "FunctionComponent") {
98
+ return false;
99
+ }
100
+ return name.endsWith("Component");
101
+ }
102
+ }
103
+ return false;
104
+ };
105
+ const containsReactFCType = (typeNode) => {
106
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
107
+ return typeNode.types.some((type) => isReactFCType(type));
108
+ }
109
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSUnionType) {
110
+ return typeNode.types.some((type) => isReactFCType(type));
111
+ }
112
+ return isReactFCType(typeNode);
113
+ };
114
+ const isReactFCType = (typeNode) => {
115
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
116
+ typeNode.typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName &&
117
+ typeNode.typeName.left.type === utils_1.AST_NODE_TYPES.Identifier &&
118
+ typeNode.typeName.left.name === "React" &&
119
+ typeNode.typeName.right.type === utils_1.AST_NODE_TYPES.Identifier &&
120
+ (typeNode.typeName.right.name === "FC" ||
121
+ typeNode.typeName.right.name === "FunctionComponent")) {
122
+ return true;
123
+ }
124
+ if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
125
+ typeNode.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
126
+ (typeNode.typeName.name === "FC" ||
127
+ typeNode.typeName.name === "FunctionComponent")) {
128
+ return true;
129
+ }
130
+ return false;
131
+ };
132
+ return {
133
+ ArrowFunctionExpression: (node) => {
134
+ if (isReactComponent(node) &&
135
+ !hasReactFCAnnotation(node) &&
136
+ !hasCustomComponentTypeAnnotation(node)) {
137
+ context.report({
138
+ messageId: config_1.Messages.REQUIRE_REACT_FC,
139
+ node,
140
+ });
141
+ }
142
+ },
143
+ FunctionDeclaration: (node) => {
144
+ if (isReactComponent(node) &&
145
+ !hasReactFCAnnotation(node) &&
146
+ !hasCustomComponentTypeAnnotation(node)) {
147
+ context.report({
148
+ messageId: config_1.Messages.REQUIRE_REACT_FC,
149
+ node: node.id || node,
150
+ });
151
+ }
152
+ },
153
+ FunctionExpression: (node) => {
154
+ if (isReactComponent(node) &&
155
+ !hasReactFCAnnotation(node) &&
156
+ !hasCustomComponentTypeAnnotation(node)) {
157
+ context.report({
158
+ messageId: config_1.Messages.REQUIRE_REACT_FC,
159
+ node,
160
+ });
161
+ }
162
+ },
163
+ };
164
+ };
165
+ exports.create = create;
166
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-fc/create.ts"],"names":[],"mappings":";;;AAAA,oDAAoE;AAEpE,gEAGmC;AAEnC,qCAAkD;AAE3C,MAAM,MAAM,GAAG,CAAC,OAAuC,EAAE,EAAE;IAC9D,MAAM,gBAAgB,GAAG,CAAC,IAA2B,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,IAAA,kCAAe,EAAC,IAAI,CAAC,CAAC;QAErC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAA,sCAAmB,EAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,OAAO;QACX,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,CAAC,IAA2B,EAAE,EAAE;QACjD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACb,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,cAAc;YACnD,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC7B,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,CAAC,KAA8B,EAAE,EAAE;QACxD,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YACjC,IACI,SAAS,CAAC,IAAI,KAAK,sBAAc,CAAC,eAAe;gBACjD,SAAS,CAAC,QAAQ;gBAClB,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,CAAC;gBACC,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,IAAI,SAAS,C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AAI;iBACP,CAAC,CAAC;YACP,CAAC;QACL,CAAC;QACD,mBAAmB,EAAE,CAAC,IAAkC,EAAE,EAAE;YACxD,IACI,gBAAgB,CAAC,IAAI,CAAC;gBACtB,CAAC,oBAAoB,CAAC,IAAI,CAAC;gBAC3B,CAAC,gCAAgC,CAAC,IAAI,CAAC,EACzC,CAAC;gBACC,OAAO,CAAC,MAAM,CAAC;oBACX,SAAS,EAAE,iBAAQ,CAAC,gBAAgB;oBACpC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;iBACxB,CAAC,CAAC;YACP,CAAC;QACL,CAAC;QACD,kBAAkB,EAAE,CAAC,IAAiC,EAAE,EAAE;YACtD,IACI,gBAAgB,CAAC,IAAI,CAAC;gBACtB,CAAC,oBAAoB,CAAC,IAAI,CAAC;gBAC3B,CAAC,gCAAgC,CAAC,IAAI,CAAC,EACzC,CAAC;gBACC,OAAO,CAAC,MAAM,CAAC;oBACX,SAAS,EAAE,iBAAQ,CAAC,gBAAgB;oBACpC,IAAI;iBACP,CAAC,CAAC;YACP,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AA1MW,QAAA,MAAM,UA0MjB"}
@@ -0,0 +1,2 @@
1
+ export { config, Messages } from "./config";
2
+ export * from "./rule";
@@ -0,0 +1,22 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Messages = exports.config = void 0;
18
+ var config_1 = require("./config");
19
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
20
+ Object.defineProperty(exports, "Messages", { enumerable: true, get: function () { return config_1.Messages; } });
21
+ __exportStar(require("./rule"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-fc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACzB,yCAAuB"}
@@ -1,5 +1,5 @@
1
- import { Messages, type Options } from "../models/prefer-arrow-functions.model";
2
- export declare const name = "prefer-arrow-functions";
1
+ import { Messages, name, type Options } from "./config";
2
+ export { name };
3
3
  export declare const rule: import("@typescript-eslint/utils/ts-eslint").RuleModule<Messages, Options, {
4
4
  recommended: boolean;
5
5
  }, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rule = exports.name = void 0;
4
+ const core_1 = require("../../utility/core");
5
+ const config_1 = require("./config");
6
+ Object.defineProperty(exports, "name", { enumerable: true, get: function () { return config_1.name; } });
7
+ const create_1 = require("./create");
8
+ exports.rule = (0, core_1.createRule)({
9
+ create: create_1.create,
10
+ defaultOptions: config_1.defaultOptions,
11
+ meta: config_1.config,
12
+ name: config_1.name,
13
+ });
14
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-fc/rule.ts"],"names":[],"mappings":";;;AAAA,wCAA2C;AAE3C,qCAAgF;AAGvE,qFAHkC,aAAI,OAGlC;AAFb,qCAAkC;AAIrB,QAAA,IAAI,GAAG,IAAA,iBAAU,EAAoB;IAC9C,MAAM,EAAN,eAAM;IACN,cAAc,EAAd,uBAAc;IACd,IAAI,EAAE,eAAM;IACZ,IAAI,EAAJ,aAAI;CACP,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { RuleModule } from "@typescript-eslint/utils/ts-eslint";
2
+ export declare const name = "prefer-react-with-hooks";
3
+ export declare const enum Messages {
4
+ PREFER_REACT = "PREFER_REACT",
5
+ PREFER_REACT_PREFIX = "PREFER_REACT_PREFIX"
6
+ }
7
+ export type Options = [];
8
+ type ExtendedPluginProperties = {
9
+ recommended: boolean;
10
+ };
11
+ export declare const config: {
12
+ docs: ExtendedPluginProperties & RuleModule<Messages, Options>["meta"]["docs"];
13
+ } & Omit<RuleModule<Messages, Options>["meta"], "defaultOptions">;
14
+ export declare const defaultOptions: Options;
15
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultOptions = exports.config = exports.Messages = exports.name = void 0;
4
+ exports.name = "prefer-react-with-hooks";
5
+ var Messages;
6
+ (function (Messages) {
7
+ Messages["PREFER_REACT"] = "PREFER_REACT";
8
+ Messages["PREFER_REACT_PREFIX"] = "PREFER_REACT_PREFIX";
9
+ })(Messages || (exports.Messages = Messages = {}));
10
+ exports.config = {
11
+ docs: {
12
+ description: "Enforce React.use* over named use* imports",
13
+ recommended: false,
14
+ url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-react-with-hooks.md",
15
+ },
16
+ fixable: "code",
17
+ messages: {
18
+ [Messages.PREFER_REACT]: "NIMA: Use React.{{hook}} instead of importing {{hook}} directly.",
19
+ [Messages.PREFER_REACT_PREFIX]: "NIMA: Prefix {{hook}} with React.",
20
+ },
21
+ schema: [],
22
+ type: "problem",
23
+ };
24
+ exports.defaultOptions = [];
25
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-with-hooks/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAG,yBAAyB,CAAC;AAE9C,IAAkB,QAGjB;AAHD,WAAkB,QAAQ;IACtB,yCAA6B,CAAA;IAC7B,uDAA2C,CAAA;AAC/C,CAAC,EAHiB,QAAQ,wBAAR,QAAQ,QAGzB;AAQY,QAAA,MAAM,GAGiD;IAChE,IAAI,EAAE;QACF,WAAW,EAAE,4CAA4C;QACzD,WAAW,EAAE,KAAK;QAClB,GAAG,EAAE,iHAAiH;KACzH;IACD,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,CAAC,QAAQ,CAAC,YAAY,CAAC,EACnB,kEAAkE;QACtE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,mCAAmC;KACtE;IACD,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,SAAS;CAClB,CAAC;AAEW,QAAA,cAAc,GAAY,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type TSESTree } from "@typescript-eslint/utils";
2
+ import { RuleContext } from "@typescript-eslint/utils/ts-eslint";
3
+ import { Messages, type Options } from "./config";
4
+ export declare const create: (context: RuleContext<Messages, Options>) => {
5
+ CallExpression: (node: TSESTree.CallExpression) => void;
6
+ ImportDeclaration: (node: TSESTree.ImportDeclaration) => void;
7
+ };
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const hooks_1 = require("../../constants/hooks");
5
+ const utils_1 = require("@typescript-eslint/utils");
6
+ const config_1 = require("./config");
7
+ const create = (context) => {
8
+ const sourceCode = context.sourceCode;
9
+ const program = sourceCode.ast;
10
+ let hasReactImport = false;
11
+ let reactImportNode = null;
12
+ let isAnalysisComplete = false;
13
+ let hasHookImports = false;
14
+ const analyzeImports = () => {
15
+ if (isAnalysisComplete) {
16
+ return;
17
+ }
18
+ for (const node of program.body) {
19
+ if (node.type === utils_1.AST_NODE_TYPES.ImportDeclaration &&
20
+ node.source.value === "react") {
21
+ reactImportNode = node;
22
+ hasReactImport = node.specifiers.some((spec) => spec.type === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier ||
23
+ (spec.type ===
24
+ utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier &&
25
+ spec.local.name === "React"));
26
+ hasHookImports = node.specifiers.some((spec) => spec.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
27
+ spec.imported.type === utils_1.AST_NODE_TYPES.Identifier &&
28
+ hooks_1.REACT_HOOKS.has(spec.imported.name));
29
+ break;
30
+ }
31
+ }
32
+ isAnalysisComplete = true;
33
+ };
34
+ return {
35
+ CallExpression: (node) => {
36
+ if (node.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
37
+ hooks_1.REACT_HOOKS.has(node.callee.name)) {
38
+ analyzeImports();
39
+ const hookName = node.callee.name;
40
+ context.report({
41
+ data: {
42
+ hook: hookName,
43
+ },
44
+ fix: (fixer) => {
45
+ const fixes = [];
46
+ if (!hasHookImports) {
47
+ if (!hasReactImport) {
48
+ if (reactImportNode) {
49
+ const importText = sourceCode.getText(reactImportNode);
50
+ if (importText.includes("{") &&
51
+ !/^import\s+\w+\s*,/.test(importText)) {
52
+ fixes.push(fixer.replaceText(reactImportNode, importText.replace(/^import\s*{/, "import React, {")));
53
+ }
54
+ }
55
+ else {
56
+ fixes.push(fixer.insertTextBefore(program.body.length > 0
57
+ ? program.body[0]
58
+ : node, 'import React from "react";\n'));
59
+ }
60
+ }
61
+ fixes.push(fixer.insertTextBefore(node.callee, "React."));
62
+ }
63
+ return fixes;
64
+ },
65
+ messageId: config_1.Messages.PREFER_REACT_PREFIX,
66
+ node: node.callee,
67
+ });
68
+ }
69
+ },
70
+ ImportDeclaration: (node) => {
71
+ if (node.source.value === "react") {
72
+ reactImportNode = node;
73
+ hasReactImport = node.specifiers.some((spec) => spec.type === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier ||
74
+ (spec.type ===
75
+ utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier &&
76
+ spec.local.name === "React"));
77
+ const useImports = node.specifiers.filter((s) => s.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
78
+ s.imported.type === utils_1.AST_NODE_TYPES.Identifier &&
79
+ hooks_1.REACT_HOOKS.has(s.imported.name));
80
+ if (useImports.length > 0) {
81
+ const firstHookImport = useImports[0];
82
+ const hookNames = useImports
83
+ .map((spec) => spec.imported.type === utils_1.AST_NODE_TYPES.Identifier
84
+ ? spec.imported.name
85
+ : "")
86
+ .filter(Boolean);
87
+ context.report({
88
+ data: {
89
+ hook: hookNames.length === 1
90
+ ? hookNames[0]
91
+ : `${hookNames.slice(0, -1).join(", ")} and ${hookNames.at(-1) ?? ""}`,
92
+ },
93
+ fix: (fixer) => {
94
+ const fixes = [];
95
+ const allCallExpressions = [];
96
+ const traverse = (astNode) => {
97
+ if (!astNode) {
98
+ return;
99
+ }
100
+ if (Array.isArray(astNode)) {
101
+ for (const item of astNode) {
102
+ traverse(item);
103
+ }
104
+ return;
105
+ }
106
+ if (astNode.type ===
107
+ utils_1.AST_NODE_TYPES.CallExpression) {
108
+ allCallExpressions.push(astNode);
109
+ }
110
+ for (const key of Object.keys(astNode)) {
111
+ if (key === "parent" ||
112
+ key === "range" ||
113
+ key === "loc") {
114
+ continue;
115
+ }
116
+ const value = astNode[key];
117
+ if (value && typeof value === "object") {
118
+ traverse(value);
119
+ }
120
+ }
121
+ };
122
+ traverse(program);
123
+ for (const callExpr of allCallExpressions) {
124
+ if (callExpr.callee.type ===
125
+ utils_1.AST_NODE_TYPES.Identifier &&
126
+ hooks_1.REACT_HOOKS.has(callExpr.callee.name)) {
127
+ fixes.push(fixer.insertTextBefore(callExpr.callee, "React."));
128
+ }
129
+ }
130
+ const remainingSpecifiers = node.specifiers.filter((spec) => !(spec.type ===
131
+ utils_1.AST_NODE_TYPES.ImportSpecifier &&
132
+ spec.imported.type ===
133
+ utils_1.AST_NODE_TYPES.Identifier &&
134
+ hooks_1.REACT_HOOKS.has(spec.imported.name)));
135
+ if (remainingSpecifiers.length === 0 &&
136
+ !hasReactImport) {
137
+ fixes.push(fixer.replaceText(node, 'import React from "react";'));
138
+ }
139
+ else if (remainingSpecifiers.length > 0 &&
140
+ !hasReactImport) {
141
+ const nonDefaultSpecifiers = remainingSpecifiers.filter((spec) => spec.type !==
142
+ utils_1.AST_NODE_TYPES.ImportDefaultSpecifier);
143
+ if (nonDefaultSpecifiers.length > 0) {
144
+ const specifierTexts = nonDefaultSpecifiers
145
+ .map((spec) => sourceCode.getText(spec))
146
+ .join(", ");
147
+ fixes.push(fixer.replaceText(node, `import React, { ${specifierTexts} } from "react";`));
148
+ }
149
+ else {
150
+ fixes.push(fixer.replaceText(node, 'import React from "react";'));
151
+ }
152
+ }
153
+ else if (hasReactImport) {
154
+ const hasDefaultReact = remainingSpecifiers.some((spec) => spec.type ===
155
+ utils_1.AST_NODE_TYPES.ImportDefaultSpecifier);
156
+ const namedSpecifiers = remainingSpecifiers.filter((spec) => spec.type ===
157
+ utils_1.AST_NODE_TYPES.ImportSpecifier);
158
+ if (hasDefaultReact &&
159
+ namedSpecifiers.length > 0) {
160
+ const specifierTexts = namedSpecifiers
161
+ .map((spec) => sourceCode.getText(spec))
162
+ .join(", ");
163
+ fixes.push(fixer.replaceText(node, `import React, { ${specifierTexts} } from "react";`));
164
+ }
165
+ else if (hasDefaultReact &&
166
+ namedSpecifiers.length === 0) {
167
+ fixes.push(fixer.replaceText(node, 'import React from "react";'));
168
+ }
169
+ else if (!hasDefaultReact &&
170
+ namedSpecifiers.length > 0) {
171
+ const specifierTexts = namedSpecifiers
172
+ .map((spec) => sourceCode.getText(spec))
173
+ .join(", ");
174
+ fixes.push(fixer.replaceText(node, `import { ${specifierTexts} } from "react";`));
175
+ }
176
+ }
177
+ return fixes;
178
+ },
179
+ messageId: config_1.Messages.PREFER_REACT,
180
+ node: firstHookImport,
181
+ });
182
+ }
183
+ }
184
+ },
185
+ };
186
+ };
187
+ exports.create = create;
188
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-with-hooks/create.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,oDAAyE;AAGzE,qCAAkD;AAE3C,MAAM,MAAM,GAAG,CAAC,OAAuC,EAAE,EAAE;IAC9D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC;IAE/B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,eAAe,GAAsC,IAAI,CAAC;IAC9D,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAC/B,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,cAAc,GAAG,GAAG,EAAE;QACxB,IAAI,kBAAkB,EAAE,CAAC;YACrB,OAAO;QACX,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAC9B,IACI,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;gBAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,OAAO,EAC/B,CAAC;gBACC,eAAe,GAAG,IAAI,CAAC;gBACvB,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACjC,CAAC,IAAI,EAAE,EAAE,CACL,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,sBAAsB;oBACnD,CAAC,IAAI,CAAC,IAAI;wBACN,sBAAc,CAAC,wBAAwB;wBACvC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CACvC,CAAC;gBACF,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACjC,CAAC,IAAI,EAAE,EAAE,CACL,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,eAAe;oBAC5C,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,sBAAc,C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K,CAAC,IAAI,CACN,KAAK,CAAC,WAAW,CACb,IAAI,EACJ,4BAA4B,CAC/B,CACJ,CAAC;gCACN,CAAC;qCAAM,IACH,CAAC,eAAe;oCAChB,eAAe,CAAC,MAAM,GAAG,CAAC,EAC5B,CAAC;oCACC,MAAM,cAAc,GAAG,eAAe;yCACjC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;yCACvC,IAAI,CAAC,IAAI,CAAC,CAAC;oCAChB,KAAK,CAAC,IAAI,CACN,KAAK,CAAC,WAAW,CACb,IAAI,EACJ,YAAY,cAAc,kBAAkB,CAC/C,CACJ,CAAC;gCACN,CAAC;4BACL,CAAC;4BAED,OAAO,KAAK,CAAC;wBACjB,CAAC;wBACD,SAAS,EAAE,iBAAQ,CAAC,YAAY;wBAChC,IAAI,EAAE,eAAe;qBACxB,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AA7TW,QAAA,MAAM,UA6TjB"}
@@ -0,0 +1,2 @@
1
+ export { config, Messages } from "./config";
2
+ export * from "./rule";
@@ -0,0 +1,22 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Messages = exports.config = void 0;
18
+ var config_1 = require("./config");
19
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
20
+ Object.defineProperty(exports, "Messages", { enumerable: true, get: function () { return config_1.Messages; } });
21
+ __exportStar(require("./rule"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-with-hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACzB,yCAAuB"}
@@ -1,5 +1,5 @@
1
- import { Messages } from "../models/prefer-export-under-component.model";
2
- export declare const name = "prefer-export-under-component";
1
+ import { Messages, name } from "./config";
2
+ export { name };
3
3
  export declare const rule: import("@typescript-eslint/utils/ts-eslint").RuleModule<Messages, [], {
4
4
  recommended: boolean;
5
5
  }, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rule = exports.name = void 0;
4
+ const core_1 = require("../../utility/core");
5
+ const config_1 = require("./config");
6
+ Object.defineProperty(exports, "name", { enumerable: true, get: function () { return config_1.name; } });
7
+ const create_1 = require("./create");
8
+ exports.rule = (0, core_1.createRule)({
9
+ create: create_1.create,
10
+ defaultOptions: config_1.defaultOptions,
11
+ meta: config_1.config,
12
+ name: config_1.name,
13
+ });
14
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-with-hooks/rule.ts"],"names":[],"mappings":";;;AAAA,wCAA2C;AAE3C,qCAAgF;AAGvE,qFAHkC,aAAI,OAGlC;AAFb,qCAAkC;AAIrB,QAAA,IAAI,GAAG,IAAA,iBAAU,EAAoB;IAC9C,MAAM,EAAN,eAAM;IACN,cAAc,EAAd,uBAAc;IACd,IAAI,EAAE,eAAM;IACZ,IAAI,EAAJ,aAAI;CACP,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { RuleModule } from "@typescript-eslint/utils/ts-eslint";
2
+ export declare const name = "prefer-void-for-optional-param";
3
+ export declare const enum Messages {
4
+ ADD_VOID_UNION = "ADD_VOID_UNION",
5
+ PREFER_VOID_FOR_OPTIONAL_PARAM = "PREFER_VOID_FOR_OPTIONAL_PARAM"
6
+ }
7
+ export type Options = [];
8
+ type ExtendedPluginProperties = {
9
+ recommended: boolean;
10
+ };
11
+ export declare const config: {
12
+ docs: ExtendedPluginProperties & RuleModule<Messages, Options>["meta"]["docs"];
13
+ } & Omit<RuleModule<Messages, Options>["meta"], "defaultOptions">;
14
+ export declare const defaultOptions: Options;
15
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultOptions = exports.config = exports.Messages = exports.name = void 0;
4
+ exports.name = "prefer-void-for-optional-param";
5
+ var Messages;
6
+ (function (Messages) {
7
+ Messages["ADD_VOID_UNION"] = "ADD_VOID_UNION";
8
+ Messages["PREFER_VOID_FOR_OPTIONAL_PARAM"] = "PREFER_VOID_FOR_OPTIONAL_PARAM";
9
+ })(Messages || (exports.Messages = Messages = {}));
10
+ exports.config = {
11
+ docs: {
12
+ description: "Enforce void union type for optional parameters and destructure them in the function body",
13
+ recommended: false,
14
+ url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-void-for-optional-param.md",
15
+ },
16
+ fixable: "code",
17
+ messages: {
18
+ [Messages.ADD_VOID_UNION]: "NIMA: Destructure parameters inside function body and add | void to the parameter type.",
19
+ [Messages.PREFER_VOID_FOR_OPTIONAL_PARAM]: "NIMA: Destructure parameters inside function body with ?? {} instead of in parameter list.",
20
+ },
21
+ schema: [],
22
+ type: "suggestion",
23
+ };
24
+ exports.defaultOptions = [];
25
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/rules/prefer-void-for-optional-param/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAG,gCAAgC,CAAC;AAErD,IAAkB,QAGjB;AAHD,WAAkB,QAAQ;IACtB,6CAAiC,CAAA;IACjC,6EAAiE,CAAA;AACrE,CAAC,EAHiB,QAAQ,wBAAR,QAAQ,QAGzB;AAQY,QAAA,MAAM,GAGiD;IAChE,IAAI,EAAE;QACF,WAAW,EACP,2FAA2F;QAC/F,WAAW,EAAE,KAAK;QAClB,GAAG,EAAE,wHAAwH;KAChI;IACD,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,CAAC,QAAQ,CAAC,cAAc,CAAC,EACrB,yFAAyF;QAC7F,CAAC,QAAQ,CAAC,8BAA8B,CAAC,EACrC,4FAA4F;KACnG;IACD,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,YAAY;CACrB,CAAC;AAEW,QAAA,cAAc,GAAY,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type TSESTree } from "@typescript-eslint/utils";
2
+ import { RuleContext } from "@typescript-eslint/utils/ts-eslint";
3
+ import { Messages, type Options } from "./config";
4
+ export declare const create: (context: RuleContext<Messages, Options>) => {
5
+ ArrowFunctionExpression: (node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => void;
6
+ FunctionDeclaration: (node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => void;
7
+ FunctionExpression: (node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => void;
8
+ };