@bigbinary/eslint-plugin-neeto 1.1.19 → 1.1.20
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/dist/index.js +119 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3885,7 +3885,7 @@
|
|
|
3885
3885
|
name: ramda.test(PASCAL_CASE_REGEX)
|
|
3886
3886
|
}
|
|
3887
3887
|
};
|
|
3888
|
-
var EXPORTED_WITH_T_PATTERN = {
|
|
3888
|
+
var EXPORTED_WITH_T_PATTERN$1 = {
|
|
3889
3889
|
type: TYPES.EXPORT_DEFAULT_DECLARATION,
|
|
3890
3890
|
declaration: {
|
|
3891
3891
|
type: TYPES.CALL_EXPRESSION,
|
|
@@ -4484,7 +4484,7 @@
|
|
|
4484
4484
|
if (!isInsideComponentsDirectory(context)) return;
|
|
4485
4485
|
var componentNodes = findMatchingNodesDeep(node.body, COMPONENT_PATTERN);
|
|
4486
4486
|
if (ramda.isEmpty(componentNodes)) return;
|
|
4487
|
-
var isExportedWithT = patternExistsDeep(EXPORTED_WITH_T_PATTERN, node);
|
|
4487
|
+
var isExportedWithT = patternExistsDeep(EXPORTED_WITH_T_PATTERN$1, node);
|
|
4488
4488
|
componentNodes.forEach(function (node) {
|
|
4489
4489
|
var tFunctionMemeberExpressionNodes = findMatchingNodesDeep(node, T_FUNCTION_MEMBER_EXPRESSION_PATTERN);
|
|
4490
4490
|
tFunctionMemeberExpressionNodes.forEach(function (node) {
|
|
@@ -6537,6 +6537,12 @@
|
|
|
6537
6537
|
type: TYPES.IMPORT_SPECIFIER
|
|
6538
6538
|
}]
|
|
6539
6539
|
};
|
|
6540
|
+
|
|
6541
|
+
// const Component = withT(({ t, userName, ...otherProps }, randomProps) => {
|
|
6542
|
+
// const a = useRef();
|
|
6543
|
+
// const [isOpen, setIsOpen] = useState(false);
|
|
6544
|
+
// return (t("Hello"));
|
|
6545
|
+
// });
|
|
6540
6546
|
var WITH_T_HOC_PATTERN = {
|
|
6541
6547
|
type: TYPES.VARIABLE_DECLARATION,
|
|
6542
6548
|
kind: "const",
|
|
@@ -6563,11 +6569,107 @@
|
|
|
6563
6569
|
}]
|
|
6564
6570
|
};
|
|
6565
6571
|
|
|
6572
|
+
// export default withT(Component);
|
|
6573
|
+
var EXPORTED_WITH_T_PATTERN = {
|
|
6574
|
+
type: TYPES.EXPORT_DEFAULT_DECLARATION,
|
|
6575
|
+
declaration: {
|
|
6576
|
+
type: TYPES.CALL_EXPRESSION,
|
|
6577
|
+
callee: {
|
|
6578
|
+
type: TYPES.IDENTIFIER,
|
|
6579
|
+
name: "withT"
|
|
6580
|
+
},
|
|
6581
|
+
arguments: ramda.any(pure.matches({
|
|
6582
|
+
type: TYPES.IDENTIFIER,
|
|
6583
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
6584
|
+
}))
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
var SMART_COMPONENT_PATTERN = {
|
|
6588
|
+
type: TYPES.VARIABLE_DECLARATION,
|
|
6589
|
+
kind: "const",
|
|
6590
|
+
declarations: [{
|
|
6591
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
6592
|
+
init: {
|
|
6593
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
6594
|
+
body: {
|
|
6595
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
6596
|
+
body: function body(_body2) {
|
|
6597
|
+
return _body2.length >= 2;
|
|
6598
|
+
}
|
|
6599
|
+
}
|
|
6600
|
+
},
|
|
6601
|
+
id: {
|
|
6602
|
+
type: TYPES.IDENTIFIER,
|
|
6603
|
+
name: ramda.test(PASCAL_CASE_REGEX)
|
|
6604
|
+
}
|
|
6605
|
+
}]
|
|
6606
|
+
};
|
|
6607
|
+
|
|
6608
|
+
var getPropsCode = function getPropsCode(context, arrowFunctionExpression, props) {
|
|
6609
|
+
if (ramda.isEmpty(arrowFunctionExpression.params)) return "";
|
|
6610
|
+
if (props.type === TYPES.IDENTIFIER) {
|
|
6611
|
+
return "{...".concat(getCode$1(context, props), " }");
|
|
6612
|
+
}
|
|
6613
|
+
if (props.type === TYPES.OBJECT_PATTERN) {
|
|
6614
|
+
var _props$properties, _props$properties2, _props$properties2$0$;
|
|
6615
|
+
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") {
|
|
6616
|
+
return "";
|
|
6617
|
+
}
|
|
6618
|
+
return "{".concat(props.properties.map(function (property) {
|
|
6619
|
+
return getCode$1(context, property);
|
|
6620
|
+
}).filter(pure.isNot("t")).join(", "), " }");
|
|
6621
|
+
}
|
|
6622
|
+
return "";
|
|
6623
|
+
};
|
|
6624
|
+
var getCodeWithUseTranslationHook = function getCodeWithUseTranslationHook(context, arrowFunctionExpression) {
|
|
6625
|
+
var _arrowFunctionExpress = _toArray(arrowFunctionExpression.params),
|
|
6626
|
+
props = _arrowFunctionExpress[0],
|
|
6627
|
+
restParams = _arrowFunctionExpress.slice(1);
|
|
6628
|
+
var codeInsideBody = getCode$1(context, arrowFunctionExpression.body);
|
|
6629
|
+
var codeWithUseTranslation = insertTextAfterPosition(0, codeInsideBody, "const { t } = useTranslation();\n");
|
|
6630
|
+
var updatedProps = getPropsCode(context, arrowFunctionExpression, props);
|
|
6631
|
+
var replacedCodeWithUseTranslation = "(".concat(updatedProps).concat(ramda.isEmpty(restParams) ? "" : "".concat(pure.isNotEmpty(updatedProps) ? ", " : "{}, ").concat(restParams.map(function (param) {
|
|
6632
|
+
return getCode$1(context, param);
|
|
6633
|
+
}).join(", ")), ") => ").concat(codeWithUseTranslation);
|
|
6634
|
+
return replacedCodeWithUseTranslation;
|
|
6635
|
+
};
|
|
6636
|
+
var createUseTranslationImport = function createUseTranslationImport(context, fixer) {
|
|
6637
|
+
return addFunctionImport({
|
|
6638
|
+
context: context,
|
|
6639
|
+
fixer: fixer,
|
|
6640
|
+
functions: ["useTranslation"],
|
|
6641
|
+
importPattern: REACT_I18_IMPORT_PATTERN
|
|
6642
|
+
});
|
|
6643
|
+
};
|
|
6566
6644
|
var insertTextAfterPosition = function insertTextAfterPosition(position, inputString, textToInsert) {
|
|
6567
6645
|
var firstCharacter = inputString.charAt(position);
|
|
6568
6646
|
var restOfString = inputString.slice(position + 1);
|
|
6569
6647
|
return firstCharacter + textToInsert + restOfString;
|
|
6570
6648
|
};
|
|
6649
|
+
var reportError = function reportError(_ref) {
|
|
6650
|
+
var context = _ref.context,
|
|
6651
|
+
node = _ref.node,
|
|
6652
|
+
arrowFunctionExpression = _ref.arrowFunctionExpression,
|
|
6653
|
+
_ref$isExportStatemen = _ref.isExportStatement,
|
|
6654
|
+
isExportStatement = _ref$isExportStatemen === void 0 ? false : _ref$isExportStatemen;
|
|
6655
|
+
return context.report({
|
|
6656
|
+
node: node,
|
|
6657
|
+
message: NO_WITH_T_IN_SMART_COMPONENTS,
|
|
6658
|
+
fix: function fix(fixer) {
|
|
6659
|
+
var fixers = [];
|
|
6660
|
+
var replacedCodeWithUseTranslation = getCodeWithUseTranslationHook(context, arrowFunctionExpression);
|
|
6661
|
+
if (isExportStatement) {
|
|
6662
|
+
fixers.push(fixer.replaceText(node.declaration, node.declaration.arguments[0].name));
|
|
6663
|
+
fixers.push(fixer.replaceText(arrowFunctionExpression, replacedCodeWithUseTranslation));
|
|
6664
|
+
} else {
|
|
6665
|
+
fixers.push(fixer.replaceText(node.declarations[0].init, replacedCodeWithUseTranslation));
|
|
6666
|
+
}
|
|
6667
|
+
var importUseTranslation = createUseTranslationImport(context, fixer);
|
|
6668
|
+
importUseTranslation && fixers.push(importUseTranslation);
|
|
6669
|
+
return fixers;
|
|
6670
|
+
}
|
|
6671
|
+
});
|
|
6672
|
+
};
|
|
6571
6673
|
|
|
6572
6674
|
var noWithTForSmartComponents = {
|
|
6573
6675
|
meta: {
|
|
@@ -6579,52 +6681,26 @@
|
|
|
6579
6681
|
fixable: "code"
|
|
6580
6682
|
},
|
|
6581
6683
|
create: function create(context) {
|
|
6684
|
+
var componentDeclaration = null;
|
|
6582
6685
|
return {
|
|
6583
6686
|
VariableDeclaration: function VariableDeclaration(node) {
|
|
6687
|
+
componentDeclaration = node;
|
|
6584
6688
|
if (!pure.matches(WITH_T_HOC_PATTERN, node)) return;
|
|
6585
6689
|
var arrowFunctionExpression = node.declarations[0].init.arguments[0];
|
|
6586
|
-
|
|
6587
|
-
|
|
6690
|
+
reportError({
|
|
6691
|
+
context: context,
|
|
6588
6692
|
node: node,
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
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
|
-
}
|
|
6693
|
+
arrowFunctionExpression: arrowFunctionExpression
|
|
6694
|
+
});
|
|
6695
|
+
},
|
|
6696
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
|
6697
|
+
if (!pure.matches(EXPORTED_WITH_T_PATTERN, node)) return;
|
|
6698
|
+
if (!pure.matches(SMART_COMPONENT_PATTERN, componentDeclaration)) return;
|
|
6699
|
+
reportError({
|
|
6700
|
+
context: context,
|
|
6701
|
+
node: node,
|
|
6702
|
+
arrowFunctionExpression: componentDeclaration.declarations[0].init,
|
|
6703
|
+
isExportStatement: true
|
|
6628
6704
|
});
|
|
6629
6705
|
}
|
|
6630
6706
|
};
|