@bigbinary/eslint-plugin-neeto 1.1.9 → 1.1.10

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 +185 -27
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -81,6 +81,7 @@ module.exports = {
81
81
  - [use-array-methods](./docs/src/rules/use-array-methods.md)
82
82
  - [use-axios-config-for-passing-query-parameters](./docs/src/rules/use-axios-config-for-passing-query-parameters.md)
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
+ - [use-common-constants](./docs/src/rules/use-common-constants.md)
84
85
  - [use-common-routes](./docs/src/rules/use-common-routes.md)
85
86
  - [use-components-children-prop-in-trans](./docs/src/rules/use-components-children-prop-in-trans.md)
86
87
  - [use-create-subscription-util-function](./docs/src/rules/use-create-subscription-util-function.md)
package/dist/index.js CHANGED
@@ -1,13 +1,32 @@
1
1
  (function (global, factory) {
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';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda'), require('@bigbinary/neeto-commons-frontend/pure'), require('fs'), require('@bigbinary/neeto-commons-frontend/constants')) :
3
+ typeof define === 'function' && define.amd ? define(['path', 'ramda', '@bigbinary/neeto-commons-frontend/pure', 'fs', '@bigbinary/neeto-commons-frontend/constants'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path$2, global.ramda, global.pure, global.fs, global.neetoCommonsConstants));
5
+ })(this, (function (path$2, ramda, pure, fs, neetoCommonsConstants) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
9
27
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path$2);
10
28
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
29
+ var neetoCommonsConstants__namespace = /*#__PURE__*/_interopNamespace(neetoCommonsConstants);
11
30
 
12
31
  var absolutePath = function absolutePath(jsPath) {
13
32
  return path__default["default"].resolve(__dirname, "../../../..", jsPath);
@@ -127,7 +146,8 @@
127
146
  "@bigbinary/neeto/no-repetition-in-prop-key-value-names": "error",
128
147
  "@bigbinary/neeto/merge-spread-attributes": "error",
129
148
  "@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
130
- "@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error"
149
+ "@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
150
+ "@bigbinary/neeto/use-common-constants": "warn"
131
151
  };
132
152
 
133
153
  var recommended = {
@@ -439,6 +459,9 @@
439
459
  var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
440
460
  return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
441
461
  };
462
+ var suggestCommonConstants = function suggestCommonConstants(constantName, repository) {
463
+ return "Use \"".concat(constantName, "\" from \"@bigbinary/").concat(repository, "/constants\"");
464
+ };
442
465
  var addRequiredPeerDependencies$1 = function addRequiredPeerDependencies(packageName) {
443
466
  return "".concat(packageName, " should be added to peerDependencies");
444
467
  };
@@ -1252,7 +1275,7 @@
1252
1275
  }
1253
1276
  };
1254
1277
 
1255
- var checkAndReport$5 = function checkAndReport(context, node) {
1278
+ var checkAndReport$6 = function checkAndReport(context, node) {
1256
1279
  if (!isInsideApisDirectory(context)) return;
1257
1280
  context.report({
1258
1281
  node: node,
@@ -1270,11 +1293,11 @@
1270
1293
  create: function create(context) {
1271
1294
  return {
1272
1295
  ExportNamedDeclaration: function ExportNamedDeclaration(node) {
1273
- checkAndReport$5(context, node);
1296
+ checkAndReport$6(context, node);
1274
1297
  },
1275
1298
  ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
1276
1299
  if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
1277
- checkAndReport$5(context, node);
1300
+ checkAndReport$6(context, node);
1278
1301
  }
1279
1302
  };
1280
1303
  }
@@ -1376,7 +1399,7 @@
1376
1399
  }
1377
1400
  });
1378
1401
  };
1379
- var checkAndReport$4 = function checkAndReport(context, node) {
1402
+ var checkAndReport$5 = function checkAndReport(context, node) {
1380
1403
  if (!node.async) return;
1381
1404
  var subsequentAwaits = getIndependentAwaits(node);
1382
1405
  if (subsequentAwaits.length === 0) return;
@@ -1397,15 +1420,15 @@
1397
1420
  return {
1398
1421
  // const sum = (a, b) => a + b;
1399
1422
  ArrowFunctionExpression: function ArrowFunctionExpression(node) {
1400
- checkAndReport$4(context, node);
1423
+ checkAndReport$5(context, node);
1401
1424
  },
1402
1425
  // const sum = function (a, b) { return a + b };
1403
1426
  FunctionExpression: function FunctionExpression(node) {
1404
- checkAndReport$4(context, node);
1427
+ checkAndReport$5(context, node);
1405
1428
  },
1406
1429
  // function sum (a, b) { return a + b };
1407
1430
  FunctionDeclaration: function FunctionDeclaration(node) {
1408
- checkAndReport$4(context, node);
1431
+ checkAndReport$5(context, node);
1409
1432
  }
1410
1433
  };
1411
1434
  }
@@ -3988,7 +4011,7 @@
3988
4011
  }
3989
4012
  return false;
3990
4013
  };
3991
- var checkAndReport$3 = function checkAndReport(node, context) {
4014
+ var checkAndReport$4 = function checkAndReport(node, context) {
3992
4015
  var nodeValue = node.type === TYPES.TEMPLATE_ELEMENT ? node.value.raw : node.value;
3993
4016
  if (!shouldReport(node, nodeValue, context)) return;
3994
4017
  context.report({
@@ -4007,13 +4030,13 @@
4007
4030
  create: function create(context) {
4008
4031
  return {
4009
4032
  Literal: function Literal(node) {
4010
- checkAndReport$3(node, context);
4033
+ checkAndReport$4(node, context);
4011
4034
  },
4012
4035
  TemplateLiteral: function TemplateLiteral(node) {
4013
- checkAndReport$3(node, context);
4036
+ checkAndReport$4(node, context);
4014
4037
  },
4015
4038
  JSXText: function JSXText(node) {
4016
- checkAndReport$3(node, context);
4039
+ checkAndReport$4(node, context);
4017
4040
  }
4018
4041
  };
4019
4042
  }
@@ -4131,7 +4154,7 @@
4131
4154
  }, ramda.assoc("content", _objectSpread$3(_objectSpread$3({}, parseJsonData(path$2.join(translationsDirPath, changedFileName))), nanosContent[lng])), translationFiles);
4132
4155
  });
4133
4156
  };
4134
- var checkAndReport$2 = function checkAndReport(_ref) {
4157
+ var checkAndReport$3 = function checkAndReport(_ref) {
4135
4158
  var _config$context, _config$count;
4136
4159
  var context = _ref.context,
4137
4160
  node = _ref.node,
@@ -4214,7 +4237,7 @@
4214
4237
  config.count = getObjectPropValue(node.arguments[1], "count");
4215
4238
  config.context = getObjectPropValue(node.arguments[1], "context");
4216
4239
  }
4217
- checkAndReport$2({
4240
+ checkAndReport$3({
4218
4241
  key: node.arguments[0].value,
4219
4242
  context: context,
4220
4243
  node: node,
@@ -4232,7 +4255,7 @@
4232
4255
  count: getCountNode(node),
4233
4256
  context: contextAttribute === null || contextAttribute === void 0 ? void 0 : contextAttribute.value
4234
4257
  };
4235
- checkAndReport$2({
4258
+ checkAndReport$3({
4236
4259
  key: keyNode.value,
4237
4260
  context: context,
4238
4261
  node: node,
@@ -5881,7 +5904,7 @@
5881
5904
  return getCode$1(context, param);
5882
5905
  }).join(", ");
5883
5906
  };
5884
- var checkAndReport$1 = function checkAndReport(context, params) {
5907
+ var checkAndReport$2 = function checkAndReport(context, params) {
5885
5908
  var isApiAction = isInsideApisDirectory(context);
5886
5909
  if (!containsExcessArguments(params, isApiAction)) return;
5887
5910
  var loc = {
@@ -5913,15 +5936,15 @@
5913
5936
  return {
5914
5937
  // const sum = (a, b) => a + b;
5915
5938
  ArrowFunctionExpression: function ArrowFunctionExpression(node) {
5916
- checkAndReport$1(context, node.params);
5939
+ checkAndReport$2(context, node.params);
5917
5940
  },
5918
5941
  // const sum = function (a, b) { return a + b };
5919
5942
  FunctionExpression: function FunctionExpression(node) {
5920
- checkAndReport$1(context, node.params);
5943
+ checkAndReport$2(context, node.params);
5921
5944
  },
5922
5945
  // function sum (a, b) { return a + b };
5923
5946
  FunctionDeclaration: function FunctionDeclaration(node) {
5924
- checkAndReport$1(context, node.params);
5947
+ checkAndReport$2(context, node.params);
5925
5948
  }
5926
5949
  };
5927
5950
  }
@@ -7845,7 +7868,7 @@
7845
7868
  return key.name === name;
7846
7869
  })) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
7847
7870
  };
7848
- var checkAndReport = function checkAndReport(_ref6) {
7871
+ var checkAndReport$1 = function checkAndReport(_ref6) {
7849
7872
  var context = _ref6.context,
7850
7873
  node = _ref6.node,
7851
7874
  urlNode = _ref6.urlNode;
@@ -7882,7 +7905,7 @@
7882
7905
  return {
7883
7906
  CallExpression: function CallExpression(node) {
7884
7907
  if (pure.matches(AXIOS_GET_PATTERN, node)) {
7885
- checkAndReport({
7908
+ checkAndReport$1({
7886
7909
  context: context,
7887
7910
  node: node,
7888
7911
  urlNode: node.arguments[0]
@@ -7900,7 +7923,7 @@
7900
7923
  methodNode = getPropValue(node.arguments[1], "method");
7901
7924
  }
7902
7925
  if (((_methodNode = methodNode) === null || _methodNode === void 0 ? void 0 : _methodNode.value.toLowerCase()) !== "get") return;
7903
- checkAndReport({
7926
+ checkAndReport$1({
7904
7927
  context: context,
7905
7928
  node: node,
7906
7929
  urlNode: urlNode
@@ -7963,6 +7986,140 @@
7963
7986
  }
7964
7987
  };
7965
7988
 
7989
+ var IMPORT_SOURCES = {
7990
+ "neeto-commons-frontend": "neetocommons/constants",
7991
+ "neeto-team-members-frontend": "neetoteam/constants"
7992
+ };
7993
+ var TRANSLATION_VERBS_PATTERN = {
7994
+ type: TYPES.OBJECT_EXPRESSION,
7995
+ properties: [{
7996
+ type: TYPES.PROPERTY,
7997
+ key: {
7998
+ type: TYPES.IDENTIFIER,
7999
+ name: "count"
8000
+ },
8001
+ value: {
8002
+ type: TYPES.LITERAL,
8003
+ value: function value(_value) {
8004
+ return ramda.includes(_value, [1, 2]);
8005
+ }
8006
+ }
8007
+ }]
8008
+ };
8009
+ var constantImportPattern = function constantImportPattern(constantName, repository) {
8010
+ return {
8011
+ specifiers: function specifiers(_specifiers) {
8012
+ return pure.findBy(pure.matches({
8013
+ type: TYPES.IMPORT_SPECIFIER,
8014
+ local: {
8015
+ type: TYPES.IDENTIFIER,
8016
+ name: constantName
8017
+ }
8018
+ }), _specifiers);
8019
+ },
8020
+ source: {
8021
+ type: TYPES.LITERAL,
8022
+ value: IMPORT_SOURCES[repository]
8023
+ }
8024
+ };
8025
+ };
8026
+ var NEETO_TEAM_MEMBERS_CONSTANTS = {
8027
+ MANAGE_MEMBERS_PERMISSION: "members.manage_members",
8028
+ MANAGE_ROLES_PERMISSION: "settings.manage_roles",
8029
+ VIEW_MEMBERS_PERMISSION: "members.view_members",
8030
+ VIEW_ROLES_PERMISSION: "settings.view_roles"
8031
+ };
8032
+
8033
+ var getKeyByValue = function getKeyByValue(object, targetValue) {
8034
+ return Object.keys(object).find(function (key) {
8035
+ return object[key] === targetValue;
8036
+ });
8037
+ };
8038
+ var reportIssue = function reportIssue(_ref) {
8039
+ var node = _ref.node,
8040
+ repository = _ref.repository,
8041
+ context = _ref.context,
8042
+ constantName = _ref.constantName;
8043
+ context.report({
8044
+ node: node,
8045
+ message: suggestCommonConstants(constantName, repository)
8046
+ });
8047
+ };
8048
+ var checkAndReport = function checkAndReport(_ref2) {
8049
+ var _parentNode$init;
8050
+ var node = _ref2.node,
8051
+ constants = _ref2.constants,
8052
+ repository = _ref2.repository,
8053
+ context = _ref2.context;
8054
+ var nodeName = node.name;
8055
+ var parentNode = node.parent;
8056
+ var parentNodeValue = (_parentNode$init = parentNode.init) === null || _parentNode$init === void 0 ? void 0 : _parentNode$init.value;
8057
+ if (Object.prototype.hasOwnProperty.call(constants, nodeName) && (parentNode.type === TYPES.VARIABLE_DECLARATOR && constants[nodeName] === parentNodeValue || parentNode.type !== TYPES.IMPORT_SPECIFIER && !pure.existsBy(constantImportPattern(nodeName, repository), getAllImports(node)))) {
8058
+ reportIssue({
8059
+ node: node,
8060
+ repository: repository,
8061
+ context: context,
8062
+ constantName: nodeName
8063
+ });
8064
+ } else if (parentNode.type === TYPES.VARIABLE_DECLARATOR && !Number.isInteger(parentNodeValue)) {
8065
+ var key = getKeyByValue(constants, parentNodeValue);
8066
+ if (key) {
8067
+ reportIssue({
8068
+ node: node,
8069
+ repository: repository,
8070
+ context: context,
8071
+ constantName: key
8072
+ });
8073
+ }
8074
+ }
8075
+ };
8076
+ var checkTranslationVerbs = function checkTranslationVerbs(node, context) {
8077
+ var _parentNode$callee;
8078
+ var parentNode = node.parent;
8079
+ var repository = "neeto-commons-frontend";
8080
+ var isCommonConstant = parentNode.type === TYPES.VARIABLE_DECLARATOR ? pure.matches(TRANSLATION_VERBS_PATTERN, parentNode.init) : ((_parentNode$callee = parentNode.callee) === null || _parentNode$callee === void 0 ? void 0 : _parentNode$callee.name) === "t" && !pure.existsBy(constantImportPattern(node.name, repository), getAllImports(node));
8081
+ if (isCommonConstant) {
8082
+ reportIssue({
8083
+ node: node,
8084
+ repository: repository,
8085
+ context: context,
8086
+ constantName: "TRANSLATION_".concat(node.name)
8087
+ });
8088
+ }
8089
+ };
8090
+
8091
+ var useCommonConstants = {
8092
+ meta: {
8093
+ type: "suggestion",
8094
+ docs: {
8095
+ url: "",
8096
+ description: "Suggests using common constants from neeto-team-members and neeto-commons-frontend repos"
8097
+ }
8098
+ },
8099
+ create: function create(context) {
8100
+ return {
8101
+ Identifier: function Identifier(node) {
8102
+ var nodeName = node.name;
8103
+ if (nodeName === "SINGULAR" || nodeName === "PLURAL") {
8104
+ checkTranslationVerbs(node, context);
8105
+ }
8106
+ checkAndReport({
8107
+ node: node,
8108
+ constants: neetoCommonsConstants__namespace,
8109
+ repository: "neeto-commons-frontend",
8110
+ context: context
8111
+ });
8112
+ checkAndReport({
8113
+ node: node,
8114
+ constants: NEETO_TEAM_MEMBERS_CONSTANTS,
8115
+ repository: "neeto-team-members-frontend",
8116
+ context: context
8117
+ });
8118
+ }
8119
+ };
8120
+ }
8121
+ };
8122
+
7966
8123
  // createSubscription();
7967
8124
  var CUSTOM_CREATE_SUBSCRIPTION_PATTERN = {
7968
8125
  type: TYPES.CALL_EXPRESSION,
@@ -26330,7 +26487,8 @@
26330
26487
  "use-functions-and-hooks-from-neeto-commons-frontend": useFunctionsAndHooksFromNeetoCommonsFrontend,
26331
26488
  "no-unnecessary-if-condition": noUnnecessaryIfCondition,
26332
26489
  "zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
26333
- "add-required-peer-dependencies": addRequiredPeerDependencies
26490
+ "add-required-peer-dependencies": addRequiredPeerDependencies,
26491
+ "use-common-constants": useCommonConstants
26334
26492
  },
26335
26493
  configs: {
26336
26494
  recommended: recommended,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/eslint-plugin-neeto",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "main": "dist/index.js",
5
5
  "license": "UNLICENSED",
6
6
  "scripts": {
@@ -35,8 +35,8 @@
35
35
  "@babel/preset-typescript": "^7.18.6",
36
36
  "@babel/runtime": "^7.19.0",
37
37
  "@bigbinary/babel-preset-neeto": "^1.0.3",
38
- "@bigbinary/eslint-plugin-neeto": "^1.0.21",
39
- "@bigbinary/neeto-commons-frontend": "^2.0.92",
38
+ "@bigbinary/eslint-plugin-neeto": "^1.1.9",
39
+ "@bigbinary/neeto-commons-frontend": "^2.0.114",
40
40
  "@rollup/plugin-alias": "^3.1.9",
41
41
  "@rollup/plugin-babel": "^5.3.1",
42
42
  "@rollup/plugin-commonjs": "^22.0.0",