@bigbinary/eslint-plugin-neeto 1.1.6 → 1.1.8
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 +76 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ module.exports = {
|
|
|
88
88
|
- [use-inline-svg-for-render](./docs/src/rules/use-inline-svg-for-render.md)
|
|
89
89
|
- [use-neeto-in-strings](./docs/src/rules/use-neeto-in-strings.md)
|
|
90
90
|
- [use-neetoui-classes](./docs/src/rules/use-neetoui-classes.md)
|
|
91
|
+
- [use-permissions-prop-in-private-route](./docs/src/rules/use-permissions-prop-in-private-route.md)
|
|
91
92
|
- [use-pluralize-package](./docs/src/rules/use-pluralize-package.md)
|
|
92
93
|
- [use-react-query-for-managing-remote-data](./docs/src/rules/use-react-query-for-managing-remote-data.md)
|
|
93
94
|
- [use-snake-case-for-api-connector-filename](./docs/src/rules/use-snake-case-for-api-connector-filename.md)
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"@bigbinary/neeto/use-inline-svg-for-render": "error",
|
|
106
106
|
"@bigbinary/neeto/use-neeto-in-strings": "warn",
|
|
107
107
|
"@bigbinary/neeto/use-neetoui-classes": "warn",
|
|
108
|
+
"@bigbinary/neeto/use-permissions-prop-in-private-route": "warn",
|
|
108
109
|
"@bigbinary/neeto/use-pluralize-package": "error",
|
|
109
110
|
"@bigbinary/neeto/use-react-query-for-managing-remote-data": "warn",
|
|
110
111
|
"@bigbinary/neeto/use-snake-case-for-api-connector-filename": "error",
|
|
@@ -478,6 +479,7 @@
|
|
|
478
479
|
var USE_NEETOUI_TEXT_COLOR = "Use neetoUI text color. Refer https://bit.ly/neeto-ui-text-color for more details.";
|
|
479
480
|
var DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR = "Don't use zustand store hook without a selector function. It will impact the performance";
|
|
480
481
|
var DONT_USE_ZUSTAND_STORE_WITHOUT_COMPARATOR_FUNCTION = "Don't pick multiple zustand state items without comparator function";
|
|
482
|
+
var USE_PERMISSIONS_PROP_IN_PRIVATE_ROUTE = "Use `permissions` prop of PrivateRoute component for consistency in handling permission denied pages.";
|
|
481
483
|
var USE_PROP_FOR_PICKING_SINGLE_ITEM = "Use prop instead of pick when picking single item";
|
|
482
484
|
var ENSURE_ZUSTAND_STORES_ARE_TYPE_ANNOTATED = "\n Zustand stores should be type annotated like this:\n /** @type {import(\"neetocommons/react-utils\").ZustandStoreHook} */\n const useUserStore = create(...)\n";
|
|
483
485
|
var USE_REACT_QUERY_FOR_MANAGING_REMOTE_DATA = "API calls should be managed using React Query";
|
|
@@ -3932,7 +3934,7 @@
|
|
|
3932
3934
|
};
|
|
3933
3935
|
var NATURAL_LANGUAGE_REGEX = /^(?:(?:[a-z]+\s)+|\s(?:[a-z]+\s)+|[a-z]*(?:\s[a-z]+)+)$/i;
|
|
3934
3936
|
var EXCLUDED_KEYWORDS_REGEX = /^(.*classnames?|.*class|.*styles?|.*format|viewBox|d|keybinding|rel|sequence)$/i;
|
|
3935
|
-
var INCLUDED_KEYWORDS_REGEX = /^(.*label|.*title|placeholder|helpText)$/i;
|
|
3937
|
+
var INCLUDED_KEYWORDS_REGEX = /^(.*label|.*title|placeholder|helpText|message|description)$/i;
|
|
3936
3938
|
var ONLY_NON_WORD_CHAR_REGEX = /^[\s\n\r\t\W0-9_ ]*(&.*;)*[\s\n\r\t\W0-9_ ]*$/;
|
|
3937
3939
|
|
|
3938
3940
|
var getNodeName = function getNodeName(node) {
|
|
@@ -3950,17 +3952,26 @@
|
|
|
3950
3952
|
}
|
|
3951
3953
|
};
|
|
3952
3954
|
var shouldReport = function shouldReport(node, nodeValue, context) {
|
|
3953
|
-
if (
|
|
3954
|
-
|
|
3955
|
-
|
|
3955
|
+
if (node.type !== TYPES.TEMPLATE_LITERAL) {
|
|
3956
|
+
if (typeof nodeValue !== "string") return false;
|
|
3957
|
+
var containOnlyNonWordChars = ONLY_NON_WORD_CHAR_REGEX.test(nodeValue);
|
|
3958
|
+
if (containOnlyNonWordChars) return false;
|
|
3959
|
+
}
|
|
3956
3960
|
var isJSXTextType = node.type === TYPES.JSX_TEXT;
|
|
3957
3961
|
if (isJSXTextType) return true;
|
|
3958
3962
|
var ancestors = context.getAncestors(node);
|
|
3963
|
+
var isMatchesNaturalLangRegex = NATURAL_LANGUAGE_REGEX.test(nodeValue);
|
|
3959
3964
|
for (var i = ancestors.length - 1; i > 0; i--) {
|
|
3960
3965
|
var _parent$init;
|
|
3961
3966
|
var parent = ancestors[i];
|
|
3967
|
+
var excludedTypes = [TYPES.MEMBER_EXPRESSION, TYPES.BINARY_EXPRESSION];
|
|
3968
|
+
if (excludedTypes.includes(parent.type)) {
|
|
3969
|
+
return false;
|
|
3970
|
+
}
|
|
3962
3971
|
if (((_parent$init = parent.init) === null || _parent$init === void 0 ? void 0 : _parent$init.type) === TYPES.ARROW_FUNCTION_EXPRESSION) return false;
|
|
3963
3972
|
if (parent.type === TYPES.CALL_EXPRESSION) {
|
|
3973
|
+
var _parent$callee;
|
|
3974
|
+
if (((_parent$callee = parent.callee) === null || _parent$callee === void 0 ? void 0 : _parent$callee.name) === "t" && isMatchesNaturalLangRegex) return true;
|
|
3964
3975
|
var isToastrFunc = pure.matches(TOASTR_CALL_EXPRESSION_PATTERN, parent);
|
|
3965
3976
|
return isToastrFunc;
|
|
3966
3977
|
}
|
|
@@ -3968,11 +3979,10 @@
|
|
|
3968
3979
|
if (nodeName) {
|
|
3969
3980
|
var isInIncludedList = INCLUDED_KEYWORDS_REGEX.test(nodeName);
|
|
3970
3981
|
if (isInIncludedList) return true;
|
|
3971
|
-
var
|
|
3972
|
-
if (!
|
|
3982
|
+
var _isMatchesNaturalLangRegex = NATURAL_LANGUAGE_REGEX.test(nodeValue);
|
|
3983
|
+
if (!_isMatchesNaturalLangRegex) return false;
|
|
3973
3984
|
var isInExcludedList = EXCLUDED_KEYWORDS_REGEX.test(nodeName);
|
|
3974
3985
|
if (isInExcludedList) return false;
|
|
3975
|
-
return true;
|
|
3976
3986
|
}
|
|
3977
3987
|
}
|
|
3978
3988
|
return false;
|
|
@@ -3998,7 +4008,7 @@
|
|
|
3998
4008
|
Literal: function Literal(node) {
|
|
3999
4009
|
checkAndReport$3(node, context);
|
|
4000
4010
|
},
|
|
4001
|
-
|
|
4011
|
+
TemplateLiteral: function TemplateLiteral(node) {
|
|
4002
4012
|
checkAndReport$3(node, context);
|
|
4003
4013
|
},
|
|
4004
4014
|
JSXText: function JSXText(node) {
|
|
@@ -25576,6 +25586,63 @@
|
|
|
25576
25586
|
}
|
|
25577
25587
|
};
|
|
25578
25588
|
|
|
25589
|
+
var PERMISSION_FUNCTIONS = ["hasPermission", "hasAllPermissions", "hasAnyPermission"];
|
|
25590
|
+
var CONDITION_ATTRIBUTE_PATTERN = {
|
|
25591
|
+
type: TYPES.JSX_ATTRIBUTE,
|
|
25592
|
+
name: {
|
|
25593
|
+
type: TYPES.JSX_IDENTIFIER,
|
|
25594
|
+
name: "condition"
|
|
25595
|
+
},
|
|
25596
|
+
value: {
|
|
25597
|
+
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
25598
|
+
expression: {
|
|
25599
|
+
type: TYPES.CALL_EXPRESSION,
|
|
25600
|
+
callee: {
|
|
25601
|
+
type: TYPES.IDENTIFIER,
|
|
25602
|
+
name: ramda.includes(ramda.__, PERMISSION_FUNCTIONS)
|
|
25603
|
+
}
|
|
25604
|
+
}
|
|
25605
|
+
}
|
|
25606
|
+
};
|
|
25607
|
+
var PRIVATE_ROUTE_PATTERN = {
|
|
25608
|
+
type: TYPES.JSX_OPENING_ELEMENT,
|
|
25609
|
+
name: {
|
|
25610
|
+
type: TYPES.JSX_IDENTIFIER,
|
|
25611
|
+
name: "PrivateRoute"
|
|
25612
|
+
},
|
|
25613
|
+
attributes: pure.existsBy(CONDITION_ATTRIBUTE_PATTERN)
|
|
25614
|
+
};
|
|
25615
|
+
|
|
25616
|
+
var usePermissionsPropInPrivateRoute = {
|
|
25617
|
+
meta: {
|
|
25618
|
+
type: "suggestion",
|
|
25619
|
+
docs: {
|
|
25620
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-permissions-prop-in-private-route.md",
|
|
25621
|
+
description: "Enforces the use of permissions prop for permission checks in PrivateRoute"
|
|
25622
|
+
},
|
|
25623
|
+
fixable: "code"
|
|
25624
|
+
},
|
|
25625
|
+
create: function create(context) {
|
|
25626
|
+
return {
|
|
25627
|
+
JSXOpeningElement: function JSXOpeningElement(node) {
|
|
25628
|
+
if (!pure.matches(PRIVATE_ROUTE_PATTERN, node)) return;
|
|
25629
|
+
var errorNode = pure.findBy(CONDITION_ATTRIBUTE_PATTERN, node.attributes);
|
|
25630
|
+
var functionArguments = errorNode.value.expression.arguments;
|
|
25631
|
+
var arrayFormat = functionArguments.map(function (argument) {
|
|
25632
|
+
return argument.type === TYPES.ARRAY_EXPRESSION ? context.getSourceCode().getText(argument).slice(1, -1) : context.getSourceCode().getText(argument);
|
|
25633
|
+
}).join(", ");
|
|
25634
|
+
context.report({
|
|
25635
|
+
node: errorNode,
|
|
25636
|
+
message: USE_PERMISSIONS_PROP_IN_PRIVATE_ROUTE,
|
|
25637
|
+
fix: function fix(fixer) {
|
|
25638
|
+
return fixer.replaceText(errorNode, "permissions={[".concat(arrayFormat, "]}"));
|
|
25639
|
+
}
|
|
25640
|
+
});
|
|
25641
|
+
}
|
|
25642
|
+
};
|
|
25643
|
+
}
|
|
25644
|
+
};
|
|
25645
|
+
|
|
25579
25646
|
var isSnakeCase = function isSnakeCase(text) {
|
|
25580
25647
|
return SNAKE_CASE_REGEX.test(text);
|
|
25581
25648
|
};
|
|
@@ -26233,6 +26300,7 @@
|
|
|
26233
26300
|
"use-inline-svg-for-render": useInlineSvgForRender,
|
|
26234
26301
|
"use-neeto-in-strings": useNeetoInStrings,
|
|
26235
26302
|
"use-neetoui-classes": useNeetouiClasses,
|
|
26303
|
+
"use-permissions-prop-in-private-route": usePermissionsPropInPrivateRoute,
|
|
26236
26304
|
"use-pluralize-package": usePluralizePackage,
|
|
26237
26305
|
"use-react-query-for-managing-remote-data": useReactQueryForManagingRemoteData,
|
|
26238
26306
|
"use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
|