@bigbinary/eslint-plugin-neeto 1.0.12 → 1.0.13

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 +6 -1
  2. package/dist/index.js +628 -80
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ neeto.
8
8
  Install the plugin from npm:
9
9
 
10
10
  ```bash
11
- yarn add -D "@bigbinary/eslint-plugin-neeto@1.0.12"
11
+ yarn add -D "@bigbinary/eslint-plugin-neeto@1.0.13"
12
12
  ```
13
13
 
14
14
  In your eslintrc.js file, add `neeto` in the `plugins` list and add the required
@@ -30,6 +30,7 @@ module.exports = {
30
30
 
31
31
  ## Exported rules
32
32
 
33
+ - [consistent-button-link-anchor](./docs/src/rules/consistent-button-link-anchor.md)
33
34
  - [neetocommons-tips](./docs/src/rules/neetocommons-tips.md)
34
35
  - [api-connector-name-should-match-filename](./docs/src/rules/api-connector-name-should-match-filename.md)
35
36
  - [api-connector-should-use-default-export](./docs/src/rules/api-connector-should-use-default-export.md)
@@ -45,10 +46,14 @@ module.exports = {
45
46
  - [no-namespace-specifier-import-for-ramda](./docs/src/rules/no-namespace-specifier-import-for-ramda.md)
46
47
  - [no-redundant-jsx-expression](./docs/src/rules/no-redundant-jsx-expression.md)
47
48
  - [no-redundant-string-templates](./docs/src/rules/no-redundant-string-templates.md)
49
+ - [no-routes-destructure-and-reassignment](./docs/src/rules/no-routes-destructure-and-reassignment.md)
48
50
  - [prefix-neeto-ui-import-alias](./docs/src/rules/prefix-neeto-ui-import-alias.md)
49
51
  - [ramda-tips](./docs/src/rules/ramda-tips.md)
52
+ - [routes-should-match-object-path](./docs/src/rules/routes-should-match-object-path.md)
53
+ - [routes-should-be-declared-and-default-exported](./docs/src/rules/routes-should-be-declared-and-default-exported.md)
50
54
  - [use-axios-config-for-passing-query-parameters](./docs/src/rules/use-axios-config-for-passing-query-parameters.md)
51
55
  - [use-constant-case](./docs/src/rules/use-constant-case.md)
56
+ - [use-common-routes](./docs/src/rules/use-common-routes.md)
52
57
  - [use-snake-case-for-api-connector-filename](./docs/src/rules/use-snake-case-for-api-connector-filename.md)
53
58
  - [use-webpack-alias](./docs/src/rules/use-webpack-alias.md)
54
59
 
package/dist/index.js CHANGED
@@ -224,13 +224,15 @@
224
224
  });
225
225
  });
226
226
  ramda.complement(ramda.isNil);
227
- ramda.complement(ramda.isEmpty);
228
- ramda.curry(function (x, y) {
227
+ var isNotEmpty$1 = ramda.complement(ramda.isEmpty);
228
+ var notEquals = ramda.curry(function (x, y) {
229
229
  return x !== y;
230
230
  });
231
+ var isNot$1 = notEquals;
231
232
  ramda.complement(ramda.equals);
232
233
 
233
234
  const APIS_DIRECTORY = "app/javascript/src/apis";
235
+ const ROUTES_FILE_PATH = "app/javascript/src/common/routes.js";
234
236
  const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
235
237
  const TYPES = {
236
238
  ARRAY_EXPRESSION: "ArrayExpression",
@@ -240,8 +242,11 @@
240
242
  BINARY_EXPRESSION: "BinaryExpression",
241
243
  CALL_EXPRESSION: "CallExpression",
242
244
  EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
245
+ EXPORT_DEFAULT_DECLARATION: "ExportDefaultDeclaration",
243
246
  IDENTIFIER: "Identifier",
244
247
  IF_STATEMENT: "IfStatement",
248
+ IMPORT_DECLARATION: "ImportDeclaration",
249
+ IMPORT_DEFAULT_SPECIFIER: "ImportDefaultSpecifier",
245
250
  LITERAL: "Literal",
246
251
  LOGICAL_EXPRESSION: "LogicalExpression",
247
252
  MEMBER_EXPRESSION: "MemberExpression",
@@ -252,11 +257,13 @@
252
257
  SPREAD_ELEMENT: "SpreadElement",
253
258
  TEMPLATE_LITERAL: "TemplateLiteral",
254
259
  UNARY_EXPRESSION: "UnaryExpression",
260
+ VARIABLE_DECLARATION: "VariableDeclaration",
255
261
  VARIABLE_DECLARATOR: "VariableDeclarator",
256
262
  WHILE_STATEMENT: "WhileStatement",
257
263
  JSX_ATTRIBUTE: "JSXAttribute",
258
264
  JSX_ELEMENT: "JSXElement",
259
- JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer"
265
+ JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer",
266
+ JSX_IDENTIFIER: "JSXIdentifier"
260
267
  };
261
268
  const IMPORT_DECLARATION = {
262
269
  type: "ImportDeclaration",
@@ -274,7 +281,7 @@
274
281
  * @returns the source code corresponding to the supplied node.
275
282
  */
276
283
 
277
- const getCode = (context, node) => context.getSourceCode().text.substr(node.range[0], node.range[1] - node.range[0]);
284
+ const getCode$1 = (context, node) => context.getSourceCode().text.substr(node.range[0], node.range[1] - node.range[0]);
278
285
  /**
279
286
  * Checks if the specified package is imported or not
280
287
  * using the package name or any alias
@@ -370,9 +377,20 @@
370
377
  const NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE = `API actions should use named parameters for more than ${API_ACTIONS_ARGUMENT_LIMIT} parameters`;
371
378
  const NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE = `Functions should use named parameters for more than ${ARGUMENT_LIMIT} parameters`;
372
379
  const NO_GLOBALPROPS_REASSIGNMENT_MESSAGE = "globalProps or its nested properties should not be re-assigned.";
380
+ const NO_ROUTES_ASSIGNMENT = "`routes` or its nested properties should not be assigned to other variables.";
381
+ const NO_ROUTES_REASSIGNMENT = "`routes` or its nested properties should not be re-assigned.";
373
382
  const NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE = 'Use `import { methodsToImport } from "ramda"` instead';
374
383
  const PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE = "Aliases for anything imported from neetoUI or neetoIcons should start with `NeetoUI`";
384
+ const ROUTE_SHOULD_BE_A_STRING = "Route should be a plain string literal.";
385
+ const ROUTE_SHOULD_MATCH_OBJECT_PATH = "Route string should match with its object path.";
386
+ const ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
387
+ const ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
388
+ const ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
375
389
  const USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
390
+ const USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
391
+ const USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
392
+ const USE_BUTTON_TO_FOR_LINK_NAVIGATION = "Use `to` prop of Button (<Button to='path'>) for click-navigation instead of onClick handler";
393
+ const USE_BUTTON_TO_FOR_ANCHOR_NAVIGATION = "Use `href` prop of Button (<Button href='path'>) for click-navigation instead of onClick handler";
376
394
 
377
395
  const toCamelCase = text => {
378
396
  const capitalized = text.split(/[^0-9a-z]/i).map(part => `${part[0].toUpperCase()}${part.slice(1)}`).join("");
@@ -468,14 +486,14 @@
468
486
  * @param {Object} pattern the pattern to match partially
469
487
  */
470
488
 
471
- const patternExistsDeep = (obj, pattern) => {
489
+ const patternExistsDeep = ramda.curry((pattern, obj) => {
472
490
  if (typeof obj !== "object" || ramda.isNil(obj)) return false;
473
491
  if (matches(pattern, obj)) return true;
474
492
  return Object.entries(obj).some(([key, value]) => {
475
493
  if (key === "parent") return false;
476
- return patternExistsDeep(value, pattern);
494
+ return patternExistsDeep(pattern, value);
477
495
  });
478
- };
496
+ });
479
497
 
480
498
  const AWAIT_DECLARATION_PATTERN = {
481
499
  type: TYPES.VARIABLE_DECLARATOR,
@@ -483,7 +501,7 @@
483
501
  type: TYPES.AWAIT_EXPRESSION
484
502
  }
485
503
  };
486
- const IDENTIFIER_PATTERN = {
504
+ const IDENTIFIER_PATTERN$1 = {
487
505
  type: TYPES.IDENTIFIER
488
506
  };
489
507
 
@@ -493,8 +511,8 @@
493
511
  return ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : (_node$parent$right = _node$parent.right) === null || _node$parent$right === void 0 ? void 0 : _node$parent$right.name) === node.name;
494
512
  };
495
513
 
496
- const getChildCode = (context, nodes, pathArray) => nodes.map(node => getCode(context, ramda.path(pathArray, node))).join(", ");
497
- const getIdentifiersInNode = node => findMatchingNodesDeep(node, IDENTIFIER_PATTERN).filter(node => !(isKeyNode(node) || isDefaultValueNode(node) || node.parent.computed)); // id from const { id : orgID } = ...
514
+ const getChildCode = (context, nodes, pathArray) => nodes.map(node => getCode$1(context, ramda.path(pathArray, node))).join(", ");
515
+ const getIdentifiersInNode = node => findMatchingNodesDeep(node, IDENTIFIER_PATTERN$1).filter(node => !(isKeyNode(node) || isDefaultValueNode(node) || node.parent.computed)); // id from const { id : orgID } = ...
498
516
 
499
517
  const isKeyNode = node => {
500
518
  var _node$parent2;
@@ -513,7 +531,7 @@
513
531
  return isPrevLineSameAsLastAwait || areBothAwaitsInSameLine;
514
532
  };
515
533
 
516
- const identifiersUsed = (node, identifiers) => identifiers.length > 0 && identifiers.some(identifier => findMatchingNodesDeep(node, { ...IDENTIFIER_PATTERN,
534
+ const identifiersUsed = (node, identifiers) => identifiers.length > 0 && identifiers.some(identifier => findMatchingNodesDeep(node, { ...IDENTIFIER_PATTERN$1,
517
535
  name: identifier.name
518
536
  }).some(node => !isKeyNode(node)));
519
537
 
@@ -596,6 +614,520 @@
596
614
  })
597
615
  };
598
616
 
617
+ const SPECIAL_KEYS = ["home", "index", "show"]; // import routes from "common/routes", import routes from "routes"
618
+
619
+ const ROUTES_IMPORT_PATTERN = {
620
+ type: TYPES.IMPORT_DECLARATION,
621
+ source: {
622
+ type: TYPES.LITERAL,
623
+ value: matchesAny(["routes", "common/routes"])
624
+ },
625
+ specifiers: [{
626
+ type: TYPES.IMPORT_DEFAULT_SPECIFIER,
627
+ local: {
628
+ type: TYPES.IDENTIFIER,
629
+ name: "routes"
630
+ }
631
+ }]
632
+ }; // const routes = { home: "/" }, const routes = "/", const routes = ["/"] etc
633
+
634
+ const DECALARATION_PATTERN = {
635
+ type: TYPES.VARIABLE_DECLARATION,
636
+ declarations: [{
637
+ type: TYPES.VARIABLE_DECLARATOR,
638
+ id: {
639
+ type: TYPES.IDENTIFIER,
640
+ name: "routes"
641
+ }
642
+ }]
643
+ }; // const routes = { home: "/" }
644
+
645
+ const OBJECT_DECALARATION_PATTERN = ramda.assocPath(["declarations", 0, "init"], {
646
+ type: TYPES.OBJECT_EXPRESSION
647
+ }, DECALARATION_PATTERN); // export const routes = { home: "/" }
648
+
649
+ const EXPORT_NAMED_DECLARATION_PATTERN = {
650
+ type: TYPES.EXPORT_NAMED_DECLARATION,
651
+ declaration: matches(OBJECT_DECALARATION_PATTERN)
652
+ }; // export default routes, export default deepFreezeObject(routes)
653
+
654
+ const DEFAULT_EXPORT_PATTERN = {
655
+ type: TYPES.EXPORT_DEFAULT_DECLARATION,
656
+ declaration: matchesAny([{
657
+ type: TYPES.IDENTIFIER,
658
+ name: "routes"
659
+ }, {
660
+ type: TYPES.CALL_EXPRESSION,
661
+ callee: {
662
+ name: "deepFreezeObject"
663
+ },
664
+ arguments: [{
665
+ name: "routes"
666
+ }]
667
+ }])
668
+ };
669
+ const IDENTIFIER_PATTERN = {
670
+ type: TYPES.IDENTIFIER,
671
+ name: "routes"
672
+ };
673
+ const MEMBER_EXPRESSION_PATTERN = {
674
+ type: TYPES.MEMBER_EXPRESSION,
675
+ object: {
676
+ type: TYPES.IDENTIFIER,
677
+ name: "routes"
678
+ }
679
+ }; // const { home } = routes, const homeRoute = routes.home
680
+
681
+ const ASSIGNMENT_PATTERN = {
682
+ id: {
683
+ type: matchesAny([TYPES.IDENTIFIER, TYPES.OBJECT_PATTERN])
684
+ },
685
+ init: matchesAny([IDENTIFIER_PATTERN, MEMBER_EXPRESSION_PATTERN])
686
+ }; // const routes = { home: "/" }, const routes.home = "/"
687
+
688
+ const REASSIGNMENT_PATTERN = {
689
+ left: matchesAny([IDENTIFIER_PATTERN, MEMBER_EXPRESSION_PATTERN])
690
+ }; // path={string | template literals}, to={string | template literals}
691
+
692
+ const PATH_OR_TO_PROP_PATTERN = {
693
+ type: TYPES.JSX_ATTRIBUTE,
694
+ name: {
695
+ type: TYPES.JSX_IDENTIFIER,
696
+ name: ramda.includes(ramda.__, ["to", "path"])
697
+ },
698
+ value: matchesAny([{
699
+ type: TYPES.JSX_EXPRESSION_CONTAINER,
700
+ expression: {
701
+ type: ramda.includes(ramda.__, [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL]),
702
+ value: notEquals("*")
703
+ }
704
+ }, {
705
+ type: TYPES.LITERAL,
706
+ value: notEquals("*")
707
+ }])
708
+ };
709
+ /*
710
+ <Route path={string | template literals} />, <Redirect to={string | template literals} />
711
+ <Link to={string | template literals} />, <NavLink to={string | template literals} />
712
+ */
713
+
714
+ const NAVIGATION_COMPONENTS_PATTERN = {
715
+ name: {
716
+ type: TYPES.JSX_IDENTIFIER,
717
+ name: ramda.includes(ramda.__, ["Route", "Redirect", "Link", "NavLink"])
718
+ },
719
+ attributes: ramda.any(matches(PATH_OR_TO_PROP_PATTERN))
720
+ }; // history.push(string| | template literal), history.replace(string | template literal)
721
+
722
+ const HISTORY_PATTERN = {
723
+ callee: {
724
+ type: TYPES.MEMBER_EXPRESSION,
725
+ object: {
726
+ name: "history"
727
+ },
728
+ property: {
729
+ name: ramda.includes(ramda.__, ["push", "replace"])
730
+ }
731
+ },
732
+ arguments: [{
733
+ type: ramda.includes(ramda.__, [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL])
734
+ }]
735
+ };
736
+ /*
737
+ `${routes.home.projects}/find?id=123`, `home/${routes.projects}/find?id=322`
738
+ `${routes.projects}/{routes.user.show}?name=john&&age=21`
739
+ */
740
+
741
+ const QUERY_PARAMS_PATTERN = {
742
+ type: TYPES.TEMPLATE_LITERAL,
743
+ expressions: ramda.any(patternExistsDeep({
744
+ type: TYPES.MEMBER_EXPRESSION,
745
+ object: {
746
+ type: TYPES.IDENTIFIER,
747
+ name: "routes"
748
+ }
749
+ })),
750
+ quasis: ramda.any(({
751
+ value
752
+ }) => value.cooked.includes("?"))
753
+ };
754
+
755
+ const isRoutesImportPresent = context => context.getAncestors()[0].body.some(matches(ROUTES_IMPORT_PATTERN));
756
+
757
+ var noRoutesDestructureAndReassignment = {
758
+ meta: {
759
+ type: "problem",
760
+ docs: {
761
+ description: "Disallow destructuring and re-assignment of routes"
762
+ }
763
+ },
764
+ create: context => ({
765
+ VariableDeclaration(node) {
766
+ if (matches(DECALARATION_PATTERN, node) && isRoutesImportPresent(context)) {
767
+ context.report(node, ROUTES_HAS_ALREADY_BEEN_DECLARED);
768
+ }
769
+ },
770
+
771
+ VariableDeclarator(node) {
772
+ if (matches(ASSIGNMENT_PATTERN, node) && isRoutesImportPresent(context)) {
773
+ context.report(node, NO_ROUTES_ASSIGNMENT);
774
+ }
775
+ },
776
+
777
+ AssignmentExpression(node) {
778
+ if (matches(REASSIGNMENT_PATTERN, node) && isRoutesImportPresent(context)) {
779
+ context.report(node, NO_ROUTES_REASSIGNMENT);
780
+ }
781
+ }
782
+
783
+ })
784
+ };
785
+
786
+ const isInsideRoutesFile$1 = context => {
787
+ const filename = context.getFilename();
788
+ return filename.endsWith(ROUTES_FILE_PATH);
789
+ };
790
+
791
+ var routesShouldBeDeclaredAndDefaultExported = {
792
+ meta: {
793
+ type: "problem",
794
+ docs: {
795
+ description: "common/routes.js file should declare a constant named routes and should be exported using default export"
796
+ }
797
+ },
798
+ create: context => ({
799
+ Program(node) {
800
+ if (!isInsideRoutesFile$1(context)) return;
801
+ const isDeclarationPresent = node.body.some(matchesAny([OBJECT_DECALARATION_PATTERN, EXPORT_NAMED_DECLARATION_PATTERN]));
802
+
803
+ if (isDeclarationPresent) {
804
+ const isDefaultExportPresent = node.body.some(matches(DEFAULT_EXPORT_PATTERN));
805
+ if (isDefaultExportPresent) return;
806
+ context.report(node, ROUTES_SHOULD_USE_DEFAULT_EXPORT);
807
+ } else {
808
+ context.report(node, ROUTES_CONSTANT_SHOULD_BE_DECLARED);
809
+ }
810
+ }
811
+
812
+ })
813
+ };
814
+
815
+ const camelize = text => {
816
+ text = text.replace(/[-_\s.]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
817
+ return text.substring(0, 1).toLowerCase() + text.substring(1);
818
+ };
819
+
820
+ const isInsideRoutesFile = context => {
821
+ const filename = context.getFilename();
822
+ return filename.endsWith(ROUTES_FILE_PATH);
823
+ };
824
+
825
+ const isParam = e => e === null || e === void 0 ? void 0 : e.startsWith(":");
826
+
827
+ const isNotParam = e => !isParam(e);
828
+
829
+ const checkObjectPath = (context, object, objectPath = []) => {
830
+ if (object.type === TYPES.OBJECT_EXPRESSION) {
831
+ object.properties.forEach(property => checkObjectPath(context, property, objectPath));
832
+ } else if (object.type === TYPES.PROPERTY) {
833
+ if (object.value.type === TYPES.LITERAL) {
834
+ const routeKeys = object.value.value.split("/").filter(isNotEmpty$1);
835
+ const routeNonParams = routeKeys.filter(isNotParam).map(camelize);
836
+ if (isNotEmpty$1(routeKeys) && ramda.isEmpty(routeNonParams)) return;
837
+ let updatedObjectPath = SPECIAL_KEYS.includes(object.key.name) ? objectPath : [...objectPath, object.key.name];
838
+
839
+ if (isParam(routeKeys[0])) {
840
+ updatedObjectPath = ramda.remove(0, 1, updatedObjectPath);
841
+ }
842
+
843
+ const lastNonParamIndex = ramda.findLastIndex(isNotParam, routeKeys);
844
+ const consecutiveParamsCount = routeKeys.length - (lastNonParamIndex + 1);
845
+ const keyDiff = updatedObjectPath.length - routeNonParams.length;
846
+
847
+ if (matches(routeNonParams, updatedObjectPath) && [0, consecutiveParamsCount, consecutiveParamsCount - 1].includes(keyDiff)) {
848
+ return;
849
+ }
850
+
851
+ context.report({
852
+ node: object.value,
853
+ message: ROUTE_SHOULD_MATCH_OBJECT_PATH
854
+ });
855
+ } else if (object.value.type === TYPES.OBJECT_EXPRESSION) {
856
+ const updatedObjectPath = [...objectPath, object.key.name];
857
+ checkObjectPath(context, object.value, updatedObjectPath);
858
+ } else {
859
+ context.report({
860
+ node: object.value,
861
+ message: ROUTE_SHOULD_BE_A_STRING
862
+ });
863
+ }
864
+ }
865
+ };
866
+
867
+ var routesShouldMatchObjectPath = {
868
+ meta: {
869
+ type: "problem",
870
+ docs: {
871
+ description: "Each route string defined in the `routes` object should match with its object path."
872
+ }
873
+ },
874
+ create: context => ({
875
+ VariableDeclaration(node) {
876
+ if (isInsideRoutesFile(context) && matches(DECALARATION_PATTERN, node)) {
877
+ const object = node.declarations[0].init;
878
+ checkObjectPath(context, object);
879
+ }
880
+ }
881
+
882
+ })
883
+ };
884
+
885
+ const getCode = (context, start, length) => context.getSourceCode().text.substr(start, length);
886
+
887
+ const replacer$2 = nodeReplacerWithImports(ramda.assocPath(["source", "value"], "neetocommons/utils", IMPORT_DECLARATION));
888
+ var useCommonRoutes = {
889
+ meta: {
890
+ type: "problem",
891
+ fixable: "code",
892
+ docs: {
893
+ description: "Prevent usage of strings and template literals in Route, Redirect, Link, NavLink, history.push() and history.replace()"
894
+ }
895
+ },
896
+ create: context => ({
897
+ JSXOpeningElement(node) {
898
+ if (!matches(NAVIGATION_COMPONENTS_PATTERN, node)) return;
899
+ const componentName = node.name.name;
900
+ const valueNode = findMatchingNodesDeep(node, PATH_OR_TO_PROP_PATTERN)[0].value;
901
+ if (matches(QUERY_PARAMS_PATTERN, valueNode)) return;
902
+ const message = componentName === "Route" ? canBeReplacedWith("routes.*") : canBeReplacedWith("routes.* or buildUrl(routes.*)");
903
+ context.report(valueNode, message);
904
+ },
905
+
906
+ CallExpression(node) {
907
+ if (!matches(HISTORY_PATTERN, node)) return;
908
+ const argumentNode = node.arguments[0];
909
+ if (matches(QUERY_PARAMS_PATTERN, argumentNode)) return;
910
+ const message = canBeReplacedWith("routes.* or buildUrl(routes.*)");
911
+ context.report(argumentNode, message);
912
+ },
913
+
914
+ TemplateLiteral(node) {
915
+ if (!matches(QUERY_PARAMS_PATTERN, node)) return;
916
+ const quasiWithQuestionMark = node.quasis.find(({
917
+ value
918
+ }) => value.cooked.includes("?"));
919
+ const questionMarkIndex = quasiWithQuestionMark.range[0] + quasiWithQuestionMark.value.cooked.indexOf("?") + 1;
920
+ const textBeforeQuestionMark = getCode(context, node.range[0] + 1, questionMarkIndex - (node.range[0] + 1));
921
+ const textAfterQuestionMark = getCode(context, questionMarkIndex + 1, node.range[1] - (questionMarkIndex + 2));
922
+ if (ramda.isEmpty(textAfterQuestionMark)) return;
923
+
924
+ if (textAfterQuestionMark.indexOf("${") > -1) {
925
+ context.report({
926
+ node,
927
+ message: canBeReplacedWith("buildUrl()")
928
+ });
929
+ } else {
930
+ const queryParams = JSON.stringify(Object.fromEntries(new URLSearchParams(textAfterQuestionMark)));
931
+ const fix = `buildUrl(\`${textBeforeQuestionMark}\`, ${queryParams})`;
932
+ context.report({
933
+ node,
934
+ message: canBeReplacedWith(fix),
935
+ fix: replacer$2.replaceNode({
936
+ context,
937
+ node,
938
+ fix,
939
+ functions: "buildUrl"
940
+ })
941
+ });
942
+ }
943
+ }
944
+
945
+ })
946
+ };
947
+
948
+ // () => { <expression> }
949
+
950
+ const wrappedInBlockPattern = expression => ({
951
+ type: "BlockStatement",
952
+ body: body => body.length === 1 && matches({
953
+ type: "ExpressionStatement",
954
+ expression
955
+ }, body[0])
956
+ }); // everything except this style
957
+ // history.push({ state: something, path: somethingElse })
958
+
959
+
960
+ const HISTORY_PUSH_PATTERN = {
961
+ type: "CallExpression",
962
+ callee: {
963
+ type: "MemberExpression",
964
+ object: {
965
+ type: "Identifier",
966
+ name: "history"
967
+ },
968
+ property: {
969
+ type: "Identifier",
970
+ name: "push"
971
+ }
972
+ },
973
+ arguments: args => args.length === 1 && matches([{
974
+ type: isNot$1("ObjectExpression")
975
+ }], args)
976
+ };
977
+ const WINDOW_LOCATION_PATTERNS = [// window.location.href = "/path"
978
+ {
979
+ type: "AssignmentExpression",
980
+ operator: "=",
981
+ left: {
982
+ type: "MemberExpression",
983
+ object: {
984
+ type: "MemberExpression",
985
+ object: {
986
+ type: "Identifier",
987
+ name: "window"
988
+ },
989
+ property: {
990
+ type: "Identifier",
991
+ name: "location"
992
+ },
993
+ computed: false,
994
+ optional: false
995
+ },
996
+ property: {
997
+ type: "Identifier",
998
+ name: "href"
999
+ },
1000
+ computed: false,
1001
+ optional: false
1002
+ }
1003
+ }, // window.location.assign("/path")
1004
+ {
1005
+ type: "CallExpression",
1006
+ callee: {
1007
+ type: "MemberExpression",
1008
+ object: {
1009
+ type: "MemberExpression",
1010
+ object: {
1011
+ type: "Identifier",
1012
+ name: "window"
1013
+ },
1014
+ property: {
1015
+ type: "Identifier",
1016
+ name: "location"
1017
+ },
1018
+ computed: false,
1019
+ optional: false
1020
+ },
1021
+ property: {
1022
+ type: "Identifier",
1023
+ name: "assign"
1024
+ },
1025
+ computed: false,
1026
+ optional: false
1027
+ },
1028
+ optional: false
1029
+ }]; // onClick={() => <expression>}
1030
+
1031
+ const ONCLICK_ATTRIBUTE_PATTERN = {
1032
+ type: "JSXAttribute",
1033
+ name: {
1034
+ type: "JSXIdentifier",
1035
+ name: "onClick"
1036
+ },
1037
+ value: {
1038
+ type: "JSXExpressionContainer",
1039
+ expression: {
1040
+ type: "ArrowFunctionExpression",
1041
+ params: ramda.isEmpty,
1042
+ generator: false,
1043
+ async: false
1044
+ }
1045
+ }
1046
+ }; // <div onClick={() => history.push("/path")} />
1047
+
1048
+ const LINK_REPLACEABLE_PATTERN = {
1049
+ name: {
1050
+ type: "JSXIdentifier",
1051
+ name: ramda.includes(ramda.__, ["Button", "button", "span", "div", "a"])
1052
+ },
1053
+ attributes: ramda.any(matches(ramda.assocPath(["value", "expression", "body"], matchesAny([HISTORY_PUSH_PATTERN, wrappedInBlockPattern(HISTORY_PUSH_PATTERN)]), ONCLICK_ATTRIBUTE_PATTERN)))
1054
+ }; // <div onClick={() => window.location.href = "/path"} />
1055
+
1056
+ const ANCHOR_REPLACEABLE_PATTERN = {
1057
+ name: {
1058
+ type: "JSXIdentifier",
1059
+ name: ramda.includes(ramda.__, ["Button", "button", "span", "div"])
1060
+ },
1061
+ attributes: ramda.any(matches(ramda.assocPath(["value", "expression", "body"], matchesAny([WINDOW_LOCATION_PATTERNS, WINDOW_LOCATION_PATTERNS.map(wrappedInBlockPattern)].flat()), ONCLICK_ATTRIBUTE_PATTERN)))
1062
+ };
1063
+
1064
+ const getFixer = ({
1065
+ context,
1066
+ node,
1067
+ attribute,
1068
+ findPathNode
1069
+ }) => fixer => {
1070
+ const onClickAttributeNode = node.attributes.find(matches(ONCLICK_ATTRIBUTE_PATTERN));
1071
+ const pathNode = findPathNode(onClickAttributeNode);
1072
+ const navigateAttr = pathNode.type === "Literal" ? `${attribute}="${pathNode.value}"` : `${attribute}={${getCode$1(context, pathNode)}}`;
1073
+ return fixer.replaceText(onClickAttributeNode, navigateAttr);
1074
+ };
1075
+
1076
+ const findLinkPathNode = node => findMatchingNodesDeep(node, HISTORY_PUSH_PATTERN)[0].arguments[0];
1077
+
1078
+ const findAnchorPathNode = node => {
1079
+ let expressionNode = findMatchingNodesDeep(node, WINDOW_LOCATION_PATTERNS[0]);
1080
+ if (!ramda.isEmpty(expressionNode)) return expressionNode[0].right;
1081
+ expressionNode = findMatchingNodesDeep(node, WINDOW_LOCATION_PATTERNS[1]);
1082
+ return expressionNode[0].arguments[0];
1083
+ };
1084
+
1085
+ var consistentButtonLinkAnchor = {
1086
+ meta: {
1087
+ type: "suggestion",
1088
+ docs: {
1089
+ description: "Warns when button, div, span etc. are used with an onClick handler " + "instead of link or anchor tag to navigate to other pages."
1090
+ },
1091
+ fixable: "code"
1092
+ },
1093
+ create: context => ({
1094
+ JSXOpeningElement(node) {
1095
+ let message, fix;
1096
+
1097
+ if (matches(LINK_REPLACEABLE_PATTERN, node)) {
1098
+ if (node.name.name === "Button") {
1099
+ message = USE_BUTTON_TO_FOR_LINK_NAVIGATION;
1100
+ const findPathNode = findLinkPathNode;
1101
+ fix = getFixer({
1102
+ context,
1103
+ node,
1104
+ attribute: "to",
1105
+ findPathNode
1106
+ });
1107
+ } else message = USE_LINK_FOR_NAVIGATION;
1108
+ } else if (matches(ANCHOR_REPLACEABLE_PATTERN, node)) {
1109
+ if (node.name.name === "Button") {
1110
+ message = USE_BUTTON_TO_FOR_ANCHOR_NAVIGATION;
1111
+ const findPathNode = findAnchorPathNode;
1112
+ fix = getFixer({
1113
+ context,
1114
+ node,
1115
+ attribute: "href",
1116
+ findPathNode
1117
+ });
1118
+ } else message = USE_ANCHOR_FOR_NAVIGATION;
1119
+ } else return;
1120
+
1121
+ context.report({
1122
+ node,
1123
+ message,
1124
+ fix
1125
+ });
1126
+ }
1127
+
1128
+ })
1129
+ };
1130
+
599
1131
  const CONSTANT_CASE_PATTERN = /^[A-Z0-9_]*$/;
600
1132
  const CONSTANTS_FILES = [/.*constants.js$/i, /app\/javascript\/src\/common\/urls.js$/];
601
1133
 
@@ -676,7 +1208,7 @@
676
1208
  node,
677
1209
  message: useConstantCaseFor(name),
678
1210
  suggest: [{
679
- desc: `Replace ${getCode(context, node)} with ${toConstantCase(name)}`,
1211
+ desc: `Replace ${getCode$1(context, node)} with ${toConstantCase(name)}`,
680
1212
  fix: fixer => fixer.replaceText(node, toConstantCase(name))
681
1213
  }]
682
1214
  });
@@ -694,7 +1226,7 @@
694
1226
  node,
695
1227
  message: useConstantCaseFor(exported.name),
696
1228
  suggest: [{
697
- desc: `Replace ${getCode(context, node)} with ${toConstantCase(exported.name)}`,
1229
+ desc: `Replace ${getCode$1(context, node)} with ${toConstantCase(exported.name)}`,
698
1230
  fix: fixer => {
699
1231
  const newName = toConstantCase(exported.name);
700
1232
 
@@ -830,7 +1362,7 @@
830
1362
  },
831
1363
  create: context => ({
832
1364
  AssignmentExpression(node) {
833
- if (patternExistsDeep(node.left, GLOBALPROPS_REASSIGNMENT_PATTERN)) {
1365
+ if (patternExistsDeep(GLOBALPROPS_REASSIGNMENT_PATTERN, node.left)) {
834
1366
  context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
835
1367
  }
836
1368
  }
@@ -928,6 +1460,13 @@
928
1460
  }
929
1461
  }
930
1462
  };
1463
+ const ARRAY_LENGTH_PATTERN$1 = {
1464
+ type: TYPES.MEMBER_EXPRESSION,
1465
+ property: {
1466
+ type: TYPES.IDENTIFIER,
1467
+ name: "length"
1468
+ }
1469
+ };
931
1470
  const OBJ_KEY_LENGTH_PATTERN$1 = {
932
1471
  type: TYPES.MEMBER_EXPRESSION,
933
1472
  object: {
@@ -937,11 +1476,11 @@
937
1476
  object: {
938
1477
  type: TYPES.IDENTIFIER,
939
1478
  name: "Object"
1479
+ },
1480
+ property: {
1481
+ type: TYPES.IDENTIFIER,
1482
+ name: "keys"
940
1483
  }
941
- },
942
- property: {
943
- type: TYPES.IDENTIFIER,
944
- name: "keys"
945
1484
  }
946
1485
  },
947
1486
  property: {
@@ -949,13 +1488,6 @@
949
1488
  name: "length"
950
1489
  }
951
1490
  };
952
- const ARRAY_LENGTH_PATTERN$1 = {
953
- type: TYPES.MEMBER_EXPRESSION,
954
- property: {
955
- type: TYPES.IDENTIFIER,
956
- name: "length"
957
- }
958
- };
959
1491
  const NOOP_PATTERN = {
960
1492
  generator: false,
961
1493
  async: false,
@@ -1197,7 +1729,11 @@
1197
1729
  type: TYPES.MEMBER_EXPRESSION,
1198
1730
  object: {
1199
1731
  type: TYPES.IDENTIFIER,
1200
- name: (name, root) => name === root.right.callee.object.name
1732
+ name: (name, root) => {
1733
+ var _root$right$callee, _root$right$callee$ob;
1734
+
1735
+ return name === ((_root$right$callee = root.right.callee) === null || _root$right$callee === void 0 ? void 0 : (_root$right$callee$ob = _root$right$callee.object) === null || _root$right$callee$ob === void 0 ? void 0 : _root$right$callee$ob.name);
1736
+ }
1201
1737
  },
1202
1738
  property: {
1203
1739
  type: TYPES.IDENTIFIER,
@@ -1276,9 +1812,9 @@
1276
1812
  let array = null;
1277
1813
 
1278
1814
  if (matches(genericPatterns.VANILLA, node)) {
1279
- array = getCode(context, node.callee.object);
1815
+ array = getCode$1(context, node.callee.object);
1280
1816
  } else if (matches(genericPatterns.RAMDA, node)) {
1281
- array = getCode(context, node.arguments[1]);
1817
+ array = getCode$1(context, node.arguments[1]);
1282
1818
  } else return; // arr.filter(x => x.prop === something).length
1283
1819
 
1284
1820
 
@@ -1302,7 +1838,7 @@
1302
1838
  }
1303
1839
 
1304
1840
  if (idUsagePattern) {
1305
- const id = matches(idUsagePattern, predicate.body.left) ? getCode(context, predicate.body.right) : getCode(context, predicate.body.left);
1841
+ const id = matches(idUsagePattern, predicate.body.left) ? getCode$1(context, predicate.body.right) : getCode$1(context, predicate.body.left);
1306
1842
  const fix = `${functions.byId}(${id}, ${array})`;
1307
1843
  reportSuggestion({
1308
1844
  context,
@@ -1454,7 +1990,7 @@
1454
1990
  operateOn: TYPES.BINARY_EXPRESSION,
1455
1991
  check: (context, node) => {
1456
1992
  if (!matches(CAPITALIZE_PATTERN, node)) return;
1457
- const fix = `capitalize(${getCode(context, node.right.callee.object)})`;
1993
+ const fix = `capitalize(${getCode$1(context, node.right.callee.object)})`;
1458
1994
  reportSuggestion({
1459
1995
  context,
1460
1996
  node,
@@ -1470,7 +2006,7 @@
1470
2006
  if (!matches(COPY_KEYS_PATTERN, node)) return;
1471
2007
  const keyValuePairs = node.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
1472
2008
  const keyMap = JSON.stringify(ramda.fromPairs(keyValuePairs));
1473
- const sourceObject = getCode(context, node.properties[0].argument);
2009
+ const sourceObject = getCode$1(context, node.properties[0].argument);
1474
2010
  const fix = `copyKeys(${keyMap}, ${sourceObject})`;
1475
2011
  reportSuggestion({
1476
2012
  context,
@@ -1487,9 +2023,9 @@
1487
2023
  var _node$arguments$1$par;
1488
2024
 
1489
2025
  if (!matches(DYNAMIC_ARRAY_PATTERN, node)) return;
1490
- const length = getCode(context, node.arguments[0].properties[0].value);
2026
+ const length = getCode$1(context, node.arguments[0].properties[0].value);
1491
2027
  const elementGenIndexParam = (_node$arguments$1$par = node.arguments[1].params[1]) === null || _node$arguments$1$par === void 0 ? void 0 : _node$arguments$1$par.name;
1492
- const elementGenBody = getCode(context, node.arguments[1].body);
2028
+ const elementGenBody = getCode$1(context, node.arguments[1].body);
1493
2029
  const fix = `dynamicArray(${length}, ${elementGenIndexParam || "()"} => ${elementGenBody})`;
1494
2030
  reportSuggestion({
1495
2031
  context,
@@ -1507,8 +2043,8 @@
1507
2043
 
1508
2044
  if (node.type === TYPES.UNARY_EXPRESSION) {
1509
2045
  if (!matches(NOT_EQUALS_PATTERNS.UNARY_EXP, node)) return;
1510
- const first = getCode(context, node.argument.arguments[0]);
1511
- const second = getCode(context, node.argument.arguments[1]);
2046
+ const first = getCode$1(context, node.argument.arguments[0]);
2047
+ const second = getCode$1(context, node.argument.arguments[1]);
1512
2048
  fix = `isNot(${first}, ${second})`;
1513
2049
  } else {
1514
2050
  if (!matches(NOT_EQUALS_PATTERNS.ARROW_FUNC, node)) return;
@@ -1521,7 +2057,7 @@
1521
2057
  externalValueNode = node.body.left;
1522
2058
  } else return;
1523
2059
 
1524
- const externalValue = getCode(context, externalValueNode);
2060
+ const externalValue = getCode$1(context, externalValueNode);
1525
2061
  fix = `isNot(${externalValue})`;
1526
2062
  }
1527
2063
 
@@ -1550,15 +2086,15 @@
1550
2086
  if (isArrowFunc) {
1551
2087
  fix = "isNotEmpty";
1552
2088
  } else {
1553
- const object = isBinaryExp ? node.left.object : node.test.object;
1554
- const isObjLenCheck = object.type === TYPES.CALL_EXPRESSION;
2089
+ const expNode = isBinaryExp ? node.left : node.test;
2090
+ const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN$1, expNode);
1555
2091
  nodeToBeReplaced = isBinaryExp ? node : node.test;
1556
2092
 
1557
2093
  if (isObjLenCheck) {
1558
- const objName = getCode(context, object.arguments[0]);
2094
+ const objName = getCode$1(context, expNode.object.arguments[0]);
1559
2095
  fix = `isNotEmpty(${objName})`;
1560
2096
  } else {
1561
- const arrName = getCode(context, object);
2097
+ const arrName = getCode$1(context, expNode.object);
1562
2098
  fix = `isNotEmpty(${arrName})`;
1563
2099
  message = `Can be replaced with: ${fix}, if '${arrName}' is an array or string.`;
1564
2100
  }
@@ -1581,8 +2117,8 @@
1581
2117
 
1582
2118
  if (node.type === TYPES.BINARY_EXPRESSION) {
1583
2119
  if (!matches(NOT_EQUALS_DEEP_PATTERNS.BINARY_EXP, node)) return;
1584
- const first = getCode(context, node.left.arguments[0]);
1585
- const second = getCode(context, node.right.arguments[0]);
2120
+ const first = getCode$1(context, node.left.arguments[0]);
2121
+ const second = getCode$1(context, node.right.arguments[0]);
1586
2122
  fix = `isNotEqualDeep(${first}, ${second})`;
1587
2123
  } else {
1588
2124
  if (!matches(NOT_EQUALS_DEEP_PATTERNS.ARROW_FUNC, node)) return;
@@ -1595,7 +2131,7 @@
1595
2131
  externalValueNode = node.body.left.arguments[0];
1596
2132
  } else return;
1597
2133
 
1598
- const externalValue = getCode(context, externalValueNode);
2134
+ const externalValue = getCode$1(context, externalValueNode);
1599
2135
  fix = `isNotEqualDeep(${externalValue})`;
1600
2136
  }
1601
2137
 
@@ -1705,9 +2241,9 @@
1705
2241
  externalId = comparison.left;
1706
2242
  } else return;
1707
2243
 
1708
- const id = getCode(context, externalId);
1709
- const replacement = getCode(context, replaceNode);
1710
- const array = getCode(context, node.callee.object);
2244
+ const id = getCode$1(context, externalId);
2245
+ const replacement = getCode$1(context, replaceNode);
2246
+ const array = getCode$1(context, node.callee.object);
1711
2247
  const fix = `replaceById(${id}, ${replacement}, ${array})`;
1712
2248
  reportSuggestion({
1713
2249
  context,
@@ -1722,7 +2258,7 @@
1722
2258
  operateOn: "ObjectExpression",
1723
2259
  check: (context, node) => {
1724
2260
  if (!matches(LABEL_AND_VALUE_PATTERN, node)) return;
1725
- const [label, value] = ramda.pluck("value", node.properties).map(node => getCode(context, node)); // order doesn't matter here
2261
+ const [label, value] = ramda.pluck("value", node.properties).map(node => getCode$1(context, node)); // order doesn't matter here
1726
2262
 
1727
2263
  if (label !== value) return;
1728
2264
  const fix = `toLabelAndValue(${label})`;
@@ -1805,7 +2341,7 @@
1805
2341
  return isApiAction ? noOfParams > API_ACTIONS_ARGUMENT_LIMIT : noOfParams > ARGUMENT_LIMIT;
1806
2342
  };
1807
2343
 
1808
- const getParamList = (context, params) => params.map(param => getCode(context, param)).join(", ");
2344
+ const getParamList = (context, params) => params.map(param => getCode$1(context, param)).join(", ");
1809
2345
 
1810
2346
  const checkAndReport$2 = (context, params) => {
1811
2347
  const isApiAction = isInsideApisDirectory(context);
@@ -2112,7 +2648,7 @@
2112
2648
  expressions,
2113
2649
  quasis
2114
2650
  }) => expressions.reduce((acc, expression, index) => {
2115
- const expressionCode = getCode(context, expression);
2651
+ const expressionCode = getCode$1(context, expression);
2116
2652
  const quasi = quasis[index + 1].value.cooked;
2117
2653
  return `${acc}{${expressionCode}}${quasi}`;
2118
2654
  }, `${quasis[0].value.cooked}`);
@@ -2136,7 +2672,7 @@
2136
2672
  if (doQusisHaveSpecialCharacters(node)) return;
2137
2673
 
2138
2674
  if (isExpressionOnly(node)) {
2139
- const fix = getCode(context, node.expressions[0]);
2675
+ const fix = getCode$1(context, node.expressions[0]);
2140
2676
  context.report({
2141
2677
  node,
2142
2678
  message: canBeReplacedWith(fix),
@@ -2207,6 +2743,13 @@
2207
2743
  name: "undefined"
2208
2744
  }])
2209
2745
  };
2746
+ const ARRAY_LENGTH_PATTERN = {
2747
+ type: TYPES.MEMBER_EXPRESSION,
2748
+ property: {
2749
+ type: TYPES.IDENTIFIER,
2750
+ name: "length"
2751
+ }
2752
+ };
2210
2753
  const OBJ_KEY_LENGTH_PATTERN = {
2211
2754
  type: TYPES.MEMBER_EXPRESSION,
2212
2755
  object: {
@@ -2216,11 +2759,11 @@
2216
2759
  object: {
2217
2760
  type: TYPES.IDENTIFIER,
2218
2761
  name: "Object"
2762
+ },
2763
+ property: {
2764
+ type: TYPES.IDENTIFIER,
2765
+ name: "keys"
2219
2766
  }
2220
- },
2221
- property: {
2222
- type: TYPES.IDENTIFIER,
2223
- name: "keys"
2224
2767
  }
2225
2768
  },
2226
2769
  property: {
@@ -2228,13 +2771,6 @@
2228
2771
  name: "length"
2229
2772
  }
2230
2773
  };
2231
- const ARRAY_LENGTH_PATTERN = {
2232
- type: TYPES.MEMBER_EXPRESSION,
2233
- property: {
2234
- type: TYPES.IDENTIFIER,
2235
- name: "length"
2236
- }
2237
- };
2238
2774
  const ARRAY_INSERTS_PATTERN = {
2239
2775
  APPEND: {
2240
2776
  // x => [...x, y]
@@ -2573,11 +3109,11 @@
2573
3109
  let fix = null;
2574
3110
 
2575
3111
  if (matches(ARRAY_INSERTS_PATTERN.APPEND, node) && elements[1].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[0].argument.name) {
2576
- fix = `append(${getCode(context, elements[1])})`;
3112
+ fix = `append(${getCode$1(context, elements[1])})`;
2577
3113
  } else if (matches(ARRAY_INSERTS_PATTERN.PREPEND, node) && elements[0].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[1].argument.name) {
2578
- fix = `prepend(${getCode(context, elements[0])})`;
3114
+ fix = `prepend(${getCode$1(context, elements[0])})`;
2579
3115
  } else if (matches(ARRAY_INSERTS_PATTERN.CONCAT, node) && params[0].name === elements[0].argument.name) {
2580
- fix = `concat(${getCode(context, elements[1].argument)})`;
3116
+ fix = `concat(${getCode$1(context, elements[1].argument)})`;
2581
3117
  }
2582
3118
 
2583
3119
  if (!fix) return;
@@ -2600,8 +3136,8 @@
2600
3136
 
2601
3137
  const convertToAssoc = (context, node) => {
2602
3138
  const property = node.body.properties[1];
2603
- const key = property.computed ? getCode(context, property.key) : `"${property.key.name}"`;
2604
- return `assoc(${key}, ${getCode(context, property.value)})`;
3139
+ const key = property.computed ? getCode$1(context, property.key) : `"${property.key.name}"`;
3140
+ return `assoc(${key}, ${getCode$1(context, property.value)})`;
2605
3141
  };
2606
3142
 
2607
3143
  var assocLintCheck = {
@@ -2616,7 +3152,7 @@
2616
3152
  type: "Identifier",
2617
3153
  name: node.params[0].name
2618
3154
  };
2619
- if (patternExistsDeep(property.value, selfReferencingPattern)) return;
3155
+ if (patternExistsDeep(selfReferencingPattern, property.value)) return;
2620
3156
  const fix = convertToAssoc(context, node);
2621
3157
  context.report({
2622
3158
  node,
@@ -2638,7 +3174,7 @@
2638
3174
  operateOn: "BinaryExpression",
2639
3175
  check: (context, node) => {
2640
3176
  if (matches(JSON_EQUALS_PATTERN, node)) {
2641
- const fix = `equals(${getCode(context, node.left.arguments[0])}, ${getCode(context, node.right.arguments[0])})`;
3177
+ const fix = `equals(${getCode$1(context, node.left.arguments[0])}, ${getCode$1(context, node.right.arguments[0])})`;
2642
3178
  context.report({
2643
3179
  node,
2644
3180
  message: canBeReplacedWith(fix),
@@ -2684,14 +3220,14 @@
2684
3220
  let fix = null;
2685
3221
  let message = "";
2686
3222
  const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
2687
- const object = isBinaryExp ? node.left.object : node.argument.object;
2688
- const isObjLenCheck = object.type === TYPES.CALL_EXPRESSION;
3223
+ const expNode = isBinaryExp ? node.left : node.argument;
3224
+ const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN, expNode);
2689
3225
 
2690
3226
  if (isObjLenCheck) {
2691
- const objName = getCode(context, object.arguments[0]);
3227
+ const objName = getCode$1(context, expNode.object.arguments[0]);
2692
3228
  fix = `isEmpty(${objName})`;
2693
3229
  } else {
2694
- const arrName = getCode(context, object);
3230
+ const arrName = getCode$1(context, expNode.object);
2695
3231
  fix = `isEmpty(${arrName})`;
2696
3232
  message = `Can be replaced with: ${fix}, if '${arrName}' is an array or string.`;
2697
3233
  }
@@ -2726,7 +3262,7 @@
2726
3262
  const convertToMergeLeft = (context, node) => {
2727
3263
  const properties = node.body.properties.slice(1);
2728
3264
  const matchIndex = findPatternIndex(node);
2729
- return matchIndex === 2 && properties.length === 1 ? `mergeLeft(${getCode(context, properties[0].argument)})` : `mergeLeft({ ${getCode(context, {
3265
+ return matchIndex === 2 && properties.length === 1 ? `mergeLeft(${getCode$1(context, properties[0].argument)})` : `mergeLeft({ ${getCode$1(context, {
2730
3266
  range: [properties[0].range[0], ramda.last(properties).range[1]]
2731
3267
  })} })`;
2732
3268
  };
@@ -2743,7 +3279,7 @@
2743
3279
  name: node.params[0].name
2744
3280
  };
2745
3281
  const properties = node.body.properties.slice(1);
2746
- if (patternExistsDeep(properties, selfReferencingPattern)) return;
3282
+ if (patternExistsDeep(selfReferencingPattern, properties)) return;
2747
3283
  const fix = convertToMergeLeft(context, node);
2748
3284
  context.report({
2749
3285
  node,
@@ -2779,7 +3315,7 @@
2779
3315
  operateOn: "CallExpression",
2780
3316
  check: (context, node) => {
2781
3317
  if (matches(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
2782
- const code = getCode(context, node.callee.object);
3318
+ const code = getCode$1(context, node.callee.object);
2783
3319
  const func = node.arguments[0];
2784
3320
 
2785
3321
  if (matches(PLUCK_PATTERNS.IDENTIFIER, func)) {
@@ -2860,12 +3396,12 @@
2860
3396
  let functions = ["sum"];
2861
3397
 
2862
3398
  if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].name) {
2863
- fix = `sum(${getCode(context, node.callee.object)})`;
3399
+ fix = `sum(${getCode$1(context, node.callee.object)})`;
2864
3400
  } else if (reduceFunc.params[1].type === TYPES.OBJECT_PATTERN && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].properties[0].value.name) {
2865
- fix = `sum(pluck("${delta.name}", ${getCode(context, node.callee.object)}))`;
3401
+ fix = `sum(pluck("${delta.name}", ${getCode$1(context, node.callee.object)}))`;
2866
3402
  functions = ["sum", "pluck"];
2867
3403
  } else if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.MEMBER_EXPRESSION && delta.property.type === TYPES.IDENTIFIER && delta.object.name === reduceFunc.params[1].name) {
2868
- fix = `sum(pluck("${delta.property.name}", ${getCode(context, node.callee.object)}))`;
3404
+ fix = `sum(pluck("${delta.property.name}", ${getCode$1(context, node.callee.object)}))`;
2869
3405
  functions = ["sum", "pluck"];
2870
3406
  } else {
2871
3407
  return;
@@ -2896,7 +3432,14 @@
2896
3432
  }
2897
3433
  },
2898
3434
  create: context => {
2899
- const operations = ramda.groupBy(ramda.prop("operateOn"), [arrayInsertsLintCheck, assocLintCheck, equalsLintCheck, identityLintCheck, mergeLintCheck, pluckLintCheck, propLintCheck, sumLintCheck, isNilCheck, isEmptyCheck]);
3435
+ const operationsArr = [arrayInsertsLintCheck, assocLintCheck, equalsLintCheck, identityLintCheck, mergeLintCheck, pluckLintCheck, propLintCheck, sumLintCheck, isNilCheck, isEmptyCheck].map(op => {
3436
+ if (!Array.isArray(op.operateOn)) return op;
3437
+ return op.operateOn.map(operateOn => ({
3438
+ operateOn,
3439
+ check: op.check
3440
+ }));
3441
+ }).flat();
3442
+ const operations = ramda.groupBy(ramda.prop("operateOn"), operationsArr);
2900
3443
  return ramda.fromPairs(ramda.toPairs(operations).map(([operateOn, operations]) => [operateOn, node => operations.forEach(op => op.check(context, node))]));
2901
3444
  }
2902
3445
  };
@@ -3071,10 +3614,11 @@
3071
3614
 
3072
3615
  var index = {
3073
3616
  rules: {
3074
- "neetocommons-tips": neetocommonsTips,
3075
3617
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
3076
3618
  "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
3077
3619
  "combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
3620
+ "consistent-button-link-anchor": consistentButtonLinkAnchor,
3621
+ "neetocommons-tips": neetocommonsTips,
3078
3622
  "no-blacklisted-imports": noBlacklistedImports,
3079
3623
  "no-axios-import-outside-apis": noAxiosImportOutsideApis,
3080
3624
  "no-excess-function-arguments": noExcessFunctionArguments,
@@ -3086,10 +3630,14 @@
3086
3630
  "no-namespace-specifier-import-for-ramda": noNamespaceSpecifierImportForRamda,
3087
3631
  "no-redundant-jsx-expression": noRedundantJsxExpression,
3088
3632
  "no-redundant-string-templates": noRedundantStringTemplates,
3633
+ "no-routes-destructure-and-reassignment": noRoutesDestructureAndReassignment,
3089
3634
  "prefix-neeto-ui-import-alias": prefixNeetoUIImportAlias,
3090
3635
  "ramda-tips": ramdaTips,
3636
+ "routes-should-be-declared-and-default-exported": routesShouldBeDeclaredAndDefaultExported,
3637
+ "routes-should-match-object-path": routesShouldMatchObjectPath,
3091
3638
  "use-axios-config-for-passing-query-parameters": useAxiosConfigForPassingQueryParameters,
3092
3639
  "use-constant-case": useConstantCase,
3640
+ "use-common-routes": useCommonRoutes,
3093
3641
  "use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
3094
3642
  "use-webpack-alias": useWebpackAlias
3095
3643
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {