@bigbinary/eslint-plugin-neeto 1.7.2 → 1.7.4
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 +1 -0
- package/dist/index.js +79 -3
- package/package.json +2 -2
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.
|
|
327
|
+
var version = "1.7.3";
|
|
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.
|
|
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
|
};
|
|
@@ -11701,6 +11753,16 @@
|
|
|
11701
11753
|
};
|
|
11702
11754
|
var CONDITIONAL_NODE_TYPES = [TYPES.LOGICAL_EXPRESSION, TYPES.CONDITIONAL_EXPRESSION];
|
|
11703
11755
|
var NODE_TYPES = [TYPES.JSX_ELEMENT, TYPES.JSX_EXPRESSION_CONTAINER];
|
|
11756
|
+
var HTML_FORM_ELEMENT_PATTERN = {
|
|
11757
|
+
type: TYPES.JSX_ELEMENT,
|
|
11758
|
+
openingElement: {
|
|
11759
|
+
name: {
|
|
11760
|
+
name: function name(_name3) {
|
|
11761
|
+
return _name3 === null || _name3 === void 0 ? void 0 : _name3.includes("form");
|
|
11762
|
+
}
|
|
11763
|
+
}
|
|
11764
|
+
}
|
|
11765
|
+
};
|
|
11704
11766
|
|
|
11705
11767
|
var isFormActionButton = function isFormActionButton(node) {
|
|
11706
11768
|
return matchesAny([BUTTON_NODE_PATTERN, SUBMIT_BUTTON_PATTERN, CANCEL_BUTTON_PATTERN], node);
|
|
@@ -11719,6 +11781,17 @@
|
|
|
11719
11781
|
}
|
|
11720
11782
|
}, node.parent);
|
|
11721
11783
|
};
|
|
11784
|
+
var traverseParentsAndCheckFormType = function traverseParentsAndCheckFormType(node) {
|
|
11785
|
+
var current = node.parent;
|
|
11786
|
+
while (current) {
|
|
11787
|
+
if (neetoCist.matches(HTML_FORM_ELEMENT_PATTERN, current)) return true;
|
|
11788
|
+
current = current.parent;
|
|
11789
|
+
}
|
|
11790
|
+
return false;
|
|
11791
|
+
};
|
|
11792
|
+
var isInsideHtmlForm = function isInsideHtmlForm(node) {
|
|
11793
|
+
return traverseParentsAndCheckFormType(node);
|
|
11794
|
+
};
|
|
11722
11795
|
var getAdjacentActionNode = function getAdjacentActionNode(node) {
|
|
11723
11796
|
var _node$parent, _node$parent$parent, _filterBy2, _findIndexBy2;
|
|
11724
11797
|
var isSucceedingNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -11753,7 +11826,9 @@
|
|
|
11753
11826
|
create: function create(context) {
|
|
11754
11827
|
return {
|
|
11755
11828
|
JSXElement: function JSXElement(node) {
|
|
11756
|
-
if (!isFormSubmitButton(node) || isAlternateNode(node))
|
|
11829
|
+
if (!isFormSubmitButton(node) || isAlternateNode(node) || isInsideHtmlForm(node)) {
|
|
11830
|
+
return;
|
|
11831
|
+
}
|
|
11757
11832
|
var succeedingButton = getAdjacentActionNode(node, true);
|
|
11758
11833
|
var precedingButton = getAdjacentActionNode(node);
|
|
11759
11834
|
var start = node.loc.start;
|
|
@@ -13121,6 +13196,7 @@
|
|
|
13121
13196
|
|
|
13122
13197
|
var index = {
|
|
13123
13198
|
rules: {
|
|
13199
|
+
"switch-children-must-be-route-or-redirect": switchChildrenMustBeRouteOrRedirect,
|
|
13124
13200
|
"use-dayjs-from-neeto-commons-fronted": useDayjsFromNeetoCommonsFronted,
|
|
13125
13201
|
"use-neetoui-action-block-in-formik-forms": useNeetouiActionBlockInFormikForms,
|
|
13126
13202
|
"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.
|
|
3
|
+
"version": "1.7.4",
|
|
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.
|
|
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",
|