@bigbinary/eslint-plugin-neeto 1.1.16 → 1.1.18
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 +1 -0
- package/dist/index.js +145 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ 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)
|
|
49
50
|
- [no-large-functions-inside-jsx](./docs/src/rules/no-large-functions-inside-jsx.md)
|
|
50
51
|
- [use-standard-date-time-formats](./docs/src/rules/use-standard-date-time-formats.md)
|
|
51
52
|
- [no-dumb-components-with-use-translation](./docs/src/rules/no-dumb-components-with-use-translation.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-withT-for-smart-components": "error",
|
|
45
46
|
"@bigbinary/neeto/no-large-functions-inside-jsx": "error",
|
|
46
47
|
"@bigbinary/neeto/use-standard-date-time-formats": "error",
|
|
47
48
|
"@bigbinary/neeto/no-dumb-components-with-use-translation": "error",
|
|
@@ -544,6 +545,7 @@
|
|
|
544
545
|
var PROP_KEY_VALUE_DUPLICATE = "Prop key and value names should not be repeated";
|
|
545
546
|
var USE_WITH_IMMUTABLE_ACTIONS_WRAPPER = 'Use "withImmutableActions" wrapper from "neeto-commons-frontend" inside zustand create. Refer: https://bit.ly/withimmutableactions';
|
|
546
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.';
|
|
547
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';
|
|
548
550
|
|
|
549
551
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
@@ -3862,6 +3864,41 @@
|
|
|
3862
3864
|
}
|
|
3863
3865
|
}]
|
|
3864
3866
|
};
|
|
3867
|
+
var WRAPPED_WITH_T_PATTERN = {
|
|
3868
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
3869
|
+
init: {
|
|
3870
|
+
type: TYPES.CALL_EXPRESSION,
|
|
3871
|
+
callee: {
|
|
3872
|
+
name: "withT"
|
|
3873
|
+
},
|
|
3874
|
+
arguments: [{
|
|
3875
|
+
body: {
|
|
3876
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
3877
|
+
body: function body(_body) {
|
|
3878
|
+
return _body.length >= 2;
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
}]
|
|
3882
|
+
},
|
|
3883
|
+
id: {
|
|
3884
|
+
type: TYPES.IDENTIFIER,
|
|
3885
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
var EXPORTED_WITH_T_PATTERN = {
|
|
3889
|
+
type: TYPES.EXPORT_DEFAULT_DECLARATION,
|
|
3890
|
+
declaration: {
|
|
3891
|
+
type: TYPES.CALL_EXPRESSION,
|
|
3892
|
+
callee: {
|
|
3893
|
+
type: TYPES.IDENTIFIER,
|
|
3894
|
+
name: "withT"
|
|
3895
|
+
},
|
|
3896
|
+
arguments: ramda.any(pure.matches({
|
|
3897
|
+
type: TYPES.IDENTIFIER,
|
|
3898
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
3899
|
+
}))
|
|
3900
|
+
}
|
|
3901
|
+
};
|
|
3865
3902
|
|
|
3866
3903
|
// components={{}}
|
|
3867
3904
|
var COMPONENTS_PROP_PATTERN = {
|
|
@@ -4447,6 +4484,7 @@
|
|
|
4447
4484
|
if (!isInsideComponentsDirectory(context)) return;
|
|
4448
4485
|
var componentNodes = findMatchingNodesDeep(node.body, COMPONENT_PATTERN);
|
|
4449
4486
|
if (ramda.isEmpty(componentNodes)) return;
|
|
4487
|
+
var isExportedWithT = patternExistsDeep(EXPORTED_WITH_T_PATTERN, node);
|
|
4450
4488
|
componentNodes.forEach(function (node) {
|
|
4451
4489
|
var tFunctionMemeberExpressionNodes = findMatchingNodesDeep(node, T_FUNCTION_MEMBER_EXPRESSION_PATTERN);
|
|
4452
4490
|
tFunctionMemeberExpressionNodes.forEach(function (node) {
|
|
@@ -4458,7 +4496,9 @@
|
|
|
4458
4496
|
var tFunctionNodes = findMatchingNodesDeep(node, T_FUNCTION_PATTERN);
|
|
4459
4497
|
if (ramda.isEmpty(tFunctionNodes)) return;
|
|
4460
4498
|
var isUseTranslationHookPresent = patternExistsDeep(USE_TRANSLATION_HOOK_PATTERN, node);
|
|
4499
|
+
var isWrappedWithT = patternExistsDeep(WRAPPED_WITH_T_PATTERN, node) || isExportedWithT;
|
|
4461
4500
|
if (isUseTranslationHookPresent) return;
|
|
4501
|
+
if (isWrappedWithT) return;
|
|
4462
4502
|
tFunctionNodes.forEach(function (node) {
|
|
4463
4503
|
context.report({
|
|
4464
4504
|
node: node,
|
|
@@ -6487,6 +6527,110 @@
|
|
|
6487
6527
|
}
|
|
6488
6528
|
};
|
|
6489
6529
|
|
|
6530
|
+
var REACT_I18_IMPORT_PATTERN = {
|
|
6531
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
6532
|
+
source: {
|
|
6533
|
+
type: TYPES.LITERAL,
|
|
6534
|
+
value: "react-i18next"
|
|
6535
|
+
},
|
|
6536
|
+
specifiers: [{
|
|
6537
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
6538
|
+
}]
|
|
6539
|
+
};
|
|
6540
|
+
var WITH_T_HOC_PATTERN = {
|
|
6541
|
+
type: TYPES.VARIABLE_DECLARATION,
|
|
6542
|
+
kind: "const",
|
|
6543
|
+
declarations: [{
|
|
6544
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
6545
|
+
init: {
|
|
6546
|
+
type: TYPES.CALL_EXPRESSION,
|
|
6547
|
+
callee: {
|
|
6548
|
+
name: "withT"
|
|
6549
|
+
},
|
|
6550
|
+
arguments: [{
|
|
6551
|
+
body: {
|
|
6552
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
6553
|
+
body: function body(_body) {
|
|
6554
|
+
return _body.length >= 2;
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
}]
|
|
6558
|
+
},
|
|
6559
|
+
id: {
|
|
6560
|
+
type: TYPES.IDENTIFIER,
|
|
6561
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
6562
|
+
}
|
|
6563
|
+
}]
|
|
6564
|
+
};
|
|
6565
|
+
|
|
6566
|
+
var insertTextAfterPosition = function insertTextAfterPosition(position, inputString, textToInsert) {
|
|
6567
|
+
var firstCharacter = inputString.charAt(position);
|
|
6568
|
+
var restOfString = inputString.slice(position + 1);
|
|
6569
|
+
return firstCharacter + textToInsert + restOfString;
|
|
6570
|
+
};
|
|
6571
|
+
|
|
6572
|
+
var noWithTForSmartComponents = {
|
|
6573
|
+
meta: {
|
|
6574
|
+
type: "problem",
|
|
6575
|
+
docs: {
|
|
6576
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-withT-for-smart-components.md",
|
|
6577
|
+
description: "Disallows usage of 'withT' HOC in smart components."
|
|
6578
|
+
},
|
|
6579
|
+
fixable: "code"
|
|
6580
|
+
},
|
|
6581
|
+
create: function create(context) {
|
|
6582
|
+
return {
|
|
6583
|
+
VariableDeclaration: function VariableDeclaration(node) {
|
|
6584
|
+
if (!pure.matches(WITH_T_HOC_PATTERN, node)) return;
|
|
6585
|
+
var arrowFunctionExpression = node.declarations[0].init.arguments[0];
|
|
6586
|
+
var body = arrowFunctionExpression.body;
|
|
6587
|
+
context.report({
|
|
6588
|
+
node: node,
|
|
6589
|
+
message: NO_WITH_T_IN_SMART_COMPONENTS,
|
|
6590
|
+
fix: function fix(fixer) {
|
|
6591
|
+
var fixers = [];
|
|
6592
|
+
var _arrowFunctionExpress = _toArray(arrowFunctionExpression.params),
|
|
6593
|
+
props = _arrowFunctionExpress[0],
|
|
6594
|
+
restParams = _arrowFunctionExpress.slice(1);
|
|
6595
|
+
var getPropsCode = function getPropsCode() {
|
|
6596
|
+
if (ramda.isEmpty(arrowFunctionExpression.params)) return "";
|
|
6597
|
+
if (props.type === TYPES.IDENTIFIER) {
|
|
6598
|
+
return "{...".concat(getCode$1(context, props), " }");
|
|
6599
|
+
}
|
|
6600
|
+
if (props.type === TYPES.OBJECT_PATTERN) {
|
|
6601
|
+
var _props$properties, _props$properties2, _props$properties2$0$;
|
|
6602
|
+
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") {
|
|
6603
|
+
return "";
|
|
6604
|
+
}
|
|
6605
|
+
return "{".concat(props.properties.map(function (property) {
|
|
6606
|
+
return getCode$1(context, property);
|
|
6607
|
+
}).filter(pure.isNot("t")).join(", "), " }");
|
|
6608
|
+
}
|
|
6609
|
+
return "";
|
|
6610
|
+
};
|
|
6611
|
+
var codeInsideBody = getCode$1(context, body);
|
|
6612
|
+
var codeWithUseTranslation = insertTextAfterPosition(0, codeInsideBody, "const { t } = useTranslation();\n");
|
|
6613
|
+
var updatedProps = getPropsCode();
|
|
6614
|
+
var replacedCodeWithUseTranslation = "(".concat(updatedProps).concat(ramda.isEmpty(restParams) ? "" : "".concat(pure.isNotEmpty(updatedProps) ? ", " : "").concat(restParams.map(function (param) {
|
|
6615
|
+
return getCode$1(context, param);
|
|
6616
|
+
}).join(", ")), ") => ").concat(codeWithUseTranslation);
|
|
6617
|
+
var replaceIncorrectWithTCode = fixer.replaceText(node.declarations[0].init, replacedCodeWithUseTranslation);
|
|
6618
|
+
fixers.push(replaceIncorrectWithTCode);
|
|
6619
|
+
var importUseTranslation = addFunctionImport({
|
|
6620
|
+
context: context,
|
|
6621
|
+
fixer: fixer,
|
|
6622
|
+
functions: ["useTranslation"],
|
|
6623
|
+
importPattern: REACT_I18_IMPORT_PATTERN
|
|
6624
|
+
});
|
|
6625
|
+
importUseTranslation && fixers.push(importUseTranslation);
|
|
6626
|
+
return fixers;
|
|
6627
|
+
}
|
|
6628
|
+
});
|
|
6629
|
+
}
|
|
6630
|
+
};
|
|
6631
|
+
}
|
|
6632
|
+
};
|
|
6633
|
+
|
|
6490
6634
|
var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
|
|
6491
6635
|
|
|
6492
6636
|
var importedFromNeeto = function importedFromNeeto(context, node) {
|
|
@@ -26614,6 +26758,7 @@
|
|
|
26614
26758
|
|
|
26615
26759
|
var index = {
|
|
26616
26760
|
rules: {
|
|
26761
|
+
"no-withT-for-smart-components": noWithTForSmartComponents,
|
|
26617
26762
|
"no-large-functions-inside-jsx": noLargeFunctionsInsideJsx,
|
|
26618
26763
|
"use-standard-date-time-formats": useStandardDateTimeFormats,
|
|
26619
26764
|
"no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
|