@bigbinary/eslint-plugin-neeto 1.1.15 → 1.1.17
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 +2 -0
- package/dist/index.js +154 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ module.exports = {
|
|
|
46
46
|
|
|
47
47
|
## Exported rules
|
|
48
48
|
|
|
49
|
+
- [no-withT-for-smart-components](./docs/src/rules/no-withT-for-smart-components.md)
|
|
50
|
+
- [no-large-functions-inside-jsx](./docs/src/rules/no-large-functions-inside-jsx.md)
|
|
49
51
|
- [use-standard-date-time-formats](./docs/src/rules/use-standard-date-time-formats.md)
|
|
50
52
|
- [no-dumb-components-with-use-translation](./docs/src/rules/no-dumb-components-with-use-translation.md)
|
|
51
53
|
- [no-unnecessary-if-condition](./docs/src/rules/no-unnecessary-if-condition.md)
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,8 @@
|
|
|
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-withT-for-smart-components": "error",
|
|
46
|
+
"@bigbinary/neeto/no-large-functions-inside-jsx": "error",
|
|
45
47
|
"@bigbinary/neeto/use-standard-date-time-formats": "error",
|
|
46
48
|
"@bigbinary/neeto/no-dumb-components-with-use-translation": "error",
|
|
47
49
|
"@bigbinary/neeto/api-connector-name-should-match-filename": "error",
|
|
@@ -406,7 +408,19 @@
|
|
|
406
408
|
}
|
|
407
409
|
}]
|
|
408
410
|
};
|
|
411
|
+
var PROP_FUNCTION_PATTERN = {
|
|
412
|
+
value: {
|
|
413
|
+
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
414
|
+
expression: {
|
|
415
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
416
|
+
body: {
|
|
417
|
+
type: TYPES.BLOCK_STATEMENT
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
409
422
|
var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
|
|
423
|
+
var MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX = 4;
|
|
410
424
|
|
|
411
425
|
var ARGUMENT_LIMIT = 3;
|
|
412
426
|
var API_ACTIONS_ARGUMENT_LIMIT = 2;
|
|
@@ -458,6 +472,10 @@
|
|
|
458
472
|
var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
|
|
459
473
|
return "Do not have multiple component definitions that exceed ".concat(maxAllowedNoOfLines, " lines in a single file.");
|
|
460
474
|
};
|
|
475
|
+
var avoidLargeFunctionsInsideJsx = function avoidLargeFunctionsInsideJsx() {
|
|
476
|
+
var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
|
|
477
|
+
return "Avoid inline functions that exceed ".concat(maxAllowedNoOfLines, " lines directly inside JSX. Extract the function outside of JSX.");
|
|
478
|
+
};
|
|
461
479
|
var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
|
|
462
480
|
return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
|
|
463
481
|
};
|
|
@@ -527,6 +545,7 @@
|
|
|
527
545
|
var PROP_KEY_VALUE_DUPLICATE = "Prop key and value names should not be repeated";
|
|
528
546
|
var USE_WITH_IMMUTABLE_ACTIONS_WRAPPER = 'Use "withImmutableActions" wrapper from "neeto-commons-frontend" inside zustand create. Refer: https://bit.ly/withimmutableactions';
|
|
529
547
|
var USE_WITH_T_HOC_IN_DUMB_COMPONENTS = 'Use "withT" HOC from "neeto-commons-frontend" instead of useTranslation hook in Dumb components';
|
|
548
|
+
var NO_WITH_T_IN_SMART_COMPONENTS = '"withT" HOC should only be used in dumb components. "useTranslation" hook should be used here.';
|
|
530
549
|
var USE_STANDARD_DATE_TIME_FORMATS = 'Use "dateFormat/timeFormat" from "@bigbinary/neeto-commons-frontend/utils" instead. Refer: https://github.com/bigbinary/neeto-commons-frontend/blob/main/docs/utils/README.md#dateformattimeformat';
|
|
531
550
|
|
|
532
551
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
@@ -6088,6 +6107,35 @@
|
|
|
6088
6107
|
}
|
|
6089
6108
|
};
|
|
6090
6109
|
|
|
6110
|
+
var noLargeFunctionsInsideJsx = {
|
|
6111
|
+
meta: {
|
|
6112
|
+
type: "problem",
|
|
6113
|
+
docs: {
|
|
6114
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-large-functions-inside-jsx.md",
|
|
6115
|
+
description: "Disallows the use of functions with large bodies, that exceed maxAllowedNoOfLines, directly inside JSX elements." + "The default value for maxAllowedNoOfLines is 4."
|
|
6116
|
+
}
|
|
6117
|
+
},
|
|
6118
|
+
create: function create(context) {
|
|
6119
|
+
return {
|
|
6120
|
+
JSXAttribute: function JSXAttribute(node) {
|
|
6121
|
+
var _context$options$;
|
|
6122
|
+
if (!pure.matches(PROP_FUNCTION_PATTERN, node)) return;
|
|
6123
|
+
var functionBody = node.value.expression.body;
|
|
6124
|
+
var _functionBody$loc = functionBody.loc,
|
|
6125
|
+
start = _functionBody$loc.start,
|
|
6126
|
+
end = _functionBody$loc.end;
|
|
6127
|
+
var linesInsideBlock = end.line - (start.line + 1);
|
|
6128
|
+
var maxAllowedNoOfLines = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.maxAllowedNoOfLines) || MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX;
|
|
6129
|
+
if (linesInsideBlock <= maxAllowedNoOfLines) return;
|
|
6130
|
+
context.report({
|
|
6131
|
+
node: node,
|
|
6132
|
+
message: avoidLargeFunctionsInsideJsx(maxAllowedNoOfLines)
|
|
6133
|
+
});
|
|
6134
|
+
}
|
|
6135
|
+
};
|
|
6136
|
+
}
|
|
6137
|
+
};
|
|
6138
|
+
|
|
6091
6139
|
var noMultipleComponentsInAFile = {
|
|
6092
6140
|
meta: {
|
|
6093
6141
|
type: "problem",
|
|
@@ -6441,6 +6489,110 @@
|
|
|
6441
6489
|
}
|
|
6442
6490
|
};
|
|
6443
6491
|
|
|
6492
|
+
var REACT_I18_IMPORT_PATTERN = {
|
|
6493
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
6494
|
+
source: {
|
|
6495
|
+
type: TYPES.LITERAL,
|
|
6496
|
+
value: "react-i18next"
|
|
6497
|
+
},
|
|
6498
|
+
specifiers: [{
|
|
6499
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
6500
|
+
}]
|
|
6501
|
+
};
|
|
6502
|
+
var WITH_T_HOC_PATTERN = {
|
|
6503
|
+
type: TYPES.VARIABLE_DECLARATION,
|
|
6504
|
+
kind: "const",
|
|
6505
|
+
declarations: [{
|
|
6506
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
6507
|
+
init: {
|
|
6508
|
+
type: TYPES.CALL_EXPRESSION,
|
|
6509
|
+
callee: {
|
|
6510
|
+
name: "withT"
|
|
6511
|
+
},
|
|
6512
|
+
arguments: [{
|
|
6513
|
+
body: {
|
|
6514
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
6515
|
+
body: function body(_body) {
|
|
6516
|
+
return _body.length >= 2;
|
|
6517
|
+
}
|
|
6518
|
+
}
|
|
6519
|
+
}]
|
|
6520
|
+
},
|
|
6521
|
+
id: {
|
|
6522
|
+
type: TYPES.IDENTIFIER,
|
|
6523
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
6524
|
+
}
|
|
6525
|
+
}]
|
|
6526
|
+
};
|
|
6527
|
+
|
|
6528
|
+
var insertTextAfterPosition = function insertTextAfterPosition(position, inputString, textToInsert) {
|
|
6529
|
+
var firstCharacter = inputString.charAt(position);
|
|
6530
|
+
var restOfString = inputString.slice(position + 1);
|
|
6531
|
+
return firstCharacter + textToInsert + restOfString;
|
|
6532
|
+
};
|
|
6533
|
+
|
|
6534
|
+
var noWithTForSmartComponents = {
|
|
6535
|
+
meta: {
|
|
6536
|
+
type: "problem",
|
|
6537
|
+
docs: {
|
|
6538
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-withT-for-smart-components.md",
|
|
6539
|
+
description: "Disallows usage of 'withT' HOC in smart components."
|
|
6540
|
+
},
|
|
6541
|
+
fixable: "code"
|
|
6542
|
+
},
|
|
6543
|
+
create: function create(context) {
|
|
6544
|
+
return {
|
|
6545
|
+
VariableDeclaration: function VariableDeclaration(node) {
|
|
6546
|
+
if (!pure.matches(WITH_T_HOC_PATTERN, node)) return;
|
|
6547
|
+
var arrowFunctionExpression = node.declarations[0].init.arguments[0];
|
|
6548
|
+
var body = arrowFunctionExpression.body;
|
|
6549
|
+
context.report({
|
|
6550
|
+
node: node,
|
|
6551
|
+
message: NO_WITH_T_IN_SMART_COMPONENTS,
|
|
6552
|
+
fix: function fix(fixer) {
|
|
6553
|
+
var fixers = [];
|
|
6554
|
+
var _arrowFunctionExpress = _toArray(arrowFunctionExpression.params),
|
|
6555
|
+
props = _arrowFunctionExpress[0],
|
|
6556
|
+
restParams = _arrowFunctionExpress.slice(1);
|
|
6557
|
+
var getPropsCode = function getPropsCode() {
|
|
6558
|
+
if (ramda.isEmpty(arrowFunctionExpression.params)) return "";
|
|
6559
|
+
if (props.type === TYPES.IDENTIFIER) {
|
|
6560
|
+
return "{...".concat(getCode$1(context, props), " }");
|
|
6561
|
+
}
|
|
6562
|
+
if (props.type === TYPES.OBJECT_PATTERN) {
|
|
6563
|
+
var _props$properties, _props$properties2, _props$properties2$0$;
|
|
6564
|
+
if (((_props$properties = props.properties) === null || _props$properties === void 0 ? void 0 : _props$properties.length) === 1 && ((_props$properties2 = props.properties) === null || _props$properties2 === void 0 ? void 0 : (_props$properties2$0$ = _props$properties2[0].value) === null || _props$properties2$0$ === void 0 ? void 0 : _props$properties2$0$.name) === "t") {
|
|
6565
|
+
return "";
|
|
6566
|
+
}
|
|
6567
|
+
return "{".concat(props.properties.map(function (property) {
|
|
6568
|
+
return getCode$1(context, property);
|
|
6569
|
+
}).filter(pure.isNot("t")).join(", "), " }");
|
|
6570
|
+
}
|
|
6571
|
+
return "";
|
|
6572
|
+
};
|
|
6573
|
+
var codeInsideBody = getCode$1(context, body);
|
|
6574
|
+
var codeWithUseTranslation = insertTextAfterPosition(0, codeInsideBody, "const { t } = useTranslation();\n");
|
|
6575
|
+
var updatedProps = getPropsCode();
|
|
6576
|
+
var replacedCodeWithUseTranslation = "(".concat(updatedProps).concat(ramda.isEmpty(restParams) ? "" : "".concat(pure.isNotEmpty(updatedProps) ? ", " : "").concat(restParams.map(function (param) {
|
|
6577
|
+
return getCode$1(context, param);
|
|
6578
|
+
}).join(", ")), ") => ").concat(codeWithUseTranslation);
|
|
6579
|
+
var replaceIncorrectWithTCode = fixer.replaceText(node.declarations[0].init, replacedCodeWithUseTranslation);
|
|
6580
|
+
fixers.push(replaceIncorrectWithTCode);
|
|
6581
|
+
var importUseTranslation = addFunctionImport({
|
|
6582
|
+
context: context,
|
|
6583
|
+
fixer: fixer,
|
|
6584
|
+
functions: ["useTranslation"],
|
|
6585
|
+
importPattern: REACT_I18_IMPORT_PATTERN
|
|
6586
|
+
});
|
|
6587
|
+
importUseTranslation && fixers.push(importUseTranslation);
|
|
6588
|
+
return fixers;
|
|
6589
|
+
}
|
|
6590
|
+
});
|
|
6591
|
+
}
|
|
6592
|
+
};
|
|
6593
|
+
}
|
|
6594
|
+
};
|
|
6595
|
+
|
|
6444
6596
|
var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
|
|
6445
6597
|
|
|
6446
6598
|
var importedFromNeeto = function importedFromNeeto(context, node) {
|
|
@@ -26568,6 +26720,8 @@
|
|
|
26568
26720
|
|
|
26569
26721
|
var index = {
|
|
26570
26722
|
rules: {
|
|
26723
|
+
"no-withT-for-smart-components": noWithTForSmartComponents,
|
|
26724
|
+
"no-large-functions-inside-jsx": noLargeFunctionsInsideJsx,
|
|
26571
26725
|
"use-standard-date-time-formats": useStandardDateTimeFormats,
|
|
26572
26726
|
"no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
|
|
26573
26727
|
"api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
|