@bigbinary/eslint-plugin-neeto 1.1.16 → 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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +107 -0
  3. 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"];
@@ -6487,6 +6489,110 @@
6487
6489
  }
6488
6490
  };
6489
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
+
6490
6596
  var NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
6491
6597
 
6492
6598
  var importedFromNeeto = function importedFromNeeto(context, node) {
@@ -26614,6 +26720,7 @@
26614
26720
 
26615
26721
  var index = {
26616
26722
  rules: {
26723
+ "no-withT-for-smart-components": noWithTForSmartComponents,
26617
26724
  "no-large-functions-inside-jsx": noLargeFunctionsInsideJsx,
26618
26725
  "use-standard-date-time-formats": useStandardDateTimeFormats,
26619
26726
  "no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {