@bigbinary/eslint-plugin-neeto 1.0.63 → 1.0.65

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 +1 -0
  2. package/dist/index.js +277 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -83,6 +83,7 @@ module.exports = {
83
83
  - [use-camel-case-or-pascal-case-for-function-names](./docs/src/rules/use-camel-case-or-pascal-case-for-function-names.md)
84
84
  - [use-common-routes](./docs/src/rules/use-common-routes.md)
85
85
  - [use-components-children-prop-in-trans](./docs/src/rules/use-components-children-prop-in-trans.md)
86
+ - [use-create-subscription-util-function](./docs/src/rules/use-create-subscription-util-function.md)
86
87
  - [use-i18next-plurals](./docs/src/rules/use-i18next-plurals.md)
87
88
  - [use-inline-svg-for-render](./docs/src/rules/use-inline-svg-for-render.md)
88
89
  - [use-neeto-in-strings](./docs/src/rules/use-neeto-in-strings.md)
package/dist/index.js CHANGED
@@ -12,16 +12,16 @@
12
12
  var absolutePath = function absolutePath(jsPath) {
13
13
  return path__default["default"].resolve(__dirname, "../../../..", jsPath);
14
14
  };
15
- var loadJS = function loadJS(jsPath) {
15
+ var loadJS$2 = function loadJS(jsPath) {
16
16
  try {
17
17
  return require(absolutePath(jsPath));
18
18
  } catch (_unused) {
19
19
  return {};
20
20
  }
21
21
  };
22
- var projectResolve = loadJS("config/webpack/resolve.js");
23
- var commonResolve = loadJS("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
24
- var resolve = ramda.mergeDeepLeft(projectResolve, commonResolve);
22
+ var projectResolve$2 = loadJS$2("config/webpack/resolve.js");
23
+ var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
24
+ var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
25
25
  var rules = {
26
26
  "@bigbinary/neeto/api-connector-name-should-match-filename": "error",
27
27
  "@bigbinary/neeto/api-connector-should-use-default-export": "error",
@@ -72,7 +72,7 @@
72
72
  "@bigbinary/neeto/hard-coded-strings-should-be-localized": "warn",
73
73
  "@bigbinary/neeto/minimize-zustand-store-access-scope": "error",
74
74
  "@bigbinary/neeto/neetocommons-tips": "warn",
75
- "@bigbinary/neeto/no-axios-import-outside-apis": ["error", resolve.alias],
75
+ "@bigbinary/neeto/no-axios-import-outside-apis": ["error", resolve$2.alias],
76
76
  "@bigbinary/neeto/no-blacklisted-imports": "warn",
77
77
  "@bigbinary/neeto/no-conditional-overlays": "error",
78
78
  "@bigbinary/neeto/no-deprecated-imports-from-zustand": "error",
@@ -91,7 +91,7 @@
91
91
  "@bigbinary/neeto/no-redundant-string-templates": "error",
92
92
  "@bigbinary/neeto/no-routes-destructure-and-reassignment": "error",
93
93
  "@bigbinary/neeto/no-translation-functions-in-string-interpolation": "error",
94
- "@bigbinary/neeto/prefix-neeto-ui-import-alias": ["error", resolve.alias],
94
+ "@bigbinary/neeto/prefix-neeto-ui-import-alias": ["error", resolve$2.alias],
95
95
  "@bigbinary/neeto/ramda-tips": "warn",
96
96
  "@bigbinary/neeto/routes-should-be-declared-and-default-exported": "error",
97
97
  "@bigbinary/neeto/routes-should-match-object-path": "error",
@@ -100,6 +100,7 @@
100
100
  "@bigbinary/neeto/use-camel-case-or-pascal-case-for-function-names": "error",
101
101
  "@bigbinary/neeto/use-common-routes": "error",
102
102
  "@bigbinary/neeto/use-components-children-prop-in-trans": "error",
103
+ "@bigbinary/neeto/use-create-subscription-util-function": "error",
103
104
  "@bigbinary/neeto/use-i18next-plurals": "error",
104
105
  "@bigbinary/neeto/use-inline-svg-for-render": "error",
105
106
  "@bigbinary/neeto/use-neeto-in-strings": "warn",
@@ -109,7 +110,7 @@
109
110
  "@bigbinary/neeto/use-snake-case-for-api-connector-filename": "error",
110
111
  "@bigbinary/neeto/use-translation-hook-in-components": "error",
111
112
  "@bigbinary/neeto/use-trans-components-and-values-props": "error",
112
- "@bigbinary/neeto/use-webpack-alias": ["error", resolve.alias],
113
+ "@bigbinary/neeto/use-webpack-alias": ["error", resolve$2.alias],
113
114
  "@bigbinary/neeto/use-zustand-for-global-state-management": "error",
114
115
  "@bigbinary/neeto/use-zustand-pick-transformer": "warn",
115
116
  "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": ["error", {
@@ -135,6 +136,100 @@
135
136
  rules: rules
136
137
  };
137
138
 
139
+ var rootOfTheProject$1 = path__default["default"].join(__dirname, "../../../../");
140
+ var pathToTranslationsDir = "src/translations";
141
+ var pathToResolveFile$1 = "resolve.js";
142
+ var pathToJsConfigFile = "jsconfig.json";
143
+ var loadJS$1 = function loadJS(jsPath) {
144
+ try {
145
+ return require(path__default["default"].join(rootOfTheProject$1, jsPath));
146
+ } catch (_unused) {
147
+ return {};
148
+ }
149
+ };
150
+ var commonResolve$1 = loadJS$1("node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/webpack/resolve.js");
151
+ var projectResolve$1 = loadJS$1(pathToResolveFile$1);
152
+ var resolve$1 = ramda.mergeDeepRight(commonResolve$1, projectResolve$1);
153
+ var nanosRecommended = ramda.mergeDeepRight(recommended, {
154
+ rules: {
155
+ "@bigbinary/neeto/file-name-and-export-name-standards": ["warn", {
156
+ basePath: path__default["default"].join(rootOfTheProject$1, "src"),
157
+ "default": {
158
+ filenameCase: "camelCase",
159
+ exportnameCase: "camelCase"
160
+ },
161
+ configs: [{
162
+ filenameCase: "camelCase",
163
+ exportnameCase: "CONSTANT_CASE",
164
+ includes: ["/**/constants.{js,jsx}", "/**/constants/**"]
165
+ }, {
166
+ filenameCase: "camelCase",
167
+ includes: ["/**/utils.{js,jsx}", "/**/utils/**"]
168
+ }, {
169
+ filenameCase: "snake_case",
170
+ exportnameCase: "camelCase",
171
+ includes: "/apis/**"
172
+ }, {
173
+ filenameCase: "camelCase",
174
+ exportnameCase: "camelCase",
175
+ includes: "/channels/**"
176
+ }, {
177
+ filenameCase: "camelCase",
178
+ exportnameCase: "camelCase",
179
+ includes: "/**/hooks/**"
180
+ }, {
181
+ filenameCase: "camelCase",
182
+ includes: "/lib/**"
183
+ }, {
184
+ filenameCase: "camelCase",
185
+ exportnameCase: "camelCase",
186
+ includes: "/**/stores/**"
187
+ }, {
188
+ filenameCase: "PascalCase",
189
+ exportnameCase: "PascalCase",
190
+ includes: ["/components/**", "/*.jsx"]
191
+ }]
192
+ }],
193
+ "@bigbinary/neeto/no-axios-import-outside-apis": ["error", resolve$1.alias],
194
+ "@bigbinary/neeto/no-missing-localization": ["error", {
195
+ translationsDir: path__default["default"].join(rootOfTheProject$1, pathToTranslationsDir),
196
+ languages: ["en"]
197
+ }],
198
+ "@bigbinary/neeto/prefix-neeto-ui-import-alias": ["error", resolve$1.alias],
199
+ "@bigbinary/neeto/use-webpack-alias": ["error", resolve$1.alias],
200
+ "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": ["error", {
201
+ jsconfigFilePath: path__default["default"].join(rootOfTheProject$1, pathToJsConfigFile),
202
+ aliasFilePath: path__default["default"].join(rootOfTheProject$1, pathToResolveFile$1)
203
+ }]
204
+ }
205
+ });
206
+
207
+ var rootOfTheProject = path__default["default"].join(__dirname, "../../../../");
208
+ var pathToResolveFile = "resolve.js";
209
+ var loadJS = function loadJS(jsPath) {
210
+ try {
211
+ return require(path__default["default"].join(rootOfTheProject, jsPath));
212
+ } catch (_unused) {
213
+ return {};
214
+ }
215
+ };
216
+ var commonResolve = loadJS("node_modules/@bigbinary/neeto-commons-frontend/configs/nextjs/webpack/resolve.js");
217
+ var projectResolve = loadJS(pathToResolveFile);
218
+ var resolve = ramda.mergeDeepRight(commonResolve, projectResolve);
219
+ var nextjsRecommended = ramda.mergeDeepRight(recommended, {
220
+ rules: {
221
+ "@bigbinary/neeto/file-name-and-export-name-standards": "off",
222
+ "@bigbinary/neeto/no-axios-import-outside-apis": "off",
223
+ "@bigbinary/neeto/no-missing-localization": "off",
224
+ "@bigbinary/neeto/prefix-neeto-ui-import-alias": ["error", resolve.alias],
225
+ "@bigbinary/neeto/use-react-query-for-managing-remote-data": "off",
226
+ "@bigbinary/neeto/use-webpack-alias": ["error", resolve.alias],
227
+ "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": "off",
228
+ "@bigbinary/neeto/use-neetoui-classes": "off",
229
+ "@bigbinary/neeto/hard-coded-strings-should-be-localized": "off"
230
+ }
231
+ });
232
+
138
233
  function _arrayWithHoles(arr) {
139
234
  if (Array.isArray(arr)) return arr;
140
235
  }
@@ -891,6 +986,9 @@
891
986
  var moveToConstantsJs = function moveToConstantsJs(constantName) {
892
987
  return "Move the constant ".concat(constantName, " to a constants.js file.");
893
988
  };
989
+ var preferSubscriptionUnsubscribe = function preferSubscriptionUnsubscribe(replacerText) {
990
+ return "Prefer to use ".concat(replacerText, ".unsubscribe() to prevent consumer creation boilerplate.");
991
+ };
894
992
  var renameFile = function renameFile(filename) {
895
993
  return "Rename this file to ".concat(filename);
896
994
  };
@@ -940,8 +1038,10 @@
940
1038
  var ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
941
1039
  var ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
942
1040
  var ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
1041
+ var UNNECESSARY_CREATE_CONSUMER = "`createSubscription` function from `neetocommon/utils` invalidates the need of `createConsumer`";
943
1042
  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";
944
1043
  var USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
1044
+ 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";
945
1045
  var USE_INLINE_SVG_FOR_RENDER = "Use inline SVG instead of img tag for rendering SVGs";
946
1046
  var USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
947
1047
  var USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
@@ -7620,6 +7720,172 @@
7620
7720
  }
7621
7721
  };
7622
7722
 
7723
+ // createSubscription();
7724
+ var CUSTOM_CREATE_SUBSCRIPTION_PATTERN = {
7725
+ type: TYPES.CALL_EXPRESSION,
7726
+ callee: {
7727
+ type: TYPES.IDENTIFIER,
7728
+ name: "createSubscription"
7729
+ }
7730
+ };
7731
+
7732
+ // [variableName].subscriptions.create();
7733
+ var SUBSCRIPTION_CREATE_PATTERN = {
7734
+ type: TYPES.CALL_EXPRESSION,
7735
+ callee: {
7736
+ type: TYPES.MEMBER_EXPRESSION,
7737
+ object: {
7738
+ type: TYPES.MEMBER_EXPRESSION,
7739
+ property: {
7740
+ type: TYPES.IDENTIFIER,
7741
+ name: "subscriptions"
7742
+ }
7743
+ },
7744
+ property: {
7745
+ type: TYPES.IDENTIFIER,
7746
+ name: "create"
7747
+ }
7748
+ }
7749
+ };
7750
+
7751
+ // [variableName].subscriptions.remove(subscriptionObject);
7752
+ var SUBSCRIPTION_REMOVE_PATTERN = {
7753
+ type: TYPES.CALL_EXPRESSION,
7754
+ callee: {
7755
+ type: TYPES.MEMBER_EXPRESSION,
7756
+ object: {
7757
+ type: TYPES.MEMBER_EXPRESSION,
7758
+ property: {
7759
+ type: TYPES.IDENTIFIER,
7760
+ name: "subscriptions"
7761
+ }
7762
+ },
7763
+ property: {
7764
+ type: TYPES.IDENTIFIER,
7765
+ name: "remove"
7766
+ }
7767
+ }
7768
+ };
7769
+
7770
+ // import { createConsumer } from "@rails/actioncable";
7771
+ var CREATE_CONSUMER_IMPORT_PATTERN = {
7772
+ type: TYPES.IMPORT_DECLARATION,
7773
+ source: {
7774
+ type: TYPES.LITERAL,
7775
+ value: "@rails/actioncable"
7776
+ },
7777
+ specifiers: pure.existsBy({
7778
+ type: TYPES.IMPORT_SPECIFIER,
7779
+ imported: {
7780
+ type: TYPES.IDENTIFIER,
7781
+ name: "createConsumer"
7782
+ }
7783
+ })
7784
+ };
7785
+
7786
+ // import { functionName } from neetocommons/utils;
7787
+ var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
7788
+ type: TYPES.IMPORT_DECLARATION,
7789
+ source: {
7790
+ type: TYPES.LITERAL,
7791
+ value: "neetocommons/utils"
7792
+ },
7793
+ specifiers: [{
7794
+ type: TYPES.IMPORT_SPECIFIER
7795
+ }]
7796
+ };
7797
+
7798
+ var createSubscriptionImportPattern = function createSubscriptionImportPattern(functionName) {
7799
+ return {
7800
+ type: TYPES.IMPORT_DECLARATION,
7801
+ source: {
7802
+ type: TYPES.LITERAL,
7803
+ value: pure.isNot("neetocommons/utils")
7804
+ },
7805
+ specifiers: ramda.any(matchesAny([{
7806
+ type: TYPES.IMPORT_DEFAULT_SPECIFIER,
7807
+ local: {
7808
+ type: TYPES.IDENTIFIER,
7809
+ name: functionName
7810
+ }
7811
+ }, {
7812
+ type: TYPES.IMPORT_SPECIFIER,
7813
+ local: {
7814
+ type: TYPES.IDENTIFIER,
7815
+ name: functionName
7816
+ }
7817
+ }]))
7818
+ };
7819
+ };
7820
+ var importExists = function importExists(context, functionName) {
7821
+ var ast = context.getSourceCode().ast;
7822
+ return pure.existsBy(createSubscriptionImportPattern(functionName), ast.body);
7823
+ };
7824
+
7825
+ var useCreateSubscriptionUtilFunction = {
7826
+ meta: {
7827
+ type: "problem",
7828
+ docs: {
7829
+ url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-create-subscription-util-function.md",
7830
+ description: "Suggests the use of createSubscription function rather than a custom implementation to create a channel"
7831
+ },
7832
+ fixable: "code"
7833
+ },
7834
+ create: function create(context) {
7835
+ var createSubscriptionImportExists = importExists(context, "createSubscription");
7836
+ return {
7837
+ CallExpression: function CallExpression(node) {
7838
+ if (createSubscriptionImportExists && pure.matches(CUSTOM_CREATE_SUBSCRIPTION_PATTERN, node)) {
7839
+ return context.report({
7840
+ node: node.callee,
7841
+ message: USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS
7842
+ });
7843
+ }
7844
+ if (pure.matches(SUBSCRIPTION_CREATE_PATTERN, node)) {
7845
+ return context.report({
7846
+ node: node.callee,
7847
+ fix: function fix(fixer) {
7848
+ var fixerArray = [fixer.replaceTextRange(node.callee.range.splice(0, 2), "createSubscription")];
7849
+ var addedImport = addFunctionImport({
7850
+ context: context,
7851
+ fixer: fixer,
7852
+ functions: ["createSubscription"],
7853
+ importPattern: NEETO_COMMONS_UTILS_IMPORT_PATTERN
7854
+ });
7855
+ if (addedImport) fixerArray.push(addedImport);
7856
+ return fixerArray;
7857
+ },
7858
+ message: USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS
7859
+ });
7860
+ }
7861
+ if (pure.matches(SUBSCRIPTION_REMOVE_PATTERN, node)) {
7862
+ var replacerText = context.getSourceCode().getText(node.arguments[0]);
7863
+ var replacerRange = node.range.splice(0, 2);
7864
+ return context.report({
7865
+ node: node.callee,
7866
+ fix: function fix(fixer) {
7867
+ return fixer.replaceTextRange(replacerRange, "".concat(replacerText, ".unsubscribe()"));
7868
+ },
7869
+ message: preferSubscriptionUnsubscribe(replacerText)
7870
+ });
7871
+ }
7872
+ return undefined;
7873
+ },
7874
+ ImportDeclaration: function ImportDeclaration(node) {
7875
+ if (!pure.matches(CREATE_CONSUMER_IMPORT_PATTERN, node)) return;
7876
+ context.report({
7877
+ node: pure.findBy({
7878
+ imported: {
7879
+ name: "createConsumer"
7880
+ }
7881
+ }, node.specifiers),
7882
+ message: UNNECESSARY_CREATE_CONSUMER
7883
+ });
7884
+ }
7885
+ };
7886
+ }
7887
+ };
7888
+
7623
7889
  const defaultOpts$2 = {
7624
7890
  xml: false,
7625
7891
  decodeEntities: true,
@@ -25740,6 +26006,7 @@
25740
26006
  "use-camel-case-or-pascal-case-for-function-names": useCamelCaseOrPascalCaseForFunctionNames,
25741
26007
  "use-common-routes": useCommonRoutes,
25742
26008
  "use-components-children-prop-in-trans": useComponentsChildrenPropInTrans,
26009
+ "use-create-subscription-util-function": useCreateSubscriptionUtilFunction,
25743
26010
  "use-i18next-plurals": useI18nextPlurals,
25744
26011
  "use-inline-svg-for-render": useInlineSvgForRender,
25745
26012
  "use-neeto-in-strings": useNeetoInStrings,
@@ -25764,7 +26031,9 @@
25764
26031
  "zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate
25765
26032
  },
25766
26033
  configs: {
25767
- recommended: recommended
26034
+ recommended: recommended,
26035
+ "nextjs-recommended": nextjsRecommended,
26036
+ "nanos-recommended": nanosRecommended
25768
26037
  }
25769
26038
  };
25770
26039
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {