@bigbinary/eslint-plugin-neeto 1.1.6 → 1.1.7

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
@@ -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";
@@ -25576,6 +25578,63 @@
25576
25578
  }
25577
25579
  };
25578
25580
 
25581
+ var PERMISSION_FUNCTIONS = ["hasPermission", "hasAllPermissions", "hasAnyPermission"];
25582
+ var CONDITION_ATTRIBUTE_PATTERN = {
25583
+ type: TYPES.JSX_ATTRIBUTE,
25584
+ name: {
25585
+ type: TYPES.JSX_IDENTIFIER,
25586
+ name: "condition"
25587
+ },
25588
+ value: {
25589
+ type: TYPES.JSX_EXPRESSION_CONTAINER,
25590
+ expression: {
25591
+ type: TYPES.CALL_EXPRESSION,
25592
+ callee: {
25593
+ type: TYPES.IDENTIFIER,
25594
+ name: ramda.includes(ramda.__, PERMISSION_FUNCTIONS)
25595
+ }
25596
+ }
25597
+ }
25598
+ };
25599
+ var PRIVATE_ROUTE_PATTERN = {
25600
+ type: TYPES.JSX_OPENING_ELEMENT,
25601
+ name: {
25602
+ type: TYPES.JSX_IDENTIFIER,
25603
+ name: "PrivateRoute"
25604
+ },
25605
+ attributes: pure.existsBy(CONDITION_ATTRIBUTE_PATTERN)
25606
+ };
25607
+
25608
+ var usePermissionsPropInPrivateRoute = {
25609
+ meta: {
25610
+ type: "suggestion",
25611
+ docs: {
25612
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-permissions-prop-in-private-route.md",
25613
+ description: "Enforces the use of permissions prop for permission checks in PrivateRoute"
25614
+ },
25615
+ fixable: "code"
25616
+ },
25617
+ create: function create(context) {
25618
+ return {
25619
+ JSXOpeningElement: function JSXOpeningElement(node) {
25620
+ if (!pure.matches(PRIVATE_ROUTE_PATTERN, node)) return;
25621
+ var errorNode = pure.findBy(CONDITION_ATTRIBUTE_PATTERN, node.attributes);
25622
+ var functionArguments = errorNode.value.expression.arguments;
25623
+ var arrayFormat = functionArguments.map(function (argument) {
25624
+ return argument.type === TYPES.ARRAY_EXPRESSION ? context.getSourceCode().getText(argument).slice(1, -1) : context.getSourceCode().getText(argument);
25625
+ }).join(", ");
25626
+ context.report({
25627
+ node: errorNode,
25628
+ message: USE_PERMISSIONS_PROP_IN_PRIVATE_ROUTE,
25629
+ fix: function fix(fixer) {
25630
+ return fixer.replaceText(errorNode, "permissions={[".concat(arrayFormat, "]}"));
25631
+ }
25632
+ });
25633
+ }
25634
+ };
25635
+ }
25636
+ };
25637
+
25579
25638
  var isSnakeCase = function isSnakeCase(text) {
25580
25639
  return SNAKE_CASE_REGEX.test(text);
25581
25640
  };
@@ -26233,6 +26292,7 @@
26233
26292
  "use-inline-svg-for-render": useInlineSvgForRender,
26234
26293
  "use-neeto-in-strings": useNeetoInStrings,
26235
26294
  "use-neetoui-classes": useNeetouiClasses,
26295
+ "use-permissions-prop-in-private-route": usePermissionsPropInPrivateRoute,
26236
26296
  "use-pluralize-package": usePluralizePackage,
26237
26297
  "use-react-query-for-managing-remote-data": useReactQueryForManagingRemoteData,
26238
26298
  "use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {