@bigbinary/eslint-plugin-neeto 1.1.15 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,6 +46,7 @@ module.exports = {
46
46
 
47
47
  ## Exported rules
48
48
 
49
+ - [no-large-functions-inside-jsx](./docs/src/rules/no-large-functions-inside-jsx.md)
49
50
  - [use-standard-date-time-formats](./docs/src/rules/use-standard-date-time-formats.md)
50
51
  - [no-dumb-components-with-use-translation](./docs/src/rules/no-dumb-components-with-use-translation.md)
51
52
  - [no-unnecessary-if-condition](./docs/src/rules/no-unnecessary-if-condition.md)
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@
42
42
  var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
43
43
  var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
44
44
  var rules = {
45
+ "@bigbinary/neeto/no-large-functions-inside-jsx": "error",
45
46
  "@bigbinary/neeto/use-standard-date-time-formats": "error",
46
47
  "@bigbinary/neeto/no-dumb-components-with-use-translation": "error",
47
48
  "@bigbinary/neeto/api-connector-name-should-match-filename": "error",
@@ -406,7 +407,19 @@
406
407
  }
407
408
  }]
408
409
  };
410
+ var PROP_FUNCTION_PATTERN = {
411
+ value: {
412
+ type: TYPES.JSX_EXPRESSION_CONTAINER,
413
+ expression: {
414
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
415
+ body: {
416
+ type: TYPES.BLOCK_STATEMENT
417
+ }
418
+ }
419
+ }
420
+ };
409
421
  var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
422
+ var MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX = 4;
410
423
 
411
424
  var ARGUMENT_LIMIT = 3;
412
425
  var API_ACTIONS_ARGUMENT_LIMIT = 2;
@@ -458,6 +471,10 @@
458
471
  var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
459
472
  return "Do not have multiple component definitions that exceed ".concat(maxAllowedNoOfLines, " lines in a single file.");
460
473
  };
474
+ var avoidLargeFunctionsInsideJsx = function avoidLargeFunctionsInsideJsx() {
475
+ var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
476
+ return "Avoid inline functions that exceed ".concat(maxAllowedNoOfLines, " lines directly inside JSX. Extract the function outside of JSX.");
477
+ };
461
478
  var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
462
479
  return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
463
480
  };
@@ -6088,6 +6105,35 @@
6088
6105
  }
6089
6106
  };
6090
6107
 
6108
+ var noLargeFunctionsInsideJsx = {
6109
+ meta: {
6110
+ type: "problem",
6111
+ docs: {
6112
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-large-functions-inside-jsx.md",
6113
+ description: "Disallows the use of functions with large bodies, that exceed maxAllowedNoOfLines, directly inside JSX elements." + "The default value for maxAllowedNoOfLines is 4."
6114
+ }
6115
+ },
6116
+ create: function create(context) {
6117
+ return {
6118
+ JSXAttribute: function JSXAttribute(node) {
6119
+ var _context$options$;
6120
+ if (!pure.matches(PROP_FUNCTION_PATTERN, node)) return;
6121
+ var functionBody = node.value.expression.body;
6122
+ var _functionBody$loc = functionBody.loc,
6123
+ start = _functionBody$loc.start,
6124
+ end = _functionBody$loc.end;
6125
+ var linesInsideBlock = end.line - (start.line + 1);
6126
+ var maxAllowedNoOfLines = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.maxAllowedNoOfLines) || MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX;
6127
+ if (linesInsideBlock <= maxAllowedNoOfLines) return;
6128
+ context.report({
6129
+ node: node,
6130
+ message: avoidLargeFunctionsInsideJsx(maxAllowedNoOfLines)
6131
+ });
6132
+ }
6133
+ };
6134
+ }
6135
+ };
6136
+
6091
6137
  var noMultipleComponentsInAFile = {
6092
6138
  meta: {
6093
6139
  type: "problem",
@@ -26568,6 +26614,7 @@
26568
26614
 
26569
26615
  var index = {
26570
26616
  rules: {
26617
+ "no-large-functions-inside-jsx": noLargeFunctionsInsideJsx,
26571
26618
  "use-standard-date-time-formats": useStandardDateTimeFormats,
26572
26619
  "no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
26573
26620
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {