eslint-plugin-nima 1.2.3 → 1.2.5

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 (222) hide show
  1. package/README.md +26 -23
  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 +29 -22
  6. package/dist/index.js +13 -55
  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-react-with-hooks/rule.d.ts +5 -0
  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 +22 -22
  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 +8 -7
  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 -9
  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/restrict-console-methods.model.d.ts +0 -8
  189. package/dist/models/restrict-console-methods.model.js +0 -8
  190. package/dist/models/restrict-console-methods.model.js.map +0 -1
  191. package/dist/models/restrict-function-usage.model.d.ts +0 -11
  192. package/dist/models/restrict-function-usage.model.js +0 -8
  193. package/dist/models/restrict-function-usage.model.js.map +0 -1
  194. package/dist/models/restrict-imports.model.d.ts +0 -12
  195. package/dist/models/restrict-imports.model.js +0 -8
  196. package/dist/models/restrict-imports.model.js.map +0 -1
  197. package/dist/rules/boolean-naming-convention.d.ts +0 -5
  198. package/dist/rules/boolean-naming-convention.js +0 -387
  199. package/dist/rules/boolean-naming-convention.js.map +0 -1
  200. package/dist/rules/no-handler-suffix.js +0 -90
  201. package/dist/rules/no-handler-suffix.js.map +0 -1
  202. package/dist/rules/no-objects-in-deps.js +0 -90
  203. package/dist/rules/no-objects-in-deps.js.map +0 -1
  204. package/dist/rules/params-naming-convention.d.ts +0 -5
  205. package/dist/rules/params-naming-convention.js +0 -95
  206. package/dist/rules/params-naming-convention.js.map +0 -1
  207. package/dist/rules/prefer-arrow-functions.js +0 -211
  208. package/dist/rules/prefer-arrow-functions.js.map +0 -1
  209. package/dist/rules/prefer-export-under-component.d.ts +0 -5
  210. package/dist/rules/prefer-export-under-component.js +0 -115
  211. package/dist/rules/prefer-export-under-component.js.map +0 -1
  212. package/dist/rules/prefer-react-fc.js +0 -207
  213. package/dist/rules/prefer-react-fc.js.map +0 -1
  214. package/dist/rules/prefer-react-with-hooks.js +0 -185
  215. package/dist/rules/prefer-react-with-hooks.js.map +0 -1
  216. package/dist/rules/restrict-console-methods.d.ts +0 -5
  217. package/dist/rules/restrict-console-methods.js +0 -66
  218. package/dist/rules/restrict-console-methods.js.map +0 -1
  219. package/dist/rules/restrict-function-usage.js +0 -121
  220. package/dist/rules/restrict-function-usage.js.map +0 -1
  221. package/dist/rules/restrict-imports.js +0 -135
  222. package/dist/rules/restrict-imports.js.map +0 -1
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rule = exports.name = void 0;
4
- const params_naming_convention_model_1 = require("../models/params-naming-convention.model");
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const core_1 = require("../utility/core");
7
- const function_helpers_1 = require("../utility/function-helpers");
8
- exports.name = "params-naming-convention";
9
- exports.rule = (0, core_1.createRule)({
10
- create: (context, [options]) => {
11
- const { allowedParameters = 1, ignore = ["e"], ignoreFunctions = ["reduce"], ignorePrefixes = ["$"], } = options;
12
- function checkParams(node) {
13
- const parameters = node.params;
14
- const fnName = (0, function_helpers_1.getFunctionName)(node);
15
- if (parameters.length <= allowedParameters) {
16
- return;
17
- }
18
- if (fnName && ignoreFunctions.includes(fnName)) {
19
- return;
20
- }
21
- if (parameters.length === 1 &&
22
- parameters[0].type === utils_1.AST_NODE_TYPES.ObjectPattern)
23
- return;
24
- if (parameters.length > 1 &&
25
- parameters[1].type === utils_1.AST_NODE_TYPES.Identifier &&
26
- parameters[1].name === "index") {
27
- return;
28
- }
29
- const identifiers = parameters.filter((p) => p.type === utils_1.AST_NODE_TYPES.Identifier);
30
- const parameterNames = identifiers.filter((p) => !ignore.includes(p.name) &&
31
- !(ignorePrefixes === null || ignorePrefixes === void 0 ? void 0 : ignorePrefixes.some((prefix) => p.name.startsWith(prefix))));
32
- const suggestedParameters = ignorePrefixes.flatMap((ignoredPrefix) => parameterNames
33
- .slice(-(parameterNames.length - allowedParameters))
34
- .map((parameter) => ignoredPrefix + parameter.name));
35
- if (parameterNames.length > 0) {
36
- context.report({
37
- data: {
38
- count: suggestedParameters.length.toString(),
39
- params: suggestedParameters.join(", "),
40
- },
41
- messageId: params_naming_convention_model_1.Messages.USE_OBJECT_PARAMETERS,
42
- node,
43
- });
44
- }
45
- }
46
- return {
47
- "FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": checkParams,
48
- };
49
- },
50
- defaultOptions: [
51
- {
52
- allowedParameters: 1,
53
- ignore: ["e"],
54
- ignoreFunctions: ["reduce"],
55
- ignorePrefixes: ["$"],
56
- },
57
- ],
58
- meta: {
59
- docs: {
60
- description: "Enforce using a single object parameter for all functions",
61
- recommended: false,
62
- url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/params-naming-convention.md",
63
- },
64
- messages: {
65
- [params_naming_convention_model_1.Messages.USE_OBJECT_PARAMETERS]: "NIMA: Function has {{count}} extra parameter(s). Either prefix them: {{params}}, or put all parameters in one object.",
66
- },
67
- schema: [
68
- {
69
- additionalProperties: false,
70
- properties: {
71
- allowedParameters: {
72
- default: 1,
73
- type: "number",
74
- },
75
- ignore: {
76
- items: { type: "string" },
77
- type: "array",
78
- },
79
- ignoreFunctions: {
80
- items: { type: "string" },
81
- type: "array",
82
- },
83
- ignorePrefixes: {
84
- items: { type: "string" },
85
- type: "array",
86
- },
87
- },
88
- type: "object",
89
- },
90
- ],
91
- type: "problem",
92
- },
93
- name: exports.name,
94
- });
95
- //# sourceMappingURL=params-naming-convention.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"params-naming-convention.js","sourceRoot":"","sources":["../../src/rules/params-naming-convention.ts"],"names":[],"mappings":";;;AAAA,2FAAgF;AAChF,oDAAyE;AACzE,wCAA2C;AAC3C,gEAA4D;AAE/C,QAAA,IAAI,GAAG,0BAA0B,CAAC;AAElC,QAAA,IAAI,GAAG,IAAA,iBAAU,EAAoB;IAChD,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE;QAC7B,MAAM,EACJ,iBAAiB,GAAG,CAAC,EACrB,MAAM,GAAG,CAAC,GAAG,CAAC,EACd,eAAe,GAAG,CAAC,QAAQ,CAAC,EAC5B,cAAc,GAAG,CAAC,GAAG,CAAC,GACvB,GAAG,OAAO,CAAC;QAEZ,SAAS,WAAW,CAAC,IAA2B;YAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAA,kCAAe,EAAC,IAAI,CAAC,CAAC;YAErC,IAAI,UAAU,CAAC,MAAM,IAAI,iBAAiB,EAAE,CAAC;gBAC3C,OAAO;YACT,CAAC;YAED,IAAI,MAAM,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/C,OAAO;YACT,CAAC;YAED,IAC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AC;qBACvC;oBACD,SAAS,EAAE,yCAAQ,CAAC,qBAAqB;oBACzC,IAAI;iBACL,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO;YACL,kEAAkE,EAChE,WAAW;SACd,CAAC;IACJ,CAAC;IACD,cAAc,EAAE;QACd;YACE,iBAAiB,EAAE,CAAC;YACpB,MAAM,EAAE,CAAC,GAAG,CAAC;YACb,eAAe,EAAE,CAAC,QAAQ,CAAC;YAC3B,cAAc,EAAE,CAAC,GAAG,CAAC;SACtB;KACF;IAED,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,2DAA2D;YACxE,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,kHAAkH;SACxH;QACD,QAAQ,EAAE;YACR,CAAC,yCAAQ,CAAC,qBAAqB,CAAC,EAC9B,uHAAuH;SAC1H;QACD,MAAM,EAAE;YACN;gBACE,oBAAoB,EAAE,KAAK;gBAC3B,UAAU,EAAE;oBACV,iBAAiB,EAAE;wBACjB,OAAO,EAAE,CAAC;wBACV,IAAI,EAAE,QAAQ;qBACf;oBACD,MAAM,EAAE;wBACN,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,IAAI,EAAE,OAAO;qBACd;oBACD,eAAe,EAAE;wBACf,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,IAAI,EAAE,OAAO;qBACd;oBACD,cAAc,EAAE;wBACd,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,IAAI,EAAE,OAAO;qBACd;iBACF;gBACD,IAAI,EAAE,QAAQ;aACf;SACF;QACD,IAAI,EAAE,SAAS;KAChB;IAED,IAAI,EAAJ,YAAI;CACL,CAAC,CAAC"}
@@ -1,211 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rule = exports.name = void 0;
4
- const prefer_arrow_functions_model_1 = require("../models/prefer-arrow-functions.model");
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const core_1 = require("../utility/core");
7
- exports.name = "prefer-arrow-functions";
8
- exports.rule = (0, core_1.createRule)({
9
- create: (context, [options]) => {
10
- const { allowAsync = true, allowConstructors = true, allowFunctionDeclarations = false, allowFunctionExpressions = false, allowGenerators = true, allowMethodDefinitions = false, } = options;
11
- const sourceCode = context.sourceCode;
12
- const shouldSkipFunction = (node) => {
13
- var _a;
14
- if (allowConstructors &&
15
- ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.MethodDefinition &&
16
- node.parent.kind === "constructor") {
17
- return true;
18
- }
19
- if (allowGenerators && (node === null || node === void 0 ? void 0 : node.generator)) {
20
- return true;
21
- }
22
- if (allowAsync && (node === null || node === void 0 ? void 0 : node.async)) {
23
- return true;
24
- }
25
- if (node.type === utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
26
- return true;
27
- }
28
- return false;
29
- };
30
- const generateArrowFunction = (node) => {
31
- const asyncKeyword = node.async ? "async " : "";
32
- const params = node.params.length === 0
33
- ? "()"
34
- : node.params.length === 1 &&
35
- node.params[0].type === utils_1.AST_NODE_TYPES.Identifier &&
36
- !node.params[0].typeAnnotation
37
- ? sourceCode.getText(node.params[0])
38
- : `(${node.params.map((p) => sourceCode.getText(p)).join(", ")})`;
39
- const returnType = node.returnType
40
- ? `: ${sourceCode.getText(node.returnType.typeAnnotation)}`
41
- : "";
42
- const body = node.body ? sourceCode.getText(node.body) : "";
43
- return `${asyncKeyword}${params}${returnType} => ${body}`;
44
- };
45
- return {
46
- FunctionDeclaration: (node) => {
47
- if (allowFunctionDeclarations || shouldSkipFunction(node)) {
48
- return;
49
- }
50
- context.report({
51
- fix: (fixer) => {
52
- var _a, _b;
53
- if (!node.id)
54
- return null;
55
- const functionName = node.id.name;
56
- const arrowFunction = generateArrowFunction(node);
57
- let replacement;
58
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
59
- const constDeclaration = `const ${functionName} = ${arrowFunction}`;
60
- const exportDeclaration = `export default ${functionName}`;
61
- replacement = `${constDeclaration};\n${exportDeclaration}`;
62
- return fixer.replaceText(node.parent, replacement);
63
- }
64
- else if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
65
- replacement = `export const ${functionName} = ${arrowFunction}`;
66
- return fixer.replaceText(node.parent, replacement);
67
- }
68
- else {
69
- replacement = `const ${functionName} = ${arrowFunction}`;
70
- return fixer.replaceText(node, replacement);
71
- }
72
- },
73
- messageId: prefer_arrow_functions_model_1.Messages.PREFER_ARROW_FUNCTIONS,
74
- node: node.id || node,
75
- });
76
- },
77
- FunctionExpression: (node) => {
78
- var _a, _b, _c;
79
- if ((((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.MethodDefinition ||
80
- (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.Property &&
81
- (node.parent.method || !node.parent.method))) &&
82
- allowMethodDefinitions) {
83
- return;
84
- }
85
- if (((_c = node.parent) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.Property &&
86
- node.parent.method) {
87
- return;
88
- }
89
- if (allowFunctionExpressions || shouldSkipFunction(node)) {
90
- return;
91
- }
92
- context.report({
93
- fix: (fixer) => {
94
- const arrowFunction = generateArrowFunction(node);
95
- return fixer.replaceText(node, arrowFunction);
96
- },
97
- messageId: prefer_arrow_functions_model_1.Messages.PREFER_ARROW_FUNCTION_EXPRESSION,
98
- node,
99
- });
100
- },
101
- MethodDefinition: (node) => {
102
- if (allowMethodDefinitions ||
103
- node.kind === "constructor" ||
104
- node.kind === "get" ||
105
- node.kind === "set") {
106
- return;
107
- }
108
- if (node.value.type === utils_1.AST_NODE_TYPES.FunctionExpression &&
109
- !shouldSkipFunction(node.value)) {
110
- context.report({
111
- fix: (fixer) => {
112
- const key = sourceCode.getText(node.key);
113
- const arrowFunction = generateArrowFunction(node.value);
114
- const static_ = node.static ? "static " : "";
115
- const replacement = `${static_}${key} = ${arrowFunction}`;
116
- return fixer.replaceText(node, replacement);
117
- },
118
- messageId: prefer_arrow_functions_model_1.Messages.PREFER_ARROW_METHOD,
119
- node: node.key,
120
- });
121
- }
122
- },
123
- Property: (node) => {
124
- if (allowMethodDefinitions ||
125
- !node.method ||
126
- node.kind === "get" ||
127
- node.kind === "set" ||
128
- node.value.type !== utils_1.AST_NODE_TYPES.FunctionExpression) {
129
- return;
130
- }
131
- const functionNode = node.value;
132
- if (!shouldSkipFunction(functionNode)) {
133
- context.report({
134
- fix: (fixer) => {
135
- const key = sourceCode.getText(node.key);
136
- const arrowFunction = generateArrowFunction(functionNode);
137
- const replacement = `${key}: ${arrowFunction}`;
138
- return fixer.replaceText(node, replacement);
139
- },
140
- messageId: prefer_arrow_functions_model_1.Messages.PREFER_ARROW_METHOD,
141
- node: node.key,
142
- });
143
- }
144
- },
145
- };
146
- },
147
- defaultOptions: [
148
- {
149
- allowAsync: true,
150
- allowConstructors: true,
151
- allowFunctionDeclarations: false,
152
- allowFunctionExpressions: false,
153
- allowGenerators: true,
154
- allowMethodDefinitions: false,
155
- },
156
- ],
157
- meta: {
158
- docs: {
159
- description: "Prefer arrow functions over function declarations and expressions",
160
- recommended: true,
161
- url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-arrow-functions.md",
162
- },
163
- fixable: "code",
164
- messages: {
165
- [prefer_arrow_functions_model_1.Messages.PREFER_ARROW_FUNCTION_EXPRESSION]: "NIMA: Prefer arrow functions over function expressions.",
166
- [prefer_arrow_functions_model_1.Messages.PREFER_ARROW_FUNCTIONS]: "NIMA: Prefer arrow functions over function declarations.",
167
- [prefer_arrow_functions_model_1.Messages.PREFER_ARROW_METHOD]: "NIMA: Prefer arrow functions over method definitions.",
168
- },
169
- schema: [
170
- {
171
- additionalProperties: false,
172
- properties: {
173
- allowAsync: {
174
- default: true,
175
- description: "Allow async functions (they can still be arrow functions)",
176
- type: "boolean",
177
- },
178
- allowConstructors: {
179
- default: true,
180
- description: "Allow constructor functions",
181
- type: "boolean",
182
- },
183
- allowFunctionDeclarations: {
184
- default: false,
185
- description: "Allow function declarations (function name() {})",
186
- type: "boolean",
187
- },
188
- allowFunctionExpressions: {
189
- default: false,
190
- description: "Allow function expressions (const name = function() {})",
191
- type: "boolean",
192
- },
193
- allowGenerators: {
194
- default: true,
195
- description: "Allow generator functions",
196
- type: "boolean",
197
- },
198
- allowMethodDefinitions: {
199
- default: false,
200
- description: "Allow method definitions in classes and objects",
201
- type: "boolean",
202
- },
203
- },
204
- type: "object",
205
- },
206
- ],
207
- type: "suggestion",
208
- },
209
- name: exports.name,
210
- });
211
- //# sourceMappingURL=prefer-arrow-functions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prefer-arrow-functions.js","sourceRoot":"","sources":["../../src/rules/prefer-arrow-functions.ts"],"names":[],"mappings":";;;AAAA,uFAA8E;AAC9E,oDAAyE;AACzE,wCAA2C;AAE9B,QAAA,IAAI,GAAG,wBAAwB,CAAC;AAEhC,QAAA,IAAI,GAAG,IAAA,iBAAU,EAAoB;IAChD,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE;QAC7B,MAAM,EACJ,UAAU,GAAG,IAAI,EACjB,iBAAiB,GAAG,IAAI,EACxB,yBAAyB,GAAG,KAAK,EACjC,wBAAwB,GAAG,KAAK,EAChC,eAAe,GAAG,IAAI,EACtB,sBAAsB,GAAG,KAAK,GAC/B,GAAG,OAAO,CAAC;QAEZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,MAAM,kBAAkB,GAAG,CAAC,IAA2B,EAAE,EAAE;;YACzD,IACE,iBAAiB;gBACjB,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,MAAK,sBAAc,CAAC,gBAAgB;gBACrD,IAAI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M,EAAE;YACN;gBACE,oBAAoB,EAAE,KAAK;gBAC3B,UAAU,EAAE;oBACV,UAAU,EAAE;wBACV,OAAO,EAAE,IAAI;wBACb,WAAW,EACT,2DAA2D;wBAC7D,IAAI,EAAE,SAAS;qBAChB;oBACD,iBAAiB,EAAE;wBACjB,OAAO,EAAE,IAAI;wBACb,WAAW,EAAE,6BAA6B;wBAC1C,IAAI,EAAE,SAAS;qBAChB;oBACD,yBAAyB,EAAE;wBACzB,OAAO,EAAE,KAAK;wBACd,WAAW,EAAE,kDAAkD;wBAC/D,IAAI,EAAE,SAAS;qBAChB;oBACD,wBAAwB,EAAE;wBACxB,OAAO,EAAE,KAAK;wBACd,WAAW,EACT,yDAAyD;wBAC3D,IAAI,EAAE,SAAS;qBAChB;oBACD,eAAe,EAAE;wBACf,OAAO,EAAE,IAAI;wBACb,WAAW,EAAE,2BAA2B;wBACxC,IAAI,EAAE,SAAS;qBAChB;oBACD,sBAAsB,EAAE;wBACtB,OAAO,EAAE,KAAK;wBACd,WAAW,EAAE,iDAAiD;wBAC9D,IAAI,EAAE,SAAS;qBAChB;iBACF;gBACD,IAAI,EAAE,QAAQ;aACf;SACF;QACD,IAAI,EAAE,YAAY;KACnB;IACD,IAAI,EAAJ,YAAI;CACL,CAAC,CAAC"}
@@ -1,5 +0,0 @@
1
- import { Messages, Options } from "../models/prefer-export-under-component.model";
2
- export declare const name = "prefer-export-under-component";
3
- export declare const rule: import("@typescript-eslint/utils/ts-eslint").RuleModule<Messages, Options, {
4
- recommended: boolean;
5
- }, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rule = exports.name = void 0;
4
- const prefer_export_under_component_model_1 = require("../models/prefer-export-under-component.model");
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const core_1 = require("../utility/core");
7
- const function_helpers_1 = require("../utility/function-helpers");
8
- exports.name = "prefer-export-under-component";
9
- exports.rule = (0, core_1.createRule)({
10
- create: (context) => {
11
- return {
12
- ExportDefaultDeclaration: (node) => {
13
- var _a;
14
- if (node.declaration.type !== utils_1.AST_NODE_TYPES.FunctionDeclaration) {
15
- return;
16
- }
17
- const fnName = (_a = node.declaration.id) === null || _a === void 0 ? void 0 : _a.name;
18
- if (fnName &&
19
- (0, function_helpers_1.isComponentFunction)(fnName) &&
20
- (0, function_helpers_1.isReactReturn)(node.declaration)) {
21
- context.report({
22
- data: {
23
- fnName,
24
- },
25
- fix: (fixer) => {
26
- const sourceCode = context.sourceCode;
27
- const text = sourceCode.getText(node);
28
- const newText = text.replace(/^export\s+default\s+/, "");
29
- return [
30
- fixer.replaceText(node, newText),
31
- fixer.insertTextAfter(node, `\n\nexport { ${fnName} };`),
32
- ];
33
- },
34
- messageId: prefer_export_under_component_model_1.Messages.EXPORT_BELOW_COMPONENT,
35
- node,
36
- });
37
- }
38
- },
39
- ExportNamedDeclaration: (node) => {
40
- if (!node.declaration)
41
- return;
42
- if (node.declaration.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
43
- const declarator = node.declaration.declarations[0];
44
- if (!declarator.init)
45
- return;
46
- const fnNode = declarator.init;
47
- if (fnNode.type !== utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
48
- fnNode.type !== utils_1.AST_NODE_TYPES.FunctionExpression) {
49
- return;
50
- }
51
- const fnName = (0, function_helpers_1.getFunctionName)(fnNode);
52
- if (fnName && (0, function_helpers_1.isComponentFunction)(fnName) && (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: prefer_export_under_component_model_1.Messages.EXPORT_BELOW_COMPONENT,
67
- node,
68
- });
69
- }
70
- }
71
- },
72
- FunctionDeclaration: (node) => {
73
- var _a;
74
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) !== utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
75
- return;
76
- }
77
- const fnName = (0, function_helpers_1.getFunctionName)(node);
78
- if (fnName && (0, function_helpers_1.isComponentFunction)(fnName) && (0, function_helpers_1.isReactReturn)(node)) {
79
- context.report({
80
- data: {
81
- fnName,
82
- },
83
- fix: (fixer) => {
84
- const sourceCode = context.sourceCode;
85
- const text = sourceCode.getText(node.parent);
86
- const newText = text.replace(/^export\s+/, "");
87
- return [
88
- fixer.replaceText(node.parent, newText),
89
- fixer.insertTextAfter(node.parent, `\n\nexport { ${fnName} };`),
90
- ];
91
- },
92
- messageId: prefer_export_under_component_model_1.Messages.EXPORT_BELOW_COMPONENT,
93
- node: node.parent,
94
- });
95
- }
96
- },
97
- };
98
- },
99
- defaultOptions: [{}],
100
- meta: {
101
- docs: {
102
- description: "Enforce separate declaration and export for React components",
103
- recommended: true,
104
- url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-export-under-component.md",
105
- },
106
- fixable: "code",
107
- messages: {
108
- [prefer_export_under_component_model_1.Messages.EXPORT_BELOW_COMPONENT]: "NIMA: Declare React component '{{ fnName }}' separately from its export statement",
109
- },
110
- schema: [],
111
- type: "problem",
112
- },
113
- name: exports.name,
114
- });
115
- //# sourceMappingURL=prefer-export-under-component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prefer-export-under-component.js","sourceRoot":"","sources":["../../src/rules/prefer-export-under-component.ts"],"names":[],"mappings":";;;AAAA,qGAAgF;AAChF,oDAAyE;AACzE,wCAA2C;AAC3C,gEAImC;AAEtB,QAAA,IAAI,GAAG,+BAA+B,CAAC;AAEvC,QAAA,IAAI,GAAG,IAAA,iBAAU,EAAoB;IAChD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,OAAO;YACL,wBAAwB,E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CAAa,EAAC,IAAI,CAAC,EAAE,CAAC;oBACjE,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE;4BACJ,MAAM;yBACP;wBACD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;4BACb,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;4BACtC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;4BAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;4BAE/C,OAAO;gCACL,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;gCACvC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,MAAM,KAAK,CAAC;6BAChE,CAAC;wBACJ,CAAC;wBACD,SAAS,EAAE,8CAAQ,CAAC,sBAAsB;wBAC1C,IAAI,EAAE,IAAI,CAAC,MAAM;qBAClB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,EAAE,CAAC;IAEpB,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EACT,8DAA8D;YAChE,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,uHAAuH;SAC7H;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACR,CAAC,8CAAQ,CAAC,sBAAsB,CAAC,EAC/B,mFAAmF;SACtF;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KAChB;IAED,IAAI,EAAJ,YAAI;CACL,CAAC,CAAC"}
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rule = exports.name = void 0;
4
- const prefer_react_fc_model_1 = require("../models/prefer-react-fc.model");
5
- const utils_1 = require("@typescript-eslint/utils");
6
- const core_1 = require("../utility/core");
7
- const function_helpers_1 = require("../utility/function-helpers");
8
- exports.name = "prefer-react-fc";
9
- exports.rule = (0, core_1.createRule)({
10
- create(context) {
11
- function isReactComponent(node) {
12
- const fnName = (0, function_helpers_1.getFunctionName)(node);
13
- if (!(0, function_helpers_1.isComponentFunction)(fnName)) {
14
- return;
15
- }
16
- return hasJSXReturn(node);
17
- }
18
- function hasJSXReturn(node) {
19
- if (!node.body) {
20
- return false;
21
- }
22
- if (node.body.type === utils_1.AST_NODE_TYPES.BlockStatement) {
23
- return checkBlockForJSX(node.body);
24
- }
25
- else {
26
- return isJSXExpression(node.body);
27
- }
28
- }
29
- function checkBlockForJSX(block) {
30
- var _a;
31
- for (const statement of block.body) {
32
- if (statement.type === utils_1.AST_NODE_TYPES.ReturnStatement &&
33
- statement.argument) {
34
- if (isJSXExpression(statement.argument)) {
35
- return true;
36
- }
37
- }
38
- if (statement.type === utils_1.AST_NODE_TYPES.IfStatement) {
39
- if (statement.consequent.type === utils_1.AST_NODE_TYPES.BlockStatement &&
40
- checkBlockForJSX(statement.consequent)) {
41
- return true;
42
- }
43
- if (((_a = statement.alternate) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.BlockStatement &&
44
- checkBlockForJSX(statement.alternate)) {
45
- return true;
46
- }
47
- }
48
- }
49
- return false;
50
- }
51
- function isJSXExpression(node) {
52
- return (node.type === utils_1.AST_NODE_TYPES.JSXElement ||
53
- node.type === utils_1.AST_NODE_TYPES.JSXFragment ||
54
- (node.type === utils_1.AST_NODE_TYPES.ConditionalExpression &&
55
- (isJSXExpression(node.consequent) ||
56
- isJSXExpression(node.alternate))) ||
57
- (node.type === utils_1.AST_NODE_TYPES.LogicalExpression &&
58
- isJSXExpression(node.right)));
59
- }
60
- function hasReactFCAnnotation(node) {
61
- var _a;
62
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.VariableDeclarator &&
63
- node.parent.id.type === utils_1.AST_NODE_TYPES.Identifier &&
64
- node.parent.id.typeAnnotation) {
65
- const typeAnnotation = node.parent.id.typeAnnotation.typeAnnotation;
66
- return containsReactFCType(typeAnnotation);
67
- }
68
- if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration && node.returnType) {
69
- return containsReactFCType(node.returnType.typeAnnotation);
70
- }
71
- return false;
72
- }
73
- function hasCustomComponentTypeAnnotation(node) {
74
- var _a;
75
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.VariableDeclarator &&
76
- node.parent.id.type === utils_1.AST_NODE_TYPES.Identifier &&
77
- node.parent.id.typeAnnotation) {
78
- const typeAnnotation = node.parent.id.typeAnnotation.typeAnnotation;
79
- return hasCustomComponentType(typeAnnotation);
80
- }
81
- if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration && node.returnType) {
82
- return hasCustomComponentType(node.returnType.typeAnnotation);
83
- }
84
- return false;
85
- }
86
- function hasCustomComponentType(typeNode) {
87
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
88
- return typeNode.types.some((type) => isCustomComponentType(type));
89
- }
90
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSUnionType) {
91
- return typeNode.types.some((type) => isCustomComponentType(type));
92
- }
93
- return isCustomComponentType(typeNode);
94
- }
95
- function isCustomComponentType(typeNode) {
96
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference) {
97
- const typeName = typeNode.typeName;
98
- if (typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName) {
99
- return true;
100
- }
101
- if (typeName.type === utils_1.AST_NODE_TYPES.Identifier) {
102
- const name = typeName.name;
103
- if (name === "FC" || name === "FunctionComponent") {
104
- return false;
105
- }
106
- return name.endsWith("Component");
107
- }
108
- }
109
- return false;
110
- }
111
- function containsReactFCType(typeNode) {
112
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSIntersectionType) {
113
- return typeNode.types.some((type) => isReactFCType(type));
114
- }
115
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSUnionType) {
116
- return typeNode.types.some((type) => isReactFCType(type));
117
- }
118
- return isReactFCType(typeNode);
119
- }
120
- function isReactFCType(typeNode) {
121
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
122
- typeNode.typeName.type === utils_1.AST_NODE_TYPES.TSQualifiedName &&
123
- typeNode.typeName.left.type === utils_1.AST_NODE_TYPES.Identifier &&
124
- typeNode.typeName.left.name === "React" &&
125
- typeNode.typeName.right.type === utils_1.AST_NODE_TYPES.Identifier &&
126
- (typeNode.typeName.right.name === "FC" ||
127
- typeNode.typeName.right.name === "FunctionComponent")) {
128
- return true;
129
- }
130
- if (typeNode.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
131
- typeNode.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
132
- (typeNode.typeName.name === "FC" ||
133
- typeNode.typeName.name === "FunctionComponent")) {
134
- return true;
135
- }
136
- return false;
137
- }
138
- return {
139
- ArrowFunctionExpression(node) {
140
- if (isReactComponent(node) &&
141
- !hasReactFCAnnotation(node) &&
142
- !hasCustomComponentTypeAnnotation(node)) {
143
- context.report({
144
- messageId: prefer_react_fc_model_1.Messages.REQUIRE_REACT_FC,
145
- node,
146
- });
147
- }
148
- },
149
- FunctionDeclaration(node) {
150
- if (isReactComponent(node) &&
151
- !hasReactFCAnnotation(node) &&
152
- !hasCustomComponentTypeAnnotation(node)) {
153
- context.report({
154
- messageId: prefer_react_fc_model_1.Messages.REQUIRE_REACT_FC,
155
- node: node.id || node,
156
- });
157
- }
158
- },
159
- FunctionExpression(node) {
160
- if (isReactComponent(node) &&
161
- !hasReactFCAnnotation(node) &&
162
- !hasCustomComponentTypeAnnotation(node)) {
163
- context.report({
164
- messageId: prefer_react_fc_model_1.Messages.REQUIRE_REACT_FC,
165
- node,
166
- });
167
- }
168
- },
169
- };
170
- },
171
- defaultOptions: [
172
- {
173
- allowArrowFunctions: true,
174
- allowFunctionDeclarations: true,
175
- },
176
- ],
177
- meta: {
178
- docs: {
179
- description: "Enforce React.FC type annotation for React component functions",
180
- recommended: true,
181
- url: "https://github.com/NIMA-Enterprises/eslint-plugin-nima/blob/main/documentation/rules/prefer-react-fc.md",
182
- },
183
- fixable: "code",
184
- messages: {
185
- [prefer_react_fc_model_1.Messages.REQUIRE_REACT_FC]: "NIMA: Component functions must use React.FC type annotation.",
186
- },
187
- schema: [
188
- {
189
- additionalProperties: false,
190
- properties: {
191
- allowArrowFunctions: {
192
- default: true,
193
- type: "boolean",
194
- },
195
- allowFunctionDeclarations: {
196
- default: true,
197
- type: "boolean",
198
- },
199
- },
200
- type: "object",
201
- },
202
- ],
203
- type: "problem",
204
- },
205
- name: exports.name,
206
- });
207
- //# sourceMappingURL=prefer-react-fc.js.map