@bigbinary/eslint-plugin-neeto 1.7.2 → 1.7.3

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/README.md CHANGED
@@ -51,6 +51,7 @@ of the issues identified in JavaScript code.
51
51
 
52
52
  ### Errors
53
53
 
54
+ - [switch-children-must-be-route-or-redirect](./docs/src/rules/switch-children-must-be-route-or-redirect.md)
54
55
  - [no-unnecessary-classnames](./docs/src/rules/no-unnecessary-classnames.md)
55
56
  - [no-local-storage](./docs/src/rules/no-local-storage.md)
56
57
  - [no-lowercase-on-translation](./docs/src/rules/no-lowercase-on-translation.md)
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@
23
23
 
24
24
  var neetoCommonsConstants__namespace = /*#__PURE__*/_interopNamespaceDefault(neetoCommonsConstants);
25
25
 
26
+ /* eslint-disable @bigbinary/neeto/use-title-case-neeto-in-strings */
26
27
  var absolutePath$1 = function absolutePath(jsPath) {
27
28
  return path$2.resolve(__dirname, "../../../..", jsPath);
28
29
  };
@@ -37,6 +38,7 @@
37
38
  var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
38
39
  var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
39
40
  var rules = {
41
+ "@bigbinary/neeto/switch-children-must-be-route-or-redirect": "error",
40
42
  "@bigbinary/neeto/use-dayjs-from-neeto-commons-fronted": "error",
41
43
  "@bigbinary/neeto/use-neetoui-action-block-in-formik-forms": "warn",
42
44
  "@bigbinary/neeto/no-unnecessary-classnames": "error",
@@ -322,7 +324,7 @@
322
324
  }
323
325
 
324
326
  var name = "@bigbinary/eslint-plugin-neeto";
325
- var version = "1.7.1";
327
+ var version = "1.7.2";
326
328
  var main = "dist/index.js";
327
329
  var license = "UNLICENSED";
328
330
  var scripts = {
@@ -351,7 +353,7 @@
351
353
  "@babel/preset-typescript": "^7.18.6",
352
354
  "@babel/runtime": "^7.19.0",
353
355
  "@bigbinary/babel-preset-neeto": "^1.0.3",
354
- "@bigbinary/eslint-plugin-neeto": "^1.6.2",
356
+ "@bigbinary/eslint-plugin-neeto": "^1.7.2",
355
357
  "@bigbinary/neeto-cist": "^1.0.3",
356
358
  "@bigbinary/neeto-commons-frontend": "^4.13.42",
357
359
  "@rollup/plugin-alias": "^3.1.9",
@@ -729,6 +731,7 @@
729
731
  };
730
732
  var HELP_URL_SHOULD_USE_PERMALINK = "Help URL must use a permalink (/p/...) instead of an article link (/articles/...).";
731
733
  var HELP_URL_INCORRECT_FORMAT = "Incorrect help URL format. Please use the 'help.neeto<product>.com' format instead of 'neeto<product>help.neetokb.com'.";
734
+ var INVALID_SWITCH_CHILD_MESSAGE = "Switch component can only contain Route, Redirect, or PrivateRoute as direct children";
732
735
 
733
736
  var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
734
737
 
@@ -10822,6 +10825,55 @@
10822
10825
  }
10823
10826
  };
10824
10827
 
10828
+ var SWITCH_PATTERN = {
10829
+ type: TYPES.JSX_ELEMENT,
10830
+ openingElement: {
10831
+ type: TYPES.JSX_OPENING_ELEMENT,
10832
+ name: {
10833
+ type: TYPES.JSX_IDENTIFIER,
10834
+ name: "Switch"
10835
+ }
10836
+ }
10837
+ };
10838
+ var VALID_SWITCH_CHILDREN = ["Route", "Redirect", "PrivateRoute"];
10839
+
10840
+ var isValidSwitchChild = function isValidSwitchChild(child) {
10841
+ if (child.type === TYPES.JSX_EXPRESSION_CONTAINER) return true;
10842
+ if (child.type === TYPES.JSX_TEXT) {
10843
+ var trimmedValue = child.value.trim();
10844
+ return trimmedValue === "";
10845
+ }
10846
+ if (child.type === TYPES.JSX_ELEMENT) {
10847
+ var _child$openingElement, _child$openingElement2;
10848
+ var elementName = (_child$openingElement = child.openingElement) === null || _child$openingElement === void 0 ? void 0 : (_child$openingElement2 = _child$openingElement.name) === null || _child$openingElement2 === void 0 ? void 0 : _child$openingElement2.name;
10849
+ return VALID_SWITCH_CHILDREN.includes(elementName);
10850
+ }
10851
+ return false;
10852
+ };
10853
+ var switchChildrenMustBeRouteOrRedirect = {
10854
+ meta: {
10855
+ type: "problem",
10856
+ docs: {
10857
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/switch-children-must-be-route-or-redirect.md",
10858
+ description: "Enforces that Switch components can only contain Route or Redirect as direct children"
10859
+ }
10860
+ },
10861
+ create: function create(context) {
10862
+ return {
10863
+ JSXElement: function JSXElement(node) {
10864
+ if (!neetoCist.matches(SWITCH_PATTERN, node)) return;
10865
+ node.children.forEach(function (child) {
10866
+ if (isValidSwitchChild(child)) return;
10867
+ context.report({
10868
+ node: child,
10869
+ message: INVALID_SWITCH_CHILD_MESSAGE
10870
+ });
10871
+ });
10872
+ }
10873
+ };
10874
+ }
10875
+ };
10876
+
10825
10877
  var isForLoopReplacable = function isForLoopReplacable(node) {
10826
10878
  return ramda.not(patternExistsDeep(BREAK_STATEMENT_PATTERN, node.body) || patternExistsDeep(RETURN_STATEMENT_PATTERN$1, node.body) || patternExistsDeep(CHAR_AT_PATTERN, node.body));
10827
10879
  };
@@ -13121,6 +13173,7 @@
13121
13173
 
13122
13174
  var index = {
13123
13175
  rules: {
13176
+ "switch-children-must-be-route-or-redirect": switchChildrenMustBeRouteOrRedirect,
13124
13177
  "use-dayjs-from-neeto-commons-fronted": useDayjsFromNeetoCommonsFronted,
13125
13178
  "use-neetoui-action-block-in-formik-forms": useNeetouiActionBlockInFormikForms,
13126
13179
  "no-unnecessary-classnames": noUnnecessaryClassnames,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {
@@ -38,7 +38,7 @@
38
38
  "@babel/preset-typescript": "^7.18.6",
39
39
  "@babel/runtime": "^7.19.0",
40
40
  "@bigbinary/babel-preset-neeto": "^1.0.3",
41
- "@bigbinary/eslint-plugin-neeto": "^1.6.2",
41
+ "@bigbinary/eslint-plugin-neeto": "^1.7.2",
42
42
  "@bigbinary/neeto-cist": "^1.0.3",
43
43
  "@bigbinary/neeto-commons-frontend": "^4.13.42",
44
44
  "@rollup/plugin-alias": "^3.1.9",