@bigbinary/eslint-plugin-neeto 1.1.10 → 1.1.11

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 +110 -0
  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",
@@ -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;
@@ -26426,6 +26535,7 @@
26426
26535
 
26427
26536
  var index = {
26428
26537
  rules: {
26538
+ "no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
26429
26539
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
26430
26540
  "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
26431
26541
  "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.11",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {