@bigbinary/eslint-plugin-neeto 1.1.10 → 1.1.12

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 +2 -0
  2. package/dist/index.js +120 -8
  3. 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-dumb-components-with-use-translation](./docs/src/rules/no-dumb-components-with-use-translation.md)
50
+ - [no-unnecessary-if-condition](./docs/src/rules/no-unnecessary-if-condition.md)
49
51
  - [api-connector-name-should-match-filename](./docs/src/rules/api-connector-name-should-match-filename.md)
50
52
  - [api-connector-should-use-default-export](./docs/src/rules/api-connector-should-use-default-export.md)
51
53
  - [combine-multiple-independent-awaits](./docs/src/rules/combine-multiple-independent-awaits.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-dumb-components-with-use-translation": "error",
45
46
  "@bigbinary/neeto/api-connector-name-should-match-filename": "error",
46
47
  "@bigbinary/neeto/api-connector-should-use-default-export": "error",
47
48
  "@bigbinary/neeto/combine-multiple-independent-awaits": "warn",
@@ -460,7 +461,7 @@
460
461
  return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
461
462
  };
462
463
  var suggestCommonConstants = function suggestCommonConstants(constantName, repository) {
463
- return "Use \"".concat(constantName, "\" from \"@bigbinary/").concat(repository, "/constants\"");
464
+ return "Use \"".concat(constantName, "\" from \"@bigbinary/").concat(repository, "\"");
464
465
  };
465
466
  var addRequiredPeerDependencies$1 = function addRequiredPeerDependencies(packageName) {
466
467
  return "".concat(packageName, " should be added to peerDependencies");
@@ -5891,6 +5892,114 @@
5891
5892
  }
5892
5893
  };
5893
5894
 
5895
+ function _toArray(arr) {
5896
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableRest();
5897
+ }
5898
+
5899
+ var REACT_HOOKS_VARIABLE_DECLARATION_PATTERN = {
5900
+ type: TYPES.VARIABLE_DECLARATION,
5901
+ declarations: [{
5902
+ type: TYPES.VARIABLE_DECLARATOR,
5903
+ init: {
5904
+ type: TYPES.CALL_EXPRESSION,
5905
+ callee: {
5906
+ type: TYPES.IDENTIFIER,
5907
+ name: ramda.test(/use[a-zA-z0-9].+/)
5908
+ }
5909
+ }
5910
+ }]
5911
+ };
5912
+ var REACT_HOOKS_CALL_PATTERN = {
5913
+ type: TYPES.EXPRESSION_STATEMENT,
5914
+ expression: {
5915
+ type: TYPES.CALL_EXPRESSION,
5916
+ callee: {
5917
+ type: TYPES.IDENTIFIER,
5918
+ name: ramda.test(/use[a-zA-z0-9].+/)
5919
+ }
5920
+ }
5921
+ };
5922
+
5923
+ // import { functionName } from "neetocommons/react-utils";
5924
+ var NEETO_COMMONS_REACT_UTILS_IMPORT_PATTERN = {
5925
+ type: TYPES.IMPORT_DECLARATION,
5926
+ source: {
5927
+ type: TYPES.LITERAL,
5928
+ value: "neetocommons/react-utils"
5929
+ },
5930
+ specifiers: [{
5931
+ type: TYPES.IMPORT_SPECIFIER
5932
+ }]
5933
+ };
5934
+
5935
+ var noDumbComponentsWithUseTranslation = {
5936
+ meta: {
5937
+ type: "suggestion",
5938
+ docs: {
5939
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-dumb-components-with-use-translation.md",
5940
+ description: "Disallows creating dumb components with useTranslation hook"
5941
+ },
5942
+ fixable: "code"
5943
+ },
5944
+ create: function create(context) {
5945
+ return {
5946
+ VariableDeclaration: function VariableDeclaration(node) {
5947
+ if (!pure.matches(COMPONENT_PATTERN, node)) return;
5948
+ var _node$declarations = _slicedToArray(node.declarations, 1),
5949
+ arrowFunctionExpression = _node$declarations[0].init;
5950
+ var blockStatement = arrowFunctionExpression.body;
5951
+ if (!blockStatement.body) return;
5952
+ var useTranslationHook = pure.findBy(USE_TRANSLATION_HOOK_PATTERN, blockStatement.body);
5953
+ if (!useTranslationHook) return;
5954
+ var hasHooksOtherThanTranslationHook = blockStatement.body.some(function (node) {
5955
+ return (pure.matches(REACT_HOOKS_CALL_PATTERN, node) || pure.matches(REACT_HOOKS_VARIABLE_DECLARATION_PATTERN, node)) && !pure.matches(USE_TRANSLATION_HOOK_PATTERN, node);
5956
+ });
5957
+ if (hasHooksOtherThanTranslationHook) return;
5958
+ context.report({
5959
+ node: node,
5960
+ message: "Use withT HOC instead of useTranslation hook",
5961
+ fix: function fix(fixer) {
5962
+ var fixers = [];
5963
+ var _arrowFunctionExpress = _toArray(arrowFunctionExpression.params),
5964
+ props = _arrowFunctionExpress[0],
5965
+ restParams = _arrowFunctionExpress.slice(1);
5966
+ var getPropsCode = function getPropsCode() {
5967
+ if (ramda.isEmpty(arrowFunctionExpression.params) || !props) {
5968
+ return "{ t }";
5969
+ }
5970
+ if (props.type === TYPES.IDENTIFIER) {
5971
+ return "{ t, ...".concat(getCode$1(context, props), " }");
5972
+ }
5973
+ if (props.type === TYPES.OBJECT_PATTERN) {
5974
+ return "{ t, ".concat(props.properties.map(function (property) {
5975
+ return getCode$1(context, property);
5976
+ }).join(", "), " }");
5977
+ }
5978
+ return "";
5979
+ };
5980
+ var blockStatementCode = getCode$1(context, blockStatement);
5981
+ var useTranslationHookCode = getCode$1(context, useTranslationHook);
5982
+ var body = blockStatementCode.replace(useTranslationHookCode, "");
5983
+ var withTWrap = "withT((".concat(getPropsCode()).concat(pure.isNotEmpty(restParams) ? ", ".concat(restParams.map(function (param) {
5984
+ return getCode$1(context, param);
5985
+ }).join(", ")) : "", ") => ").concat(body, ")");
5986
+ var wrapWithWithT = fixer.replaceText(arrowFunctionExpression, withTWrap);
5987
+ fixers.push(wrapWithWithT);
5988
+ var importWithT = addFunctionImport({
5989
+ context: context,
5990
+ fixer: fixer,
5991
+ functions: ["withT"],
5992
+ importPattern: NEETO_COMMONS_REACT_UTILS_IMPORT_PATTERN
5993
+ });
5994
+ importWithT && fixers.push(importWithT);
5995
+ return fixers;
5996
+ }
5997
+ });
5998
+ }
5999
+ };
6000
+ }
6001
+ };
6002
+
5894
6003
  var nonDefaultParam = function nonDefaultParam(_ref) {
5895
6004
  var type = _ref.type;
5896
6005
  return type !== TYPES.ASSIGNMENT_PATTERN;
@@ -7987,8 +8096,8 @@
7987
8096
  };
7988
8097
 
7989
8098
  var IMPORT_SOURCES = {
7990
- "neeto-commons-frontend": "neetocommons/constants",
7991
- "neeto-team-members-frontend": "neetoteam/constants"
8099
+ "neeto-commons-frontend/constants": ["neetocommons/constants", "@bigbinary/neeto-commons-frontend/constants"],
8100
+ "neeto-team-members-frontend": ["neetoteam", "@bigbinary/neeto-team-members-frontend"]
7992
8101
  };
7993
8102
  var TRANSLATION_VERBS_PATTERN = {
7994
8103
  type: TYPES.OBJECT_EXPRESSION,
@@ -8019,7 +8128,9 @@
8019
8128
  },
8020
8129
  source: {
8021
8130
  type: TYPES.LITERAL,
8022
- value: IMPORT_SOURCES[repository]
8131
+ value: function value(_value2) {
8132
+ return ramda.includes(_value2, IMPORT_SOURCES[repository]);
8133
+ }
8023
8134
  }
8024
8135
  };
8025
8136
  };
@@ -8076,14 +8187,14 @@
8076
8187
  var checkTranslationVerbs = function checkTranslationVerbs(node, context) {
8077
8188
  var _parentNode$callee;
8078
8189
  var parentNode = node.parent;
8079
- var repository = "neeto-commons-frontend";
8190
+ var repository = "neeto-commons-frontend/constants";
8080
8191
  var isCommonConstant = parentNode.type === TYPES.VARIABLE_DECLARATOR ? pure.matches(TRANSLATION_VERBS_PATTERN, parentNode.init) : ((_parentNode$callee = parentNode.callee) === null || _parentNode$callee === void 0 ? void 0 : _parentNode$callee.name) === "t" && !pure.existsBy(constantImportPattern(node.name, repository), getAllImports(node));
8081
8192
  if (isCommonConstant) {
8082
8193
  reportIssue({
8083
8194
  node: node,
8084
8195
  repository: repository,
8085
8196
  context: context,
8086
- constantName: "TRANSLATION_".concat(node.name)
8197
+ constantName: node.name
8087
8198
  });
8088
8199
  }
8089
8200
  };
@@ -8092,7 +8203,7 @@
8092
8203
  meta: {
8093
8204
  type: "suggestion",
8094
8205
  docs: {
8095
- url: "",
8206
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-common-constants.md",
8096
8207
  description: "Suggests using common constants from neeto-team-members and neeto-commons-frontend repos"
8097
8208
  }
8098
8209
  },
@@ -8106,7 +8217,7 @@
8106
8217
  checkAndReport({
8107
8218
  node: node,
8108
8219
  constants: neetoCommonsConstants__namespace,
8109
- repository: "neeto-commons-frontend",
8220
+ repository: "neeto-commons-frontend/constants",
8110
8221
  context: context
8111
8222
  });
8112
8223
  checkAndReport({
@@ -26426,6 +26537,7 @@
26426
26537
 
26427
26538
  var index = {
26428
26539
  rules: {
26540
+ "no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
26429
26541
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
26430
26542
  "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
26431
26543
  "combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {