@bigbinary/eslint-plugin-neeto 1.2.0 → 1.4.0

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 +53 -16
  2. package/dist/index.js +123 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -46,12 +46,15 @@ module.exports = {
46
46
 
47
47
  ## Exported rules
48
48
 
49
+ ESLint rules are categorized as either errors or warnings based on the severity
50
+ of the issues identified in JavaScript code.
51
+
52
+ ### Errors
53
+
49
54
  - [no-unnecessary-classnames](./docs/src/rules/no-unnecessary-classnames.md)
50
- - [no-snake-case-destructuring-for-use-query-params-and-get-query-params](./docs/src/rules/no-snake-case-destructuring-for-use-query-params-and-get-query-params.md)
51
55
  - [no-local-storage](./docs/src/rules/no-local-storage.md)
52
56
  - [no-lowercase-on-translation](./docs/src/rules/no-lowercase-on-translation.md)
53
57
  - [use-use-query-client-hook](./docs/src/rules/use-use-query-client-hook.md)
54
- - [use-early-return](./docs/src/rules/use-early-return.md)
55
58
  - [use-classnames-for-dynamic-classes](./docs/src/rules/use-classnames-for-dynamic-classes.md)
56
59
  - [use-use-mutation-with-invalidation-hook](./docs/src/rules/use-use-mutation-with-invalidation-hook.md)
57
60
  - [no-withT-for-smart-components](./docs/src/rules/no-withT-for-smart-components.md)
@@ -61,22 +64,16 @@ module.exports = {
61
64
  - [no-unnecessary-if-condition](./docs/src/rules/no-unnecessary-if-condition.md)
62
65
  - [api-connector-name-should-match-filename](./docs/src/rules/api-connector-name-should-match-filename.md)
63
66
  - [api-connector-should-use-default-export](./docs/src/rules/api-connector-should-use-default-export.md)
64
- - [combine-multiple-independent-awaits](./docs/src/rules/combine-multiple-independent-awaits.md)
65
- - [consistent-button-link-anchor](./docs/src/rules/consistent-button-link-anchor.md)
66
67
  - [ensure-compact-objects](./docs/src/rules/ensure-compact-objects.md)
67
68
  - [ensure-formik-eager-validation](./docs/src/rules/ensure-formik-eager-validation.md)
68
69
  - [ensure-zustand-stores-are-type-annotated](./docs/src/rules/ensure-zustand-stores-are-type-annotated.md)
69
70
  - [files-inside-react-query-folder-should-end-with-api](./docs/src/rules/files-inside-react-query-folder-should-end-with-api.md)
70
- - [file-name-and-export-name-standards](./docs/src/rules/file-name-and-export-name-standards.md)
71
- - [hard-coded-strings-should-be-localized](./docs/src/rules/hard-coded-strings-should-be-localized.md)
72
71
  - [minimize-zustand-store-access-scope](./docs/src/rules/minimize-zustand-store-access-scope.md)
73
- - [neetocommons-tips](./docs/src/rules/neetocommons-tips.md)
74
72
  - [no-axios-import-outside-apis](./docs/src/rules/no-axios-import-outside-apis.md)
75
73
  - [no-blacklisted-imports](./docs/src/rules/no-blacklisted-imports.md)
76
74
  - [no-conditional-overlays](./docs/src/rules/no-conditional-overlays.md)
77
75
  - [no-deprecated-imports-from-zustand](./docs/src/rules/no-deprecated-imports-from-zustand.md)
78
76
  - [no-dangling-constants](./docs/src/rules/no-dangling-constants.md)
79
- - [no-excess-function-arguments](./docs/src/rules/no-excess-function-arguments.md)
80
77
  - [no-globalProps-destructure](./docs/src/rules/no-globalProps-destructure.md)
81
78
  - [no-globalProps-reassignment](./docs/src/rules/no-globalProps-reassignment.md)
82
79
  - [no-missing-localization](./docs/src/rules/no-missing-localization.md)
@@ -88,27 +85,21 @@ module.exports = {
88
85
  - [no-routes-destructure-and-reassignment](./docs/src/rules/no-routes-destructure-and-reassignment.md)
89
86
  - [no-translation-functions-in-string-interpolation](./docs/src/rules/no-translation-functions-in-string-interpolation.md)
90
87
  - [prefix-neeto-ui-import-alias](./docs/src/rules/prefix-neeto-ui-import-alias.md)
91
- - [ramda-tips](./docs/src/rules/ramda-tips.md)
92
88
  - [routes-should-be-declared-and-default-exported](./docs/src/rules/routes-should-be-declared-and-default-exported.md)
93
89
  - [routes-should-match-object-path](./docs/src/rules/routes-should-match-object-path.md)
94
90
  - [use-array-methods](./docs/src/rules/use-array-methods.md)
95
91
  - [use-axios-config-for-passing-query-parameters](./docs/src/rules/use-axios-config-for-passing-query-parameters.md)
96
92
  - [use-camel-case-or-pascal-case-for-function-names](./docs/src/rules/use-camel-case-or-pascal-case-for-function-names.md)
97
- - [use-common-constants](./docs/src/rules/use-common-constants.md)
98
93
  - [use-common-routes](./docs/src/rules/use-common-routes.md)
99
94
  - [use-components-children-prop-in-trans](./docs/src/rules/use-components-children-prop-in-trans.md)
100
95
  - [use-create-subscription-util-function](./docs/src/rules/use-create-subscription-util-function.md)
101
96
  - [use-i18next-plurals](./docs/src/rules/use-i18next-plurals.md)
102
97
  - [use-inline-svg-for-render](./docs/src/rules/use-inline-svg-for-render.md)
103
- - [use-neeto-in-strings](./docs/src/rules/use-neeto-in-strings.md)
104
- - [use-neetoui-classes](./docs/src/rules/use-neetoui-classes.md)
105
- - [use-permissions-prop-in-private-route](./docs/src/rules/use-permissions-prop-in-private-route.md)
106
98
  - [use-pluralize-package](./docs/src/rules/use-pluralize-package.md)
107
99
  - [use-react-query-for-managing-remote-data](./docs/src/rules/use-react-query-for-managing-remote-data.md)
108
100
  - [use-snake-case-for-api-connector-filename](./docs/src/rules/use-snake-case-for-api-connector-filename.md)
109
101
  - [use-translation-hook-in-components](./docs/src/rules/use-translation-hook-in-components.md)
110
102
  - [use-trans-components-and-values-props](./docs/src/rules/use-trans-components-and-values-props.md)
111
- - [use-webpack-alias](./docs/src/rules/use-webpack-alias.md)
112
103
  - [use-zustand-for-global-state-management](./docs/src/rules/use-zustand-for-global-state-management.md)
113
104
  - [webpack-aliases-and-jsconfig-paths-should-be-in-sync](./docs/src/rules/webpack-aliases-and-jsconfig-paths-should-be-in-sync.md)
114
105
  - [zustand-recommend-comparator-function-usage](./docs/src/rules/zustand-recommend-comparator-function-usage.md)
@@ -118,12 +109,58 @@ module.exports = {
118
109
  - [merge-spread-attributes](./docs/src/rules/merge-spread-attributes.md)
119
110
  - [props-with-different-key-value-should-be-outside-spread-attribute](./docs/src/rules/props-with-different-key-value-should-be-outside-spread-attribute.md)
120
111
  - [no-repetition-in-prop-key-value-names](./docs/src/rules/no-repetition-in-prop-key-value-names.md)
121
- - [use-functions-and-hooks-from-neeto-commons-frontend.md](./docs/src/rules/use-functions-and-hooks-from-neeto-commons-frontend.md)
122
112
  - [zustand-use-with-immutable-actions-wrapper-inside-create](./docs/src/rules/zustand-use-with-immutable-actions-wrapper-inside-create.md)
123
113
  - [add-required-peer-dependencies](./docs/src/rules/add-required-peer-dependencies.md)
124
114
  - [move-spread-attributes-to-top-position](./docs/src/rules/move-spread-attributes-to-top-position.md)
125
- - [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
115
+ - [use-show-thumbs-up-toastr](./docs/src/rules/use-show-thumbs-up-toastr)
116
+ - [ensure-usestate-has-initial-value](./docs/src/rules/ensure-usestate-has-initial-value.md)
117
+
118
+ ### Warnings
119
+
120
+ - [ramda-tips](./docs/src/rules/ramda-tips.md)
121
+ - [combine-multiple-independent-awaits](./docs/src/rules/combine-multiple-independent-awaits.md)
122
+ - [consistent-button-link-anchor](./docs/src/rules/consistent-button-link-anchor.md)
123
+ - [file-name-and-export-name-standards](./docs/src/rules/file-name-and-export-name-standards.md)
124
+ - [hard-coded-strings-should-be-localized](./docs/src/rules/hard-coded-strings-should-be-localized.md)
126
125
  - [jsx-prefer-guard-clause.md](./docs/src/rules/jsx-prefer-guard-clause.md)
126
+ - [neetocommons-tips](./docs/src/rules/neetocommons-tips.md)
127
+ - [no-excess-function-arguments](./docs/src/rules/no-excess-function-arguments.md)
128
+ - [no-snake-case-destructuring-for-use-query-params-and-get-query-params](./docs/src/rules/no-snake-case-destructuring-for-use-query-params-and-get-query-params.md)
129
+ - [prefer-function-reference.md](./docs/src/rules/prefer-function-reference.md)
130
+ - [use-common-constants](./docs/src/rules/use-common-constants.md)
131
+ - [use-early-return](./docs/src/rules/use-early-return.md)
132
+ - [use-functions-and-hooks-from-neeto-commons-frontend.md](./docs/src/rules/use-functions-and-hooks-from-neeto-commons-frontend.md)
133
+ - [use-neeto-in-strings](./docs/src/rules/use-neeto-in-strings.md)
134
+ - [use-neetoui-classes](./docs/src/rules/use-neetoui-classes.md)
135
+ - [use-permissions-prop-in-private-route](./docs/src/rules/use-permissions-prop-in-private-route.md)
136
+ - [use-webpack-alias](./docs/src/rules/use-webpack-alias.md)
137
+
138
+ ## Overriding rules
139
+
140
+ ### ESLint Errors
141
+
142
+ ESLint errors flag the mandatory coding standards that developers must strictly
143
+ adhere to. These errors are detected by the `pre-commit` hook and in CI checks.
144
+ There may be instances where we intentionally choose to adopt a particular
145
+ coding style and wish to prevent ESLint from throwing errors. In such cases, you
146
+ can temporarily disable the rule responsible for the false alarm by adding a
147
+ comment above the code, specifying the reason why you have disabled that
148
+ particular rule for that line to avoid any future confusion:
149
+
150
+ ```js
151
+ // Reason for disabling the rule.
152
+ // eslint-disable-next-line <rule>
153
+ ```
154
+
155
+ ### ESLint Warnings
156
+
157
+ When creating an ESLint rule, it may not always be possible to cover every edge
158
+ case and eliminate all false positives. Such rules have been configured as
159
+ warnings instead of errors. These warnings are not flagged during `pre-commit`
160
+ hooks or CI checks. Nevertheless, ESLint warnings also need to be treated in the
161
+ same way as ESLint errors. It's recommended to review and address them whenever
162
+ feasible. However, if you find that the suggestion does not apply to your
163
+ specific situation, you have the flexibility to disregard it.
127
164
 
128
165
  ## Other references
129
166
 
package/dist/index.js CHANGED
@@ -164,7 +164,9 @@
164
164
  "@bigbinary/neeto/use-common-constants": "warn",
165
165
  "@bigbinary/neeto/move-spread-attributes-to-top-position": "error",
166
166
  "@bigbinary/neeto/prefer-function-reference": "warn",
167
- "@bigbinary/neeto/jsx-prefer-guard-clause": "warn"
167
+ "@bigbinary/neeto/jsx-prefer-guard-clause": "warn",
168
+ "@bigbinary/neeto/ensure-usestate-has-initial-value": "error",
169
+ "@bigbinary/neeto/use-show-thumbs-up-toastr": "error"
168
170
  };
169
171
 
170
172
  var recommended = {
@@ -439,6 +441,18 @@
439
441
  var NO_OF_LINES_ALLOWED_FOR_MULTIPLE_COMPONENTS_IN_A_FILE = 20;
440
442
  var MAX_LINES_FOR_FUNCTIONS_INSIDE_JSX = 4;
441
443
 
444
+ // import { functionName } from neetocommons/utils;
445
+ var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
446
+ type: TYPES.IMPORT_DECLARATION,
447
+ source: {
448
+ type: TYPES.LITERAL,
449
+ value: "neetocommons/utils"
450
+ },
451
+ specifiers: [{
452
+ type: TYPES.IMPORT_SPECIFIER
453
+ }]
454
+ };
455
+
442
456
  var ARGUMENT_LIMIT = 3;
443
457
  var API_ACTIONS_ARGUMENT_LIMIT = 2;
444
458
  var FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
@@ -571,7 +585,9 @@
571
585
  var AVOID_SNAKE_CASE_DESTRUCTURING_USEQUERYPARAMS_OR_GETQUERYPARAMS = "Avoid destructuring snake-cased values from getQueryParams or useQueryParams";
572
586
  var PREFER_FUNCTION_REFERENCE = "Prefer passing function reference instead of creating a new function as the parameters and arguments are the same.";
573
587
  var JSX_PREFER_GUARD_CLAUSE = "Prefer adding a guard clause for conditional statements left of JSX statments in the last return statement of the function.";
588
+ var USE_SHOW_THUMBS_UP_TOASTR_FUNCTION = "Use 'showThumbsUpToastr' function from '@bigbinary/neeto-commons-frontend/utils' for displaying thumbs up toast message.";
574
589
  var NO_UNNECESSARY_CLASSNAMES = "classnames usage is unnecessary";
590
+ var USESTATE_DECLARATIONS_SHOULD_HAVE_INITIAL_VALUE = '"useState" declarations should have an initial value.';
575
591
 
576
592
  var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
577
593
 
@@ -2070,7 +2086,7 @@
2070
2086
  }
2071
2087
  };
2072
2088
 
2073
- var OBJECT_EXPRESSION_PATTERN = {
2089
+ var OBJECT_EXPRESSION_PATTERN$1 = {
2074
2090
  type: TYPES.OBJECT_EXPRESSION,
2075
2091
  properties: neetoCist.isNotEmpty
2076
2092
  };
@@ -2092,7 +2108,7 @@
2092
2108
  ObjectExpression: function ObjectExpression(node) {
2093
2109
  var _resolveConfig$sync;
2094
2110
  if (isExcludedFile(EXCLUDED_FILES, context.getFilename())) return;
2095
- if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN, node)) return;
2111
+ if (!neetoCist.matches(OBJECT_EXPRESSION_PATTERN$1, node)) return;
2096
2112
  var sourceCode = context.getSourceCode();
2097
2113
  var hasComments = neetoCist.isNotEmpty(sourceCode.getCommentsInside(node));
2098
2114
  if (hasComments) return;
@@ -2338,6 +2354,36 @@
2338
2354
  }
2339
2355
  };
2340
2356
 
2357
+ var USESTATE_WITHOUT_ARGUMENTS_PATTERN = {
2358
+ callee: {
2359
+ type: TYPES.IDENTIFIER,
2360
+ name: "useState"
2361
+ },
2362
+ arguments: ramda.isEmpty
2363
+ };
2364
+
2365
+ var ensureUseStateHasInitialValue = {
2366
+ meta: {
2367
+ type: "problem",
2368
+ docs: {
2369
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/ensure-usestate-has-initial-value.md",
2370
+ description: "useState declarations should have an initial value."
2371
+ }
2372
+ },
2373
+ create: function create(context) {
2374
+ return {
2375
+ CallExpression: function CallExpression(node) {
2376
+ if (neetoCist.matches(USESTATE_WITHOUT_ARGUMENTS_PATTERN, node)) {
2377
+ context.report({
2378
+ node: node,
2379
+ message: USESTATE_DECLARATIONS_SHOULD_HAVE_INITIAL_VALUE
2380
+ });
2381
+ }
2382
+ }
2383
+ };
2384
+ }
2385
+ };
2386
+
2341
2387
  const isWindows = typeof process === 'object' &&
2342
2388
  process &&
2343
2389
  process.platform === 'win32';
@@ -9032,18 +9078,6 @@
9032
9078
  })
9033
9079
  };
9034
9080
 
9035
- // import { functionName } from neetocommons/utils;
9036
- var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
9037
- type: TYPES.IMPORT_DECLARATION,
9038
- source: {
9039
- type: TYPES.LITERAL,
9040
- value: "neetocommons/utils"
9041
- },
9042
- specifiers: [{
9043
- type: TYPES.IMPORT_SPECIFIER
9044
- }]
9045
- };
9046
-
9047
9081
  var createSubscriptionImportPattern = function createSubscriptionImportPattern(functionName) {
9048
9082
  return {
9049
9083
  type: TYPES.IMPORT_DECLARATION,
@@ -9495,6 +9529,77 @@
9495
9529
  }
9496
9530
  };
9497
9531
 
9532
+ var OBJECT_EXPRESSION_PATTERN = {
9533
+ type: TYPES.OBJECT_EXPRESSION,
9534
+ properties: neetoCist.existsBy({
9535
+ key: {
9536
+ name: "icon"
9537
+ },
9538
+ value: {
9539
+ value: "👍"
9540
+ }
9541
+ })
9542
+ };
9543
+
9544
+ // Toastr.success("", { icon: "👍", className: "w-20" });
9545
+ var TOASTR_SUCCESS_THUMBS_UP_PATTERN = {
9546
+ callee: {
9547
+ object: {
9548
+ name: "Toastr"
9549
+ },
9550
+ property: {
9551
+ name: "success"
9552
+ }
9553
+ },
9554
+ arguments: neetoCist.existsBy(OBJECT_EXPRESSION_PATTERN)
9555
+ };
9556
+
9557
+ // const THUMBS_UP = { icon: "👍", className: "w-20" }
9558
+ var THUMBS_UP_OBJECT_DECLARATION = {
9559
+ id: {
9560
+ type: TYPES.IDENTIFIER,
9561
+ name: "THUMBS_UP"
9562
+ },
9563
+ init: OBJECT_EXPRESSION_PATTERN
9564
+ };
9565
+
9566
+ var useShowThumbsUpToastr = {
9567
+ meta: {
9568
+ type: "problem",
9569
+ docs: {
9570
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-show-thumbs-up-toastr.md",
9571
+ description: "Enforces the use of 'showThumbsUpToastr' function for displaying thumbs up toast messages."
9572
+ },
9573
+ fixable: "code"
9574
+ },
9575
+ create: function create(context) {
9576
+ return {
9577
+ CallExpression: function CallExpression(node) {
9578
+ if (!neetoCist.matches(TOASTR_SUCCESS_THUMBS_UP_PATTERN, node)) return;
9579
+ context.report({
9580
+ node: node,
9581
+ message: USE_SHOW_THUMBS_UP_TOASTR_FUNCTION,
9582
+ fix: function fix(fixer) {
9583
+ var fixerArr = [fixer.replaceText(node, "showThumbsUpToastr()")];
9584
+ var addImport = addFunctionImport({
9585
+ context: context,
9586
+ fixer: fixer,
9587
+ functions: ["showThumbsUpToastr"],
9588
+ importPattern: NEETO_COMMONS_UTILS_IMPORT_PATTERN
9589
+ });
9590
+ if (addImport) fixerArr.push(addImport);
9591
+ return fixerArr;
9592
+ }
9593
+ });
9594
+ },
9595
+ VariableDeclarator: function VariableDeclarator(node) {
9596
+ if (!neetoCist.matches(THUMBS_UP_OBJECT_DECLARATION, node)) return;
9597
+ context.report(node, USE_SHOW_THUMBS_UP_TOASTR_FUNCTION);
9598
+ }
9599
+ };
9600
+ }
9601
+ };
9602
+
9498
9603
  var isSnakeCase = function isSnakeCase(text) {
9499
9604
  return SNAKE_CASE_REGEX.test(text);
9500
9605
  };
@@ -10588,7 +10693,9 @@
10588
10693
  "use-common-constants": useCommonConstants,
10589
10694
  "move-spread-attributes-to-top-position": moveSpreadAttributesToTopPosition,
10590
10695
  "prefer-function-reference": preferFunctionReference,
10591
- "jsx-prefer-guard-clause": jsxPreferGuardClause
10696
+ "jsx-prefer-guard-clause": jsxPreferGuardClause,
10697
+ "ensure-usestate-has-initial-value": ensureUseStateHasInitialValue,
10698
+ "use-show-thumbs-up-toastr": useShowThumbsUpToastr
10592
10699
  },
10593
10700
  configs: {
10594
10701
  recommended: recommended,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {