@bigbinary/eslint-plugin-neeto 1.1.5 → 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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/dist/index.js +471 -305
  3. 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)
@@ -105,6 +106,7 @@ module.exports = {
105
106
  - [no-repetition-in-prop-key-value-names](./docs/src/rules/no-repetition-in-prop-key-value-names.md)
106
107
  - [use-functions-and-hooks-from-neeto-commons-frontend.md](./docs/src/rules/use-functions-and-hooks-from-neeto-commons-frontend.md)
107
108
  - [zustand-use-with-immutable-actions-wrapper-inside-create](./docs/src/rules/zustand-use-with-immutable-actions-wrapper-inside-create.md)
109
+ - [add-required-peer-dependencies](./docs/src/rules/add-required-peer-dependencies.md)
108
110
 
109
111
  ## Other references
110
112
 
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda'), require('fs'), require('@bigbinary/neeto-commons-frontend/pure')) :
3
- typeof define === 'function' && define.amd ? define(['path', 'ramda', 'fs', '@bigbinary/neeto-commons-frontend/pure'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path$2, global.ramda, global.fs, global.pure));
5
- })(this, (function (path$2, ramda, fs, pure) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda'), require('@bigbinary/neeto-commons-frontend/pure'), require('fs')) :
3
+ typeof define === 'function' && define.amd ? define(['path', 'ramda', '@bigbinary/neeto-commons-frontend/pure', 'fs'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path$2, global.ramda, global.pure, global.fs));
5
+ })(this, (function (path$2, ramda, pure, fs) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -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",
@@ -204,7 +205,8 @@
204
205
  "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": ["error", {
205
206
  jsconfigFilePath: path__default["default"].join(rootOfTheProject$1, pathToJsConfigFile),
206
207
  aliasFilePath: path__default["default"].join(rootOfTheProject$1, pathToResolveFile$1)
207
- }]
208
+ }],
209
+ "@bigbinary/neeto/add-required-peer-dependencies": "error"
208
210
  }
209
211
  });
210
212
 
@@ -234,6 +236,343 @@
234
236
  }
235
237
  });
236
238
 
239
+ function _typeof$1(obj) {
240
+ "@babel/helpers - typeof";
241
+
242
+ return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
243
+ return typeof obj;
244
+ } : function (obj) {
245
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
246
+ }, _typeof$1(obj);
247
+ }
248
+
249
+ function _toPrimitive(input, hint) {
250
+ if (_typeof$1(input) !== "object" || input === null) return input;
251
+ var prim = input[Symbol.toPrimitive];
252
+ if (prim !== undefined) {
253
+ var res = prim.call(input, hint || "default");
254
+ if (_typeof$1(res) !== "object") return res;
255
+ throw new TypeError("@@toPrimitive must return a primitive value.");
256
+ }
257
+ return (hint === "string" ? String : Number)(input);
258
+ }
259
+
260
+ function _toPropertyKey(arg) {
261
+ var key = _toPrimitive(arg, "string");
262
+ return _typeof$1(key) === "symbol" ? key : String(key);
263
+ }
264
+
265
+ function _defineProperty(obj, key, value) {
266
+ key = _toPropertyKey(key);
267
+ if (key in obj) {
268
+ Object.defineProperty(obj, key, {
269
+ value: value,
270
+ enumerable: true,
271
+ configurable: true,
272
+ writable: true
273
+ });
274
+ } else {
275
+ obj[key] = value;
276
+ }
277
+ return obj;
278
+ }
279
+
280
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
281
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
282
+ var prefix = "export default ";
283
+ var jsonProcessor = {
284
+ _prefix: prefix,
285
+ preprocess: function preprocess(text) {
286
+ return ["".concat(prefix).concat(text)];
287
+ },
288
+ postprocess: function postprocess(messages) {
289
+ return messages.reduce(function (total, next) {
290
+ return total.concat(next.filter(function (error) {
291
+ return error.ruleId && error.ruleId.startsWith("@bigbinary/neeto/");
292
+ }));
293
+ }, []).map(function (message) {
294
+ return message.fix ? _objectSpread$6(_objectSpread$6({}, message), {}, {
295
+ fix: _objectSpread$6(_objectSpread$6({}, message.fix), {}, {
296
+ range: message.fix.range.map(function (rangePart) {
297
+ return Math.max(0, rangePart - prefix.length);
298
+ })
299
+ })
300
+ }) : message;
301
+ });
302
+ },
303
+ supportsAutofix: true
304
+ };
305
+
306
+ var APIS_DIRECTORY = "app/javascript/src/apis";
307
+ var REACT_QUERY_DIRECTORY = "app/javascript/src/hooks/reactQuery";
308
+ var ROUTES_FILE_PATH = "app/javascript/src/routes.js";
309
+ var COMPONENTS_DIRECTORY = "app/javascript/src/components";
310
+ var BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "@bigbinary/neeto-utils"];
311
+ var TYPES = {
312
+ ARRAY_EXPRESSION: "ArrayExpression",
313
+ ARROW_FUNCTION_EXPRESSION: "ArrowFunctionExpression",
314
+ ASSIGNMENT_EXPRESSION: "AssignmentExpression",
315
+ ASSIGNMENT_PATTERN: "AssignmentPattern",
316
+ AWAIT_EXPRESSION: "AwaitExpression",
317
+ BINARY_EXPRESSION: "BinaryExpression",
318
+ BLOCK_STATEMENT: "BlockStatement",
319
+ BREAK_STATEMENT: "BreakStatement",
320
+ CALL_EXPRESSION: "CallExpression",
321
+ CHAIN_EXPRESSION: "ChainExpression",
322
+ CONDITIONAL_EXPRESSION: "ConditionalExpression",
323
+ EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
324
+ EXPORT_DEFAULT_DECLARATION: "ExportDefaultDeclaration",
325
+ EXPRESSION_STATEMENT: "ExpressionStatement",
326
+ FUNCTION_DECLARATION: "FunctionDeclaration",
327
+ FUNCTION_EXPRESSION: "FunctionExpression",
328
+ IDENTIFIER: "Identifier",
329
+ IF_STATEMENT: "IfStatement",
330
+ IMPORT_DECLARATION: "ImportDeclaration",
331
+ IMPORT_DEFAULT_SPECIFIER: "ImportDefaultSpecifier",
332
+ IMPORT_SPECIFIER: "ImportSpecifier",
333
+ JSX_ATTRIBUTE: "JSXAttribute",
334
+ JSX_ELEMENT: "JSXElement",
335
+ JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer",
336
+ JSX_IDENTIFIER: "JSXIdentifier",
337
+ JSX_OPENING_ELEMENT: "JSXOpeningElement",
338
+ JSX_SPREAD_ATTRIBUTE: "JSXSpreadAttribute",
339
+ JSX_TEXT: "JSXText",
340
+ LITERAL: "Literal",
341
+ LOGICAL_EXPRESSION: "LogicalExpression",
342
+ MEMBER_EXPRESSION: "MemberExpression",
343
+ OBJECT_EXPRESSION: "ObjectExpression",
344
+ OBJECT_PATTERN: "ObjectPattern",
345
+ PROGRAM: "Program",
346
+ PROPERTY: "Property",
347
+ RETURN_STATEMENT: "ReturnStatement",
348
+ SPREAD_ELEMENT: "SpreadElement",
349
+ TEMPLATE_ELEMENT: "TemplateElement",
350
+ TEMPLATE_LITERAL: "TemplateLiteral",
351
+ UNARY_EXPRESSION: "UnaryExpression",
352
+ VARIABLE_DECLARATION: "VariableDeclaration",
353
+ VARIABLE_DECLARATOR: "VariableDeclarator",
354
+ WHILE_STATEMENT: "WhileStatement",
355
+ NEW_EXPRESSION: "NewExpression"
356
+ };
357
+ var IMPORT_DECLARATION = {
358
+ type: TYPES.IMPORT_DECLARATION,
359
+ source: {
360
+ type: TYPES.LITERAL
361
+ },
362
+ specifiers: [{
363
+ type: TYPES.IMPORT_SPECIFIER
364
+ }]
365
+ };
366
+ var CAMEL_CASE_REGEX = /^[a-z][A-Za-z0-9]*$/;
367
+ var CONSTANT_CASE_REGEX = /^[A-Z0-9_]+$/;
368
+ var PASCAL_CASE_REGEX = /^(?:[A-Z]+[a-z0-9]+[A-Z]*)+$/;
369
+ var SNAKE_CASE_REGEX = /^[a-z0-9_]+$/;
370
+
371
+ // const TestComponent = () => {}
372
+ var COMPONENT_PATTERN = {
373
+ type: TYPES.VARIABLE_DECLARATION,
374
+ kind: "const",
375
+ declarations: [{
376
+ type: TYPES.VARIABLE_DECLARATOR,
377
+ init: {
378
+ type: TYPES.ARROW_FUNCTION_EXPRESSION
379
+ },
380
+ id: {
381
+ type: TYPES.IDENTIFIER,
382
+ name: ramda.test(PASCAL_CASE_REGEX)
383
+ }
384
+ }]
385
+ };
386
+ var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
387
+
388
+ var ARGUMENT_LIMIT = 3;
389
+ var API_ACTIONS_ARGUMENT_LIMIT = 2;
390
+ var FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
391
+
392
+ /* eslint-disable @bigbinary/neeto/no-dangling-constants */
393
+ var addInJsconfig = function addInJsconfig(aliasName) {
394
+ return "Add path for \"".concat(aliasName, "\" in jsconfig.json. Refer https://bit.ly/sync-webpack-alias-and-jsconfig-paths for more details.");
395
+ };
396
+ var canBeReplacedWith = function canBeReplacedWith(fix) {
397
+ return "Can be replaced with: ".concat(fix);
398
+ };
399
+ var disallowUse = function disallowUse(packageName) {
400
+ return "Do not use the package ".concat(packageName);
401
+ };
402
+ var exportedObjectShouldBe = function exportedObjectShouldBe(caseStyle) {
403
+ return "Exported object should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
404
+ };
405
+ var filenameShouldBe = function filenameShouldBe(caseStyle) {
406
+ return "Filename should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
407
+ };
408
+ var moveToConstantsJs = function moveToConstantsJs(constantName) {
409
+ return "Move the constant ".concat(constantName, " to a constants.js file.");
410
+ };
411
+ var preferSubscriptionUnsubscribe = function preferSubscriptionUnsubscribe(replacerText) {
412
+ return "Prefer to use ".concat(replacerText, ".unsubscribe() to prevent consumer creation boilerplate.");
413
+ };
414
+ var renameFile = function renameFile(filename) {
415
+ return "Rename this file to ".concat(filename);
416
+ };
417
+ var replaceWith$1 = function replaceWith(fix) {
418
+ return "Replace this with: ".concat(fix);
419
+ };
420
+ var unableToResolveKey = function unableToResolveKey(_ref) {
421
+ var key = _ref.key,
422
+ lng = _ref.lng;
423
+ return "Unable to resolve localized string '".concat(key, "' in ").concat(lng, ".json");
424
+ };
425
+ var giveCamelCaseOrPascalCaseNameFor = function giveCamelCaseOrPascalCaseNameFor(functionName) {
426
+ return "Use either camelCase or PascalCase for naming the function - ".concat(functionName, ".");
427
+ };
428
+ var replaceZustandDefaultExportWith = function replaceZustandDefaultExportWith(fix) {
429
+ return "Zustand has deprecated the use of default exports for its functions. Replace this with: ".concat(fix);
430
+ };
431
+ var replaceTailwindClass = function replaceTailwindClass(tailwindClass, neetoUIClass) {
432
+ return "Replace the class \"".concat(tailwindClass, "\" with its neetoui alternative \"").concat(neetoUIClass, "\"");
433
+ };
434
+ var noMultipleComponentsInAFile$1 = function noMultipleComponentsInAFile() {
435
+ var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
436
+ return "Do not have multiple component definitions that exceed ".concat(maxAllowedNoOfLines, " lines in a single file.");
437
+ };
438
+ var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
439
+ return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
440
+ };
441
+ var addRequiredPeerDependencies$1 = function addRequiredPeerDependencies(packageName) {
442
+ return "".concat(packageName, " should be added to peerDependencies");
443
+ };
444
+ var API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE = "API Connector should be exported using the default export method";
445
+ var CAN_BE_REPLACED_WITH_HANDLE_META_CLICK = "Can be replaced with handleMetaClick function. Refer https://bit.ly/handleMetaClick";
446
+ var COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE = "Combine independent awaits to a single `Promise.all` call.";
447
+ var EXPORTED_OBJECT_AND_FILENAME_SHOULD_MATCH_MESSAGE = "Exported object and filename should match.";
448
+ var GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "globalProps should not be assigned to other variables";
449
+ var NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "Nested properties of globalProps should not be assigned to other variables";
450
+ var NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE = "Do not use axios outside `app/javascript/src/apis`";
451
+ var NO_CONDITIONAL_RENDER_OF_OVERLAYS = "Overlay components should not be rendered conditionally. Use `isOpen` attribute instead.";
452
+ var NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE = "API actions should use named parameters for more than ".concat(API_ACTIONS_ARGUMENT_LIMIT, " parameters");
453
+ var NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE = "Functions should use named parameters for more than ".concat(ARGUMENT_LIMIT, " parameters");
454
+ var NO_GLOBALPROPS_REASSIGNMENT_MESSAGE = "globalProps or its nested properties should not be re-assigned.";
455
+ var NO_ROUTES_ASSIGNMENT = "`routes` or its nested properties should not be assigned to other variables.";
456
+ var NO_ROUTES_REASSIGNMENT = "`routes` or its nested properties should not be re-assigned.";
457
+ var NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE = 'Use `import { methodsToImport } from "ramda"` instead';
458
+ var PREFER_EAGER_VALIDATION_MESSAGE = "Prefer to use Formik defaults for `validateOnBlur` and `validateOnChange` to ensure eager validation. Refer https://bit.ly/formik-eager-validation";
459
+ var PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE = "Aliases for anything imported from neetoUI or neetoIcons should start with `NeetoUI`";
460
+ var REPLACE_WITH_HANDLE_META_CLICK = "Replace with handleMetaClick function";
461
+ var ROUTE_SHOULD_BE_A_STRING = "Route should be a plain string literal.";
462
+ var ROUTE_SHOULD_MATCH_OBJECT_PATH = "Route string should match with its object path.";
463
+ var ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
464
+ var ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
465
+ var ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
466
+ var UNNECESSARY_CREATE_CONSUMER = "`createSubscription` function from `neetocommon/utils` invalidates the need of `createConsumer`";
467
+ var USE_ARRAY_METHODS = "Use array methods (forEach, map, filter, reduce, etc) instead of 'for' loop. Refer 'Advanced Array Methods' section in https://bit.ly/array-methods-page-1";
468
+ var USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
469
+ var USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS = "Use `createSubscription` from @bigbinary/neeto-commons-frontend/utils instead. Refer: https://github.com/bigbinary/neeto-commons-frontend/blob/main/docs/utils/README.md#createsubscription";
470
+ var USE_INLINE_SVG_FOR_RENDER = "Use inline SVG instead of img tag for rendering SVGs";
471
+ var USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
472
+ var USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
473
+ var USE_BUTTON_TO_FOR_LINK_NAVIGATION = "Use `to` prop of Button (<Button to='path'>) for click-navigation instead of onClick handler";
474
+ var USE_BUTTON_TO_FOR_ANCHOR_NAVIGATION = "Use `href` prop of Button (<Button href='path'>) for click-navigation instead of onClick handler";
475
+ var USE_NEETO_SMALLER_CASE = "Use 'neeto' instead of 'Neeto' in strings";
476
+ var USE_NEETOUI_BORDER_COLOR = "Use neetoUI border color. Refer https://bit.ly/neeto-ui-border-colors for more details.";
477
+ var USE_NEETOUI_BORDER_RADIUS = "Use neetoUI border radius. Refer https://bit.ly/neeto-ui-border-radius for more details.";
478
+ var USE_NEETOUI_BOX_SHADOW = "Use neetoUI border shadow. Refer https://bit.ly/neeto-ui-box-shadows for more details.";
479
+ var USE_NEETOUI_TEXT_COLOR = "Use neetoUI text color. Refer https://bit.ly/neeto-ui-text-color for more details.";
480
+ var DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR = "Don't use zustand store hook without a selector function. It will impact the performance";
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.";
483
+ var USE_PROP_FOR_PICKING_SINGLE_ITEM = "Use prop instead of pick when picking single item";
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";
485
+ var USE_REACT_QUERY_FOR_MANAGING_REMOTE_DATA = "API calls should be managed using React Query";
486
+ var FILES_INSIDE_REACT_QUERY_FOLDER_SHOULD_END_WITH_API = "Files inside reactQuery folder should end with Api";
487
+ var USE_ZUSTAND_FOR_GLOBAL_STATE_MANAGEMENT = "Use zustand for global state management";
488
+ var AVOID_T_FUNCTIONS_IN_STRING_INTERPOLATION = "Translation function should not be used in string interpolation. Instead use a single translation key for the entire string. Refer: https://bit.ly/localization-best-practices";
489
+ var AVOID_MULTIPLE_T_FUNCTIONS_UNDER_SAME_PARENT = "Avoid using multiple translation functions under the same JSX parent. Instead use a single translation function with a single key. Refer: https://bit.ly/localization-best-practices";
490
+ var USE_TRANS_COMPONENTS_AND_VALUES_PROPS = "Instead of using numbered tags in translation string use `components` and `values` props of `Trans` to use named tag in translation string. Refer: https://bit.ly/localization-best-practices";
491
+ var USE_TRANSLATION_HOOK_IN_COMPONENTS = "Use translation function from `useTranslation()` hook in components.";
492
+ var USE_COMPONENTS_CHILDREN_PROP_IN_TRANS = "Use components children prop instead of label prop in `Trans` component to avoid multiple translation keys.";
493
+ var USE_I18NEXT_PLURALS = "Use plurals that comes with the `i18next` package for hard-coded strings. Refer: https://bit.ly/i18next-plurals";
494
+ var USE_PLURALIZE_PACKAGE = "Use `pluralize` package for dynamic values. Refer: https://bit.ly/i18next-plurals";
495
+ var USE_COPY_TO_CLIPBOARD_FROM_NEETO_COMMONS = "Use `copyToClipboard` from `@bigbinary/neeto-commons-frontend` package. Refer: https://bit.ly/copy-to-clipboard-utility-function";
496
+ var USE_ZUSTAND_PICK_TRANSFORMER = "Replace the boilerplate with zustand-pick syntax offered by babel-preset-neeto. Refer: https://bit.ly/zustand-pick-transform-doc";
497
+ var HARD_CODED_STRING_SHOULD_BE_LOCALIZED = "Hard-coded string should be localized";
498
+ var PROPS_NOT_SORTED = "Props inside spread attributes should be alphabetically sorted";
499
+ var MERGE_ADJACENT_SPREAD_ATTRIBUTES = "Merge spread attributes";
500
+ var DIFFERENT_PROPS_MUST_BE_OUTSIDE = "Props with different key and value should be outside the spread attribute";
501
+ var PROP_KEY_VALUE_DUPLICATE = "Prop key and value names should not be repeated";
502
+ var USE_WITH_IMMUTABLE_ACTIONS_WRAPPER = 'Use "withImmutableActions" wrapper from "neeto-commons-frontend" inside zustand create. Refer: https://bit.ly/withimmutableactions';
503
+
504
+ var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
505
+
506
+ // Checks if the passed package is present as a dependency
507
+ // { packageName: "version" }
508
+ var DependencyPattern = function DependencyPattern(packageName) {
509
+ return {
510
+ type: TYPES.PROPERTY,
511
+ key: {
512
+ type: TYPES.LITERAL,
513
+ value: packageName
514
+ }
515
+ };
516
+ };
517
+
518
+ var getIndentation = function getIndentation(node, context) {
519
+ var indentLevel = context.getSourceCode().getFirstToken(node).loc.start.column;
520
+ return " ".repeat(indentLevel);
521
+ };
522
+
523
+ var addRequiredPeerDependencies = {
524
+ meta: {
525
+ type: "problem",
526
+ docs: {
527
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/add-required-peer-dependencies.md",
528
+ description: "Ensures that dependencies like neetoui, neeto-molecules and neeto-commons-frontend are added in peerDependencies, if used."
529
+ },
530
+ fixable: "code"
531
+ },
532
+ create: function create(context) {
533
+ return {
534
+ Property: function Property(node) {
535
+ if (!context.getFilename().endsWith("package.json") || node.key.value !== "devDependencies") {
536
+ return;
537
+ }
538
+ PACKAGES_TO_CHECK.forEach(function (packageName) {
539
+ var dependencyPattern = DependencyPattern(packageName);
540
+ if (pure.findBy(dependencyPattern, node.value.properties)) {
541
+ var peerDependencies = pure.findBy({
542
+ key: {
543
+ value: "peerDependencies"
544
+ }
545
+ }, node.parent.properties);
546
+ var dependencyIndentLevel = getIndentation(node.value.properties[0], context);
547
+ if (peerDependencies) {
548
+ if (pure.findBy(dependencyPattern, peerDependencies.value.properties)) {
549
+ return;
550
+ }
551
+ context.report({
552
+ node: peerDependencies,
553
+ message: addRequiredPeerDependencies$1(packageName),
554
+ fix: function fix(fixer) {
555
+ return fixer.insertTextAfter(ramda.last(peerDependencies.value.properties), ",\n".concat(dependencyIndentLevel, "\"").concat(packageName, "\": \"latest\""));
556
+ }
557
+ });
558
+ } else {
559
+ context.report({
560
+ node: node,
561
+ message: addRequiredPeerDependencies$1(packageName),
562
+ fix: function fix(fixer) {
563
+ var keyIndentLevel = getIndentation(node, context);
564
+ var fixString = ",\n".concat(keyIndentLevel, "\"peerDependencies\": {\n").concat(dependencyIndentLevel, "\"").concat(packageName, "\": \"latest\"\n").concat(keyIndentLevel, "}");
565
+ return fixer.insertTextAfter(node, fixString);
566
+ }
567
+ });
568
+ }
569
+ }
570
+ });
571
+ }
572
+ };
573
+ }
574
+ };
575
+
237
576
  function _arrayWithHoles(arr) {
238
577
  if (Array.isArray(arr)) return arr;
239
578
  }
@@ -291,7 +630,7 @@
291
630
 
292
631
  var regeneratorRuntime$1 = {exports: {}};
293
632
 
294
- var _typeof$1 = {exports: {}};
633
+ var _typeof = {exports: {}};
295
634
 
296
635
  (function (module) {
297
636
  function _typeof(obj) {
@@ -304,10 +643,10 @@
304
643
  }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
305
644
  }
306
645
  module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
307
- } (_typeof$1));
646
+ } (_typeof));
308
647
 
309
648
  (function (module) {
310
- var _typeof = _typeof$1.exports["default"];
649
+ var _typeof$1 = _typeof.exports["default"];
311
650
  function _regeneratorRuntime() {
312
651
  module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
313
652
  return exports;
@@ -384,7 +723,7 @@
384
723
  if ("throw" !== record.type) {
385
724
  var result = record.arg,
386
725
  value = result.value;
387
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
726
+ return value && "object" == _typeof$1(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
388
727
  invoke("next", value, resolve, reject);
389
728
  }, function (err) {
390
729
  invoke("throw", err, resolve, reject);
@@ -566,158 +905,66 @@
566
905
  },
567
906
  abrupt: function abrupt(type, arg) {
568
907
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
569
- var entry = this.tryEntries[i];
570
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
571
- var finallyEntry = entry;
572
- break;
573
- }
574
- }
575
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
576
- var record = finallyEntry ? finallyEntry.completion : {};
577
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
578
- },
579
- complete: function complete(record, afterLoc) {
580
- if ("throw" === record.type) throw record.arg;
581
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
582
- },
583
- finish: function finish(finallyLoc) {
584
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
585
- var entry = this.tryEntries[i];
586
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
587
- }
588
- },
589
- "catch": function _catch(tryLoc) {
590
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
591
- var entry = this.tryEntries[i];
592
- if (entry.tryLoc === tryLoc) {
593
- var record = entry.completion;
594
- if ("throw" === record.type) {
595
- var thrown = record.arg;
596
- resetTryEntry(entry);
597
- }
598
- return thrown;
599
- }
600
- }
601
- throw new Error("illegal catch attempt");
602
- },
603
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
604
- return this.delegate = {
605
- iterator: values(iterable),
606
- resultName: resultName,
607
- nextLoc: nextLoc
608
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
609
- }
610
- }, exports;
611
- }
612
- module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
613
- } (regeneratorRuntime$1));
614
-
615
- // TODO(Babel 8): Remove this file.
616
-
617
- var runtime = regeneratorRuntime$1.exports();
618
- var regenerator = runtime;
619
-
620
- // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
621
- try {
622
- regeneratorRuntime = runtime;
623
- } catch (accidentalStrictMode) {
624
- if (typeof globalThis === "object") {
625
- globalThis.regeneratorRuntime = runtime;
626
- } else {
627
- Function("r", "regeneratorRuntime = r")(runtime);
628
- }
629
- }
630
-
631
- var APIS_DIRECTORY = "app/javascript/src/apis";
632
- var REACT_QUERY_DIRECTORY = "app/javascript/src/hooks/reactQuery";
633
- var ROUTES_FILE_PATH = "app/javascript/src/routes.js";
634
- var COMPONENTS_DIRECTORY = "app/javascript/src/components";
635
- var BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "@bigbinary/neeto-utils"];
636
- var TYPES = {
637
- ARRAY_EXPRESSION: "ArrayExpression",
638
- ARROW_FUNCTION_EXPRESSION: "ArrowFunctionExpression",
639
- ASSIGNMENT_EXPRESSION: "AssignmentExpression",
640
- ASSIGNMENT_PATTERN: "AssignmentPattern",
641
- AWAIT_EXPRESSION: "AwaitExpression",
642
- BINARY_EXPRESSION: "BinaryExpression",
643
- BLOCK_STATEMENT: "BlockStatement",
644
- BREAK_STATEMENT: "BreakStatement",
645
- CALL_EXPRESSION: "CallExpression",
646
- CHAIN_EXPRESSION: "ChainExpression",
647
- CONDITIONAL_EXPRESSION: "ConditionalExpression",
648
- EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
649
- EXPORT_DEFAULT_DECLARATION: "ExportDefaultDeclaration",
650
- EXPRESSION_STATEMENT: "ExpressionStatement",
651
- FUNCTION_DECLARATION: "FunctionDeclaration",
652
- FUNCTION_EXPRESSION: "FunctionExpression",
653
- IDENTIFIER: "Identifier",
654
- IF_STATEMENT: "IfStatement",
655
- IMPORT_DECLARATION: "ImportDeclaration",
656
- IMPORT_DEFAULT_SPECIFIER: "ImportDefaultSpecifier",
657
- IMPORT_SPECIFIER: "ImportSpecifier",
658
- JSX_ATTRIBUTE: "JSXAttribute",
659
- JSX_ELEMENT: "JSXElement",
660
- JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer",
661
- JSX_IDENTIFIER: "JSXIdentifier",
662
- JSX_OPENING_ELEMENT: "JSXOpeningElement",
663
- JSX_SPREAD_ATTRIBUTE: "JSXSpreadAttribute",
664
- JSX_TEXT: "JSXText",
665
- LITERAL: "Literal",
666
- LOGICAL_EXPRESSION: "LogicalExpression",
667
- MEMBER_EXPRESSION: "MemberExpression",
668
- OBJECT_EXPRESSION: "ObjectExpression",
669
- OBJECT_PATTERN: "ObjectPattern",
670
- PROGRAM: "Program",
671
- PROPERTY: "Property",
672
- RETURN_STATEMENT: "ReturnStatement",
673
- SPREAD_ELEMENT: "SpreadElement",
674
- TEMPLATE_ELEMENT: "TemplateElement",
675
- TEMPLATE_LITERAL: "TemplateLiteral",
676
- UNARY_EXPRESSION: "UnaryExpression",
677
- VARIABLE_DECLARATION: "VariableDeclaration",
678
- VARIABLE_DECLARATOR: "VariableDeclarator",
679
- WHILE_STATEMENT: "WhileStatement",
680
- NEW_EXPRESSION: "NewExpression"
681
- };
682
- var IMPORT_DECLARATION = {
683
- type: TYPES.IMPORT_DECLARATION,
684
- source: {
685
- type: TYPES.LITERAL
686
- },
687
- specifiers: [{
688
- type: TYPES.IMPORT_SPECIFIER
689
- }]
690
- };
691
- var CAMEL_CASE_REGEX = /^[a-z][A-Za-z0-9]*$/;
692
- var CONSTANT_CASE_REGEX = /^[A-Z0-9_]+$/;
693
- var PASCAL_CASE_REGEX = /^(?:[A-Z]+[a-z0-9]+[A-Z]*)+$/;
694
- var SNAKE_CASE_REGEX = /^[a-z0-9_]+$/;
908
+ var entry = this.tryEntries[i];
909
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
910
+ var finallyEntry = entry;
911
+ break;
912
+ }
913
+ }
914
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
915
+ var record = finallyEntry ? finallyEntry.completion : {};
916
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
917
+ },
918
+ complete: function complete(record, afterLoc) {
919
+ if ("throw" === record.type) throw record.arg;
920
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
921
+ },
922
+ finish: function finish(finallyLoc) {
923
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
924
+ var entry = this.tryEntries[i];
925
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
926
+ }
927
+ },
928
+ "catch": function _catch(tryLoc) {
929
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
930
+ var entry = this.tryEntries[i];
931
+ if (entry.tryLoc === tryLoc) {
932
+ var record = entry.completion;
933
+ if ("throw" === record.type) {
934
+ var thrown = record.arg;
935
+ resetTryEntry(entry);
936
+ }
937
+ return thrown;
938
+ }
939
+ }
940
+ throw new Error("illegal catch attempt");
941
+ },
942
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
943
+ return this.delegate = {
944
+ iterator: values(iterable),
945
+ resultName: resultName,
946
+ nextLoc: nextLoc
947
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
948
+ }
949
+ }, exports;
950
+ }
951
+ module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
952
+ } (regeneratorRuntime$1));
695
953
 
696
- // const TestComponent = () => {}
697
- var COMPONENT_PATTERN = {
698
- type: TYPES.VARIABLE_DECLARATION,
699
- kind: "const",
700
- declarations: [{
701
- type: TYPES.VARIABLE_DECLARATOR,
702
- init: {
703
- type: TYPES.ARROW_FUNCTION_EXPRESSION
704
- },
705
- id: {
706
- type: TYPES.IDENTIFIER,
707
- name: ramda.test(PASCAL_CASE_REGEX)
708
- }
709
- }]
710
- };
711
- var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
954
+ // TODO(Babel 8): Remove this file.
712
955
 
713
- function _typeof(obj) {
714
- "@babel/helpers - typeof";
956
+ var runtime = regeneratorRuntime$1.exports();
957
+ var regenerator = runtime;
715
958
 
716
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
717
- return typeof obj;
718
- } : function (obj) {
719
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
720
- }, _typeof(obj);
959
+ // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
960
+ try {
961
+ regeneratorRuntime = runtime;
962
+ } catch (accidentalStrictMode) {
963
+ if (typeof globalThis === "object") {
964
+ globalThis.regeneratorRuntime = runtime;
965
+ } else {
966
+ Function("r", "regeneratorRuntime = r")(runtime);
967
+ }
721
968
  }
722
969
 
723
970
  /**
@@ -731,7 +978,7 @@
731
978
  */
732
979
  var findMatchingNodesDeep = function findMatchingNodesDeep(obj, pattern) {
733
980
  var res = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
734
- if (_typeof(obj) !== "object" || ramda.isNil(obj)) return res;
981
+ if (_typeof$1(obj) !== "object" || ramda.isNil(obj)) return res;
735
982
  if (pure.matches(pattern, obj)) return ramda.append(obj, res);
736
983
  return Object.entries(obj).reduce(function (acc, _ref) {
737
984
  var _ref2 = _slicedToArray(_ref, 2),
@@ -760,7 +1007,7 @@
760
1007
  * @param {Object} obj the object tree to check
761
1008
  */
762
1009
  var patternExistsDeep = /*#__PURE__*/ramda.curry(function (pattern, obj) {
763
- if (_typeof(obj) !== "object" || ramda.isNil(obj)) return false;
1010
+ if (_typeof$1(obj) !== "object" || ramda.isNil(obj)) return false;
764
1011
  if (pure.matches(pattern, obj)) return true;
765
1012
  return Object.entries(obj).some(function (_ref3) {
766
1013
  var _ref4 = _slicedToArray(_ref3, 2),
@@ -967,118 +1214,6 @@
967
1214
  }
968
1215
  };
969
1216
 
970
- var ARGUMENT_LIMIT = 3;
971
- var API_ACTIONS_ARGUMENT_LIMIT = 2;
972
- var FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
973
-
974
- /* eslint-disable @bigbinary/neeto/no-dangling-constants */
975
- var addInJsconfig = function addInJsconfig(aliasName) {
976
- return "Add path for \"".concat(aliasName, "\" in jsconfig.json. Refer https://bit.ly/sync-webpack-alias-and-jsconfig-paths for more details.");
977
- };
978
- var canBeReplacedWith = function canBeReplacedWith(fix) {
979
- return "Can be replaced with: ".concat(fix);
980
- };
981
- var disallowUse = function disallowUse(packageName) {
982
- return "Do not use the package ".concat(packageName);
983
- };
984
- var exportedObjectShouldBe = function exportedObjectShouldBe(caseStyle) {
985
- return "Exported object should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
986
- };
987
- var filenameShouldBe = function filenameShouldBe(caseStyle) {
988
- return "Filename should be in ".concat(caseStyle, ". Refer https://www.youtube.com/watch?v=As9BzWsGJfY");
989
- };
990
- var moveToConstantsJs = function moveToConstantsJs(constantName) {
991
- return "Move the constant ".concat(constantName, " to a constants.js file.");
992
- };
993
- var preferSubscriptionUnsubscribe = function preferSubscriptionUnsubscribe(replacerText) {
994
- return "Prefer to use ".concat(replacerText, ".unsubscribe() to prevent consumer creation boilerplate.");
995
- };
996
- var renameFile = function renameFile(filename) {
997
- return "Rename this file to ".concat(filename);
998
- };
999
- var replaceWith$1 = function replaceWith(fix) {
1000
- return "Replace this with: ".concat(fix);
1001
- };
1002
- var unableToResolveKey = function unableToResolveKey(_ref) {
1003
- var key = _ref.key,
1004
- lng = _ref.lng;
1005
- return "Unable to resolve localized string '".concat(key, "' in ").concat(lng, ".json");
1006
- };
1007
- var giveCamelCaseOrPascalCaseNameFor = function giveCamelCaseOrPascalCaseNameFor(functionName) {
1008
- return "Use either camelCase or PascalCase for naming the function - ".concat(functionName, ".");
1009
- };
1010
- var replaceZustandDefaultExportWith = function replaceZustandDefaultExportWith(fix) {
1011
- return "Zustand has deprecated the use of default exports for its functions. Replace this with: ".concat(fix);
1012
- };
1013
- var replaceTailwindClass = function replaceTailwindClass(tailwindClass, neetoUIClass) {
1014
- return "Replace the class \"".concat(tailwindClass, "\" with its neetoui alternative \"").concat(neetoUIClass, "\"");
1015
- };
1016
- var noMultipleComponentsInAFile$1 = function noMultipleComponentsInAFile() {
1017
- var maxAllowedNoOfLines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
1018
- return "Do not have multiple component definitions that exceed ".concat(maxAllowedNoOfLines, " lines in a single file.");
1019
- };
1020
- var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
1021
- return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
1022
- };
1023
- var API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE = "API Connector should be exported using the default export method";
1024
- var CAN_BE_REPLACED_WITH_HANDLE_META_CLICK = "Can be replaced with handleMetaClick function. Refer https://bit.ly/handleMetaClick";
1025
- var COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE = "Combine independent awaits to a single `Promise.all` call.";
1026
- var EXPORTED_OBJECT_AND_FILENAME_SHOULD_MATCH_MESSAGE = "Exported object and filename should match.";
1027
- var GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "globalProps should not be assigned to other variables";
1028
- var NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "Nested properties of globalProps should not be assigned to other variables";
1029
- var NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE = "Do not use axios outside `app/javascript/src/apis`";
1030
- var NO_CONDITIONAL_RENDER_OF_OVERLAYS = "Overlay components should not be rendered conditionally. Use `isOpen` attribute instead.";
1031
- var NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE = "API actions should use named parameters for more than ".concat(API_ACTIONS_ARGUMENT_LIMIT, " parameters");
1032
- var NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE = "Functions should use named parameters for more than ".concat(ARGUMENT_LIMIT, " parameters");
1033
- var NO_GLOBALPROPS_REASSIGNMENT_MESSAGE = "globalProps or its nested properties should not be re-assigned.";
1034
- var NO_ROUTES_ASSIGNMENT = "`routes` or its nested properties should not be assigned to other variables.";
1035
- var NO_ROUTES_REASSIGNMENT = "`routes` or its nested properties should not be re-assigned.";
1036
- var NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE = 'Use `import { methodsToImport } from "ramda"` instead';
1037
- var PREFER_EAGER_VALIDATION_MESSAGE = "Prefer to use Formik defaults for `validateOnBlur` and `validateOnChange` to ensure eager validation. Refer https://bit.ly/formik-eager-validation";
1038
- var PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE = "Aliases for anything imported from neetoUI or neetoIcons should start with `NeetoUI`";
1039
- var REPLACE_WITH_HANDLE_META_CLICK = "Replace with handleMetaClick function";
1040
- var ROUTE_SHOULD_BE_A_STRING = "Route should be a plain string literal.";
1041
- var ROUTE_SHOULD_MATCH_OBJECT_PATH = "Route string should match with its object path.";
1042
- var ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
1043
- var ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
1044
- var ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
1045
- var UNNECESSARY_CREATE_CONSUMER = "`createSubscription` function from `neetocommon/utils` invalidates the need of `createConsumer`";
1046
- var USE_ARRAY_METHODS = "Use array methods (forEach, map, filter, reduce, etc) instead of 'for' loop. Refer 'Advanced Array Methods' section in https://bit.ly/array-methods-page-1";
1047
- var USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
1048
- var USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS = "Use `createSubscription` from @bigbinary/neeto-commons-frontend/utils instead. Refer: https://github.com/bigbinary/neeto-commons-frontend/blob/main/docs/utils/README.md#createsubscription";
1049
- var USE_INLINE_SVG_FOR_RENDER = "Use inline SVG instead of img tag for rendering SVGs";
1050
- var USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
1051
- var USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
1052
- var USE_BUTTON_TO_FOR_LINK_NAVIGATION = "Use `to` prop of Button (<Button to='path'>) for click-navigation instead of onClick handler";
1053
- var USE_BUTTON_TO_FOR_ANCHOR_NAVIGATION = "Use `href` prop of Button (<Button href='path'>) for click-navigation instead of onClick handler";
1054
- var USE_NEETO_SMALLER_CASE = "Use 'neeto' instead of 'Neeto' in strings";
1055
- var USE_NEETOUI_BORDER_COLOR = "Use neetoUI border color. Refer https://bit.ly/neeto-ui-border-colors for more details.";
1056
- var USE_NEETOUI_BORDER_RADIUS = "Use neetoUI border radius. Refer https://bit.ly/neeto-ui-border-radius for more details.";
1057
- var USE_NEETOUI_BOX_SHADOW = "Use neetoUI border shadow. Refer https://bit.ly/neeto-ui-box-shadows for more details.";
1058
- var USE_NEETOUI_TEXT_COLOR = "Use neetoUI text color. Refer https://bit.ly/neeto-ui-text-color for more details.";
1059
- var DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR = "Don't use zustand store hook without a selector function. It will impact the performance";
1060
- var DONT_USE_ZUSTAND_STORE_WITHOUT_COMPARATOR_FUNCTION = "Don't pick multiple zustand state items without comparator function";
1061
- var USE_PROP_FOR_PICKING_SINGLE_ITEM = "Use prop instead of pick when picking single item";
1062
- 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";
1063
- var USE_REACT_QUERY_FOR_MANAGING_REMOTE_DATA = "API calls should be managed using React Query";
1064
- var FILES_INSIDE_REACT_QUERY_FOLDER_SHOULD_END_WITH_API = "Files inside reactQuery folder should end with Api";
1065
- var USE_ZUSTAND_FOR_GLOBAL_STATE_MANAGEMENT = "Use zustand for global state management";
1066
- var AVOID_T_FUNCTIONS_IN_STRING_INTERPOLATION = "Translation function should not be used in string interpolation. Instead use a single translation key for the entire string. Refer: https://bit.ly/localization-best-practices";
1067
- var AVOID_MULTIPLE_T_FUNCTIONS_UNDER_SAME_PARENT = "Avoid using multiple translation functions under the same JSX parent. Instead use a single translation function with a single key. Refer: https://bit.ly/localization-best-practices";
1068
- var USE_TRANS_COMPONENTS_AND_VALUES_PROPS = "Instead of using numbered tags in translation string use `components` and `values` props of `Trans` to use named tag in translation string. Refer: https://bit.ly/localization-best-practices";
1069
- var USE_TRANSLATION_HOOK_IN_COMPONENTS = "Use translation function from `useTranslation()` hook in components.";
1070
- var USE_COMPONENTS_CHILDREN_PROP_IN_TRANS = "Use components children prop instead of label prop in `Trans` component to avoid multiple translation keys.";
1071
- var USE_I18NEXT_PLURALS = "Use plurals that comes with the `i18next` package for hard-coded strings. Refer: https://bit.ly/i18next-plurals";
1072
- var USE_PLURALIZE_PACKAGE = "Use `pluralize` package for dynamic values. Refer: https://bit.ly/i18next-plurals";
1073
- var USE_COPY_TO_CLIPBOARD_FROM_NEETO_COMMONS = "Use `copyToClipboard` from `@bigbinary/neeto-commons-frontend` package. Refer: https://bit.ly/copy-to-clipboard-utility-function";
1074
- var USE_ZUSTAND_PICK_TRANSFORMER = "Replace the boilerplate with zustand-pick syntax offered by babel-preset-neeto. Refer: https://bit.ly/zustand-pick-transform-doc";
1075
- var HARD_CODED_STRING_SHOULD_BE_LOCALIZED = "Hard-coded string should be localized";
1076
- var PROPS_NOT_SORTED = "Props inside spread attributes should be alphabetically sorted";
1077
- var MERGE_ADJACENT_SPREAD_ATTRIBUTES = "Merge spread attributes";
1078
- var DIFFERENT_PROPS_MUST_BE_OUTSIDE = "Props with different key and value should be outside the spread attribute";
1079
- var PROP_KEY_VALUE_DUPLICATE = "Prop key and value names should not be repeated";
1080
- var USE_WITH_IMMUTABLE_ACTIONS_WRAPPER = 'Use "withImmutableActions" wrapper from "neeto-commons-frontend" inside zustand create. Refer: https://bit.ly/withimmutableactions';
1081
-
1082
1217
  var toCamelCase = function toCamelCase(text) {
1083
1218
  var capitalized = text.split(/[^0-9a-z]/i).map(function (part) {
1084
1219
  return "".concat(part[0].toUpperCase()).concat(part.slice(1));
@@ -1144,37 +1279,6 @@
1144
1279
  }
1145
1280
  };
1146
1281
 
1147
- function _toPrimitive(input, hint) {
1148
- if (_typeof(input) !== "object" || input === null) return input;
1149
- var prim = input[Symbol.toPrimitive];
1150
- if (prim !== undefined) {
1151
- var res = prim.call(input, hint || "default");
1152
- if (_typeof(res) !== "object") return res;
1153
- throw new TypeError("@@toPrimitive must return a primitive value.");
1154
- }
1155
- return (hint === "string" ? String : Number)(input);
1156
- }
1157
-
1158
- function _toPropertyKey(arg) {
1159
- var key = _toPrimitive(arg, "string");
1160
- return _typeof(key) === "symbol" ? key : String(key);
1161
- }
1162
-
1163
- function _defineProperty(obj, key, value) {
1164
- key = _toPropertyKey(key);
1165
- if (key in obj) {
1166
- Object.defineProperty(obj, key, {
1167
- value: value,
1168
- enumerable: true,
1169
- configurable: true,
1170
- writable: true
1171
- });
1172
- } else {
1173
- obj[key] = value;
1174
- }
1175
- return obj;
1176
- }
1177
-
1178
1282
  var AWAIT_DECLARATION_PATTERN = {
1179
1283
  type: TYPES.VARIABLE_DECLARATOR,
1180
1284
  init: {
@@ -5859,7 +5963,7 @@
5859
5963
 
5860
5964
  var findAllRamdaUsage = function findAllRamdaUsage(node, identifierName) {
5861
5965
  var acc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5862
- if (!node || _typeof(node) !== "object") return acc;
5966
+ if (!node || _typeof$1(node) !== "object") return acc;
5863
5967
  return Object.entries(node).reduce(function (acc, _ref) {
5864
5968
  var _ref2 = _slicedToArray(_ref, 2),
5865
5969
  key = _ref2[0],
@@ -25474,6 +25578,63 @@
25474
25578
  }
25475
25579
  };
25476
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
+
25477
25638
  var isSnakeCase = function isSnakeCase(text) {
25478
25639
  return SNAKE_CASE_REGEX.test(text);
25479
25640
  };
@@ -26131,6 +26292,7 @@
26131
26292
  "use-inline-svg-for-render": useInlineSvgForRender,
26132
26293
  "use-neeto-in-strings": useNeetoInStrings,
26133
26294
  "use-neetoui-classes": useNeetouiClasses,
26295
+ "use-permissions-prop-in-private-route": usePermissionsPropInPrivateRoute,
26134
26296
  "use-pluralize-package": usePluralizePackage,
26135
26297
  "use-react-query-for-managing-remote-data": useReactQueryForManagingRemoteData,
26136
26298
  "use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
@@ -26148,12 +26310,16 @@
26148
26310
  "no-repetition-in-prop-key-value-names": noRepetitionInPropKeyAndValueName,
26149
26311
  "use-functions-and-hooks-from-neeto-commons-frontend": useFunctionsAndHooksFromNeetoCommonsFrontend,
26150
26312
  "no-unnecessary-if-condition": noUnnecessaryIfCondition,
26151
- "zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate
26313
+ "zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
26314
+ "add-required-peer-dependencies": addRequiredPeerDependencies
26152
26315
  },
26153
26316
  configs: {
26154
26317
  recommended: recommended,
26155
26318
  "nextjs-recommended": nextjsRecommended,
26156
26319
  "nanos-recommended": nanosRecommended
26320
+ },
26321
+ processors: {
26322
+ ".json": jsonProcessor
26157
26323
  }
26158
26324
  };
26159
26325
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {