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,67 @@
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-arrow-functions";
5
+ var Messages;
6
+ (function (Messages) {
7
+ Messages["PREFER_ARROW_FUNCTION_EXPRESSION"] = "PREFER_ARROW_FUNCTION_EXPRESSION";
8
+ Messages["PREFER_ARROW_FUNCTIONS"] = "PREFER_ARROW_FUNCTIONS";
9
+ Messages["PREFER_ARROW_METHOD"] = "PREFER_ARROW_METHOD";
10
+ })(Messages || (exports.Messages = Messages = {}));
11
+ exports.config = {
12
+ docs: {
13
+ description: "Prefer arrow functions over function declarations and expressions",
14
+ recommended: true,
15
+ url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-arrow-functions.md",
16
+ },
17
+ fixable: "code",
18
+ messages: {
19
+ [Messages.PREFER_ARROW_FUNCTION_EXPRESSION]: "NIMA: Prefer arrow functions over function expressions.",
20
+ [Messages.PREFER_ARROW_FUNCTIONS]: "NIMA: Prefer arrow functions over function declarations.",
21
+ [Messages.PREFER_ARROW_METHOD]: "NIMA: Prefer arrow functions over method definitions.",
22
+ },
23
+ schema: [
24
+ {
25
+ additionalProperties: false,
26
+ properties: {
27
+ allowAsync: {
28
+ description: "Allow async functions (they can still be arrow functions)",
29
+ type: "boolean",
30
+ },
31
+ allowConstructors: {
32
+ description: "Allow constructor functions",
33
+ type: "boolean",
34
+ },
35
+ allowFunctionDeclarations: {
36
+ description: "Allow function declarations (function name() {})",
37
+ type: "boolean",
38
+ },
39
+ allowFunctionExpressions: {
40
+ description: "Allow function expressions (const name = function() {})",
41
+ type: "boolean",
42
+ },
43
+ allowGenerators: {
44
+ description: "Allow generator functions",
45
+ type: "boolean",
46
+ },
47
+ allowMethodDefinitions: {
48
+ description: "Allow method definitions in classes and objects",
49
+ type: "boolean",
50
+ },
51
+ },
52
+ type: "object",
53
+ },
54
+ ],
55
+ type: "suggestion",
56
+ };
57
+ exports.defaultOptions = [
58
+ {
59
+ allowAsync: true,
60
+ allowConstructors: true,
61
+ allowFunctionDeclarations: false,
62
+ allowFunctionExpressions: false,
63
+ allowGenerators: true,
64
+ allowMethodDefinitions: false,
65
+ },
66
+ ];
67
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/rules/prefer-arrow-functions/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAG,wBAAwB,CAAC;AAE7C,IAAkB,QAIjB;AAJD,WAAkB,QAAQ;IACtB,iFAAqE,CAAA;IACrE,6DAAiD,CAAA;IACjD,uDAA2C,CAAA;AAC/C,CAAC,EAJiB,QAAQ,wBAAR,QAAQ,QAIzB;AAiBY,QAAA,MAAM,GAGiD;IAChE,IAAI,EAAE;QACF,WAAW,EACP,mEAAmE;QACvE,WAAW,EAAE,IAAI;QACjB,GAAG,EAAE,gHAAgH;KACxH;IACD,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,CAAC,QAAQ,CAAC,gCAAgC,CAAC,EACvC,yDAAyD;QAC7D,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAC7B,0DAA0D;QAC9D,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAC1B,uDAAuD;KAC9D;IACD,MAAM,EAAE;QACJ;YACI,oBAAoB,EAAE,KAAK;YAC3B,UAAU,EAAE;gBACR,UAAU,EAAE;oBACR,WAAW,EACP,2DAA2D;oBAC/D,IAAI,EAAE,SAAS;iBAClB;gBACD,iBAAiB,EAAE;oBACf,WAAW,EAAE,6BAA6B;oBAC1C,IAAI,EAAE,SAAS;iBAClB;gBACD,yBAAyB,EAAE;oBACvB,WAAW,EACP,kDAAkD;oBACtD,IAAI,EAAE,SAAS;iBAClB;gBACD,wBAAwB,EAAE;oBACtB,WAAW,EACP,yDAAyD;oBAC7D,IAAI,EAAE,SAAS;iBAClB;gBACD,eAAe,EAAE;oBACb,WAAW,EAAE,2BAA2B;oBACxC,IAAI,EAAE,SAAS;iBAClB;gBACD,sBAAsB,EAAE;oBACpB,WAAW,EACP,iDAAiD;oBACrD,IAAI,EAAE,SAAS;iBAClB;aACJ;YACD,IAAI,EAAE,QAAQ;SACjB;KACJ;IACD,IAAI,EAAE,YAAY;CACrB,CAAC;AAEW,QAAA,cAAc,GAAY;IACnC;QACI,UAAU,EAAE,IAAI;QAChB,iBAAiB,EAAE,IAAI;QACvB,yBAAyB,EAAE,KAAK;QAChC,wBAAwB,EAAE,KAAK;QAC/B,eAAe,EAAE,IAAI;QACrB,sBAAsB,EAAE,KAAK;KAChC;CACJ,CAAC"}
@@ -0,0 +1,9 @@
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>, [options]: readonly Options[number][]) => {
5
+ FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void;
6
+ FunctionExpression: (node: TSESTree.FunctionExpression) => void;
7
+ MethodDefinition: (node: TSESTree.MethodDefinition) => void;
8
+ Property: (node: TSESTree.Property) => void;
9
+ };
@@ -0,0 +1,150 @@
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 config_1 = require("./config");
6
+ const create = (context, [options]) => {
7
+ const { allowAsync = true, allowConstructors = true, allowFunctionDeclarations = false, allowFunctionExpressions = false, allowGenerators = true, allowMethodDefinitions = false, } = options;
8
+ const sourceCode = context.sourceCode;
9
+ const shouldSkipFunction = (node) => {
10
+ if (allowConstructors &&
11
+ node.parent?.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
12
+ node.parent.kind === "constructor") {
13
+ return true;
14
+ }
15
+ if (allowGenerators && node?.generator) {
16
+ return true;
17
+ }
18
+ if (allowAsync && node?.async) {
19
+ return true;
20
+ }
21
+ if (node.type === utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
22
+ return true;
23
+ }
24
+ return false;
25
+ };
26
+ const generateArrowFunction = (node) => {
27
+ const asyncKeyword = node.async ? "async " : "";
28
+ const getParams = () => {
29
+ if (node.params.length === 0) {
30
+ return "()";
31
+ }
32
+ if (node.params.length === 1 &&
33
+ node.params[0].type === utils_1.AST_NODE_TYPES.Identifier &&
34
+ !node.params[0].typeAnnotation) {
35
+ return sourceCode.getText(node.params[0]);
36
+ }
37
+ return `(${node.params.map((p) => sourceCode.getText(p)).join(", ")})`;
38
+ };
39
+ const params = getParams();
40
+ const returnType = node.returnType
41
+ ? `: ${sourceCode.getText(node.returnType.typeAnnotation)}`
42
+ : "";
43
+ const body = node.body ? sourceCode.getText(node.body) : "";
44
+ return `${asyncKeyword}${params}${returnType} => ${body}`;
45
+ };
46
+ return {
47
+ FunctionDeclaration: (node) => {
48
+ if (allowFunctionDeclarations || shouldSkipFunction(node)) {
49
+ return;
50
+ }
51
+ context.report({
52
+ fix: (fixer) => {
53
+ if (!node.id) {
54
+ return null;
55
+ }
56
+ const functionName = node.id.name;
57
+ const arrowFunction = generateArrowFunction(node);
58
+ let replacement;
59
+ if (node.parent?.type ===
60
+ utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
61
+ const constDeclaration = `const ${functionName} = ${arrowFunction}`;
62
+ const exportDeclaration = `export default ${functionName}`;
63
+ replacement = `${constDeclaration};\n${exportDeclaration}`;
64
+ return fixer.replaceText(node.parent, replacement);
65
+ }
66
+ else if (node.parent?.type ===
67
+ utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
68
+ replacement = `export const ${functionName} = ${arrowFunction}`;
69
+ return fixer.replaceText(node.parent, replacement);
70
+ }
71
+ else {
72
+ replacement = `const ${functionName} = ${arrowFunction}`;
73
+ return fixer.replaceText(node, replacement);
74
+ }
75
+ },
76
+ messageId: config_1.Messages.PREFER_ARROW_FUNCTIONS,
77
+ node: node.id || node,
78
+ });
79
+ },
80
+ FunctionExpression: (node) => {
81
+ if ((node.parent?.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
82
+ (node.parent?.type === utils_1.AST_NODE_TYPES.Property &&
83
+ (node.parent.method || !node.parent.method))) &&
84
+ allowMethodDefinitions) {
85
+ return;
86
+ }
87
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.Property &&
88
+ node.parent.method) {
89
+ return;
90
+ }
91
+ if (allowFunctionExpressions || shouldSkipFunction(node)) {
92
+ return;
93
+ }
94
+ context.report({
95
+ fix: (fixer) => {
96
+ const arrowFunction = generateArrowFunction(node);
97
+ return fixer.replaceText(node, arrowFunction);
98
+ },
99
+ messageId: config_1.Messages.PREFER_ARROW_FUNCTION_EXPRESSION,
100
+ node,
101
+ });
102
+ },
103
+ MethodDefinition: (node) => {
104
+ if (allowMethodDefinitions ||
105
+ node.kind === "constructor" ||
106
+ node.kind === "get" ||
107
+ node.kind === "set") {
108
+ return;
109
+ }
110
+ if (node.value.type === utils_1.AST_NODE_TYPES.FunctionExpression &&
111
+ !shouldSkipFunction(node.value)) {
112
+ context.report({
113
+ fix: (fixer) => {
114
+ const key = sourceCode.getText(node.key);
115
+ const arrowFunction = generateArrowFunction(node.value);
116
+ const static_ = node.static ? "static " : "";
117
+ const replacement = `${static_}${key} = ${arrowFunction}`;
118
+ return fixer.replaceText(node, replacement);
119
+ },
120
+ messageId: config_1.Messages.PREFER_ARROW_METHOD,
121
+ node: node.key,
122
+ });
123
+ }
124
+ },
125
+ Property: (node) => {
126
+ if (allowMethodDefinitions ||
127
+ !node.method ||
128
+ node.kind === "get" ||
129
+ node.kind === "set" ||
130
+ node.value.type !== utils_1.AST_NODE_TYPES.FunctionExpression) {
131
+ return;
132
+ }
133
+ const functionNode = node.value;
134
+ if (!shouldSkipFunction(functionNode)) {
135
+ context.report({
136
+ fix: (fixer) => {
137
+ const key = sourceCode.getText(node.key);
138
+ const arrowFunction = generateArrowFunction(functionNode);
139
+ const replacement = `${key}: ${arrowFunction}`;
140
+ return fixer.replaceText(node, replacement);
141
+ },
142
+ messageId: config_1.Messages.PREFER_ARROW_METHOD,
143
+ node: node.key,
144
+ });
145
+ }
146
+ },
147
+ };
148
+ };
149
+ exports.create = create;
150
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/rules/prefer-arrow-functions/create.ts"],"names":[],"mappings":";;;AAAA,oDAAyE;AAGzE,qCAAkD;AAE3C,MAAM,MAAM,GAAG,CAClB,OAAuC,EACvC,CAAC,OAAO,CAA6B,EACvC,EAAE;IACA,MAAM,EACF,UAAU,GAAG,IAAI,EACjB,iBAAiB,GAAG,IAAI,EACxB,yBAAyB,GAAG,KAAK,EACjC,wBAAwB,GAAG,KAAK,EAChC,eAAe,GAAG,IAAI,EACtB,sBAAsB,GAAG,KAAK,GACjC,GAAG,OAAO,CAAC;IAEZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAEtC,MAAM,kBAAkB,GAAG,CAAC,IAA2B,EAAE,EAAE;QACvD,IACI,iBAAiB;YACjB,IAAI,CAAC,MAAM,EAAE,IAAI,KAAK,sBAAc,CAAC,gBAAgB;YACrD,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa,EACpC,CAAC;YACC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,eAAe,IAAI,IAAI,EAAE,SAAS,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,UAAU,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,6BAA6B,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,CAAC,IAA2B,EAAE,EAAE;QAC1D,MAAM,Y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AAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;oBAChD,CAAC;oBACD,SAAS,EAAE,iBAAQ,CAAC,mBAAmB;oBACvC,IAAI,EAAE,IAAI,CAAC,GAAG;iBACjB,CAAC,CAAC;YACP,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AAxLW,QAAA,MAAM,UAwLjB"}
@@ -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-arrow-functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACzB,yCAAuB"}
@@ -1,5 +1,5 @@
1
- import { Messages, Options } from "../models/restrict-function-usage.model";
2
- export declare const name = "restrict-function-usage";
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-arrow-functions/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,14 @@
1
+ import { RuleModule } from "@typescript-eslint/utils/ts-eslint";
2
+ export declare const name = "prefer-export-under-component";
3
+ export declare const enum Messages {
4
+ EXPORT_BELOW_COMPONENT = "EXPORT_BELOW_COMPONENT"
5
+ }
6
+ export type Options = [];
7
+ type ExtendedPluginProperties = {
8
+ recommended: boolean;
9
+ };
10
+ export declare const config: {
11
+ docs: ExtendedPluginProperties & RuleModule<Messages, Options>["meta"]["docs"];
12
+ } & Omit<RuleModule<Messages, Options>["meta"], "defaultOptions">;
13
+ export declare const defaultOptions: Options;
14
+ export {};
@@ -0,0 +1,23 @@
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-export-under-component";
5
+ var Messages;
6
+ (function (Messages) {
7
+ Messages["EXPORT_BELOW_COMPONENT"] = "EXPORT_BELOW_COMPONENT";
8
+ })(Messages || (exports.Messages = Messages = {}));
9
+ exports.config = {
10
+ docs: {
11
+ description: "Enforce separate declaration and export for React components",
12
+ recommended: true,
13
+ url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-export-under-component.md",
14
+ },
15
+ fixable: "code",
16
+ messages: {
17
+ [Messages.EXPORT_BELOW_COMPONENT]: "NIMA: Declare React component '{{ fnName }}' separately from its export statement",
18
+ },
19
+ schema: [],
20
+ type: "problem",
21
+ };
22
+ exports.defaultOptions = [];
23
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/rules/prefer-export-under-component/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAG,+BAA+B,CAAC;AAEpD,IAAkB,QAEjB;AAFD,WAAkB,QAAQ;IACtB,6DAAiD,CAAA;AACrD,CAAC,EAFiB,QAAQ,wBAAR,QAAQ,QAEzB;AAQY,QAAA,MAAM,GAGiD;IAChE,IAAI,EAAE;QACF,WAAW,EACP,8DAA8D;QAClE,WAAW,EAAE,IAAI;QACjB,GAAG,EAAE,uHAAuH;KAC/H;IACD,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAC7B,mFAAmF;KAC1F;IACD,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,SAAS;CAClB,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
+ ExportDefaultDeclaration: (node: TSESTree.ExportDefaultDeclaration) => void;
6
+ ExportNamedDeclaration: (node: TSESTree.ExportNamedDeclaration) => void;
7
+ FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void;
8
+ };
@@ -0,0 +1,99 @@
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
+ return {
9
+ ExportDefaultDeclaration: (node) => {
10
+ if (node.declaration.type !== utils_1.AST_NODE_TYPES.FunctionDeclaration) {
11
+ return;
12
+ }
13
+ const fnName = node.declaration.id?.name;
14
+ if (fnName &&
15
+ (0, function_helpers_1.isComponentFunction)(fnName) &&
16
+ (0, function_helpers_1.isReactReturn)(node.declaration)) {
17
+ context.report({
18
+ data: {
19
+ fnName,
20
+ },
21
+ fix: (fixer) => {
22
+ const sourceCode = context.sourceCode;
23
+ const text = sourceCode.getText(node);
24
+ const newText = text.replace(/^export\s+default\s+/, "");
25
+ return [
26
+ fixer.replaceText(node, newText),
27
+ fixer.insertTextAfter(node, `\n\nexport { ${fnName} };`),
28
+ ];
29
+ },
30
+ messageId: config_1.Messages.EXPORT_BELOW_COMPONENT,
31
+ node,
32
+ });
33
+ }
34
+ },
35
+ ExportNamedDeclaration: (node) => {
36
+ if (!node.declaration) {
37
+ return;
38
+ }
39
+ if (node.declaration.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
40
+ const declarator = node.declaration.declarations[0];
41
+ if (!declarator.init) {
42
+ return;
43
+ }
44
+ const fnNode = declarator.init;
45
+ if (fnNode.type !== utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
46
+ fnNode.type !== utils_1.AST_NODE_TYPES.FunctionExpression) {
47
+ return;
48
+ }
49
+ const fnName = (0, function_helpers_1.getFunctionName)(fnNode);
50
+ if (fnName &&
51
+ (0, function_helpers_1.isComponentFunction)(fnName) &&
52
+ (0, function_helpers_1.isReactReturn)(fnNode)) {
53
+ context.report({
54
+ data: {
55
+ fnName,
56
+ },
57
+ fix: (fixer) => {
58
+ const sourceCode = context.sourceCode;
59
+ const text = sourceCode.getText(node);
60
+ const newText = text.replace(/^export\s+/, "");
61
+ return [
62
+ fixer.replaceText(node, newText),
63
+ fixer.insertTextAfter(node, `\n\nexport { ${fnName} };`),
64
+ ];
65
+ },
66
+ messageId: config_1.Messages.EXPORT_BELOW_COMPONENT,
67
+ node,
68
+ });
69
+ }
70
+ }
71
+ },
72
+ FunctionDeclaration: (node) => {
73
+ if (node.parent?.type !== utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
74
+ return;
75
+ }
76
+ const fnName = (0, function_helpers_1.getFunctionName)(node);
77
+ if (fnName && (0, function_helpers_1.isComponentFunction)(fnName) && (0, function_helpers_1.isReactReturn)(node)) {
78
+ context.report({
79
+ data: {
80
+ fnName,
81
+ },
82
+ fix: (fixer) => {
83
+ const sourceCode = context.sourceCode;
84
+ const text = sourceCode.getText(node.parent);
85
+ const newText = text.replace(/^export\s+/, "");
86
+ return [
87
+ fixer.replaceText(node.parent, newText),
88
+ fixer.insertTextAfter(node.parent, `\n\nexport { ${fnName} };`),
89
+ ];
90
+ },
91
+ messageId: config_1.Messages.EXPORT_BELOW_COMPONENT,
92
+ node: node.parent,
93
+ });
94
+ }
95
+ },
96
+ };
97
+ };
98
+ exports.create = create;
99
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/rules/prefer-export-under-component/create.ts"],"names":[],"mappings":";;;AAAA,oDAAyE;AAEzE,gEAImC;AAEnC,qCAAkD;AAE3C,MAAM,MAAM,GAAG,CAAC,OAAuC,EAAE,EAAE;IAC9D,OAAO;QACH,wBAAwB,EAAE,CA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,EAAC,IAAI,CAAC,EAAE,CAAC;gBAC/D,OAAO,CAAC,MAAM,CAAC;oBACX,IAAI,EAAE;wBACF,MAAM;qBACT;oBACD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;wBACX,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;wBACtC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;wBAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;wBAE/C,OAAO;4BACH,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;4BACvC,KAAK,CAAC,eAAe,CACjB,IAAI,CAAC,MAAM,EACX,gBAAgB,MAAM,KAAK,CAC9B;yBACJ,CAAC;oBACN,CAAC;oBACD,SAAS,EAAE,iBAAQ,CAAC,sBAAsB;oBAC1C,IAAI,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC,CAAC;YACP,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AAtHW,QAAA,MAAM,UAsHjB"}
@@ -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-export-under-component/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-react-with-hooks.model";
2
- export declare const name = "prefer-react-with-hooks";
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-export-under-component/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,19 @@
1
+ import { RuleModule } from "@typescript-eslint/utils/ts-eslint";
2
+ export declare const name = "prefer-react-fc";
3
+ export declare const enum Messages {
4
+ REQUIRE_REACT_FC = "REQUIRE_REACT_FC"
5
+ }
6
+ export type Options = [
7
+ Partial<{
8
+ allowArrowFunctions: boolean;
9
+ allowFunctionDeclarations: boolean;
10
+ }>
11
+ ];
12
+ type ExtendedPluginProperties = {
13
+ recommended: boolean;
14
+ };
15
+ export declare const config: {
16
+ docs: ExtendedPluginProperties & RuleModule<Messages, Options>["meta"]["docs"];
17
+ } & Omit<RuleModule<Messages, Options>["meta"], "defaultOptions">;
18
+ export declare const defaultOptions: Options;
19
+ export {};
@@ -0,0 +1,43 @@
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-fc";
5
+ var Messages;
6
+ (function (Messages) {
7
+ Messages["REQUIRE_REACT_FC"] = "REQUIRE_REACT_FC";
8
+ })(Messages || (exports.Messages = Messages = {}));
9
+ exports.config = {
10
+ docs: {
11
+ description: "Enforce React.FC type annotation for React component functions",
12
+ recommended: true,
13
+ url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-react-fc.md",
14
+ },
15
+ fixable: "code",
16
+ messages: {
17
+ [Messages.REQUIRE_REACT_FC]: "NIMA: Component functions must use React.FC type annotation.",
18
+ },
19
+ schema: [
20
+ {
21
+ additionalProperties: false,
22
+ properties: {
23
+ allowArrowFunctions: {
24
+ description: "Allow arrow function components",
25
+ type: "boolean",
26
+ },
27
+ allowFunctionDeclarations: {
28
+ description: "Allow function declaration components",
29
+ type: "boolean",
30
+ },
31
+ },
32
+ type: "object",
33
+ },
34
+ ],
35
+ type: "problem",
36
+ };
37
+ exports.defaultOptions = [
38
+ {
39
+ allowArrowFunctions: true,
40
+ allowFunctionDeclarations: true,
41
+ },
42
+ ];
43
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/rules/prefer-react-fc/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,IAAI,GAAG,iBAAiB,CAAC;AAEtC,IAAkB,QAEjB;AAFD,WAAkB,QAAQ;IACtB,iDAAqC,CAAA;AACzC,CAAC,EAFiB,QAAQ,wBAAR,QAAQ,QAEzB;AAaY,QAAA,MAAM,GAGiD;IAChE,IAAI,EAAE;QACF,WAAW,EACP,gEAAgE;QACpE,WAAW,EAAE,IAAI;QACjB,GAAG,EAAE,yGAAyG;KACjH;IACD,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EACvB,8DAA8D;KACrE;IACD,MAAM,EAAE;QACJ;YACI,oBAAoB,EAAE,KAAK;YAC3B,UAAU,EAAE;gBACR,mBAAmB,EAAE;oBACjB,WAAW,EAAE,iCAAiC;oBAC9C,IAAI,EAAE,SAAS;iBAClB;gBACD,yBAAyB,EAAE;oBACvB,WAAW,EAAE,uCAAuC;oBACpD,IAAI,EAAE,SAAS;iBAClB;aACJ;YACD,IAAI,EAAE,QAAQ;SACjB;KACJ;IACD,IAAI,EAAE,SAAS;CAClB,CAAC;AAEW,QAAA,cAAc,GAAY;IACnC;QACI,mBAAmB,EAAE,IAAI;QACzB,yBAAyB,EAAE,IAAI;KAClC;CACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { 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) => void;
6
+ FunctionDeclaration: (node: TSESTree.FunctionDeclaration) => void;
7
+ FunctionExpression: (node: TSESTree.FunctionExpression) => void;
8
+ };