@bigbinary/eslint-plugin-neeto 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.js +295 -27
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ module.exports = {
|
|
|
46
46
|
|
|
47
47
|
## Exported rules
|
|
48
48
|
|
|
49
|
+
- [no-dumb-components-with-use-translation](./docs/src/rules/no-dumb-components-with-use-translation.md)
|
|
50
|
+
- [no-unnecessary-if-condition](./docs/src/rules/no-unnecessary-if-condition.md)
|
|
49
51
|
- [api-connector-name-should-match-filename](./docs/src/rules/api-connector-name-should-match-filename.md)
|
|
50
52
|
- [api-connector-should-use-default-export](./docs/src/rules/api-connector-should-use-default-export.md)
|
|
51
53
|
- [combine-multiple-independent-awaits](./docs/src/rules/combine-multiple-independent-awaits.md)
|
|
@@ -81,6 +83,7 @@ module.exports = {
|
|
|
81
83
|
- [use-array-methods](./docs/src/rules/use-array-methods.md)
|
|
82
84
|
- [use-axios-config-for-passing-query-parameters](./docs/src/rules/use-axios-config-for-passing-query-parameters.md)
|
|
83
85
|
- [use-camel-case-or-pascal-case-for-function-names](./docs/src/rules/use-camel-case-or-pascal-case-for-function-names.md)
|
|
86
|
+
- [use-common-constants](./docs/src/rules/use-common-constants.md)
|
|
84
87
|
- [use-common-routes](./docs/src/rules/use-common-routes.md)
|
|
85
88
|
- [use-components-children-prop-in-trans](./docs/src/rules/use-components-children-prop-in-trans.md)
|
|
86
89
|
- [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);
|
|
@@ -23,6 +42,7 @@
|
|
|
23
42
|
var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
|
|
24
43
|
var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
|
|
25
44
|
var rules = {
|
|
45
|
+
"@bigbinary/neeto/no-dumb-components-with-use-translation": "error",
|
|
26
46
|
"@bigbinary/neeto/api-connector-name-should-match-filename": "error",
|
|
27
47
|
"@bigbinary/neeto/api-connector-should-use-default-export": "error",
|
|
28
48
|
"@bigbinary/neeto/combine-multiple-independent-awaits": "warn",
|
|
@@ -127,7 +147,8 @@
|
|
|
127
147
|
"@bigbinary/neeto/no-repetition-in-prop-key-value-names": "error",
|
|
128
148
|
"@bigbinary/neeto/merge-spread-attributes": "error",
|
|
129
149
|
"@bigbinary/neeto/props-inside-spread-attributes-should-be-sorted": "error",
|
|
130
|
-
"@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error"
|
|
150
|
+
"@bigbinary/neeto/props-with-different-key-value-should-be-outside-spread-attribute": "error",
|
|
151
|
+
"@bigbinary/neeto/use-common-constants": "warn"
|
|
131
152
|
};
|
|
132
153
|
|
|
133
154
|
var recommended = {
|
|
@@ -439,6 +460,9 @@
|
|
|
439
460
|
var suggestNeetoCommonsFunctionsAndHooks = function suggestNeetoCommonsFunctionsAndHooks(functionName, utilType, url) {
|
|
440
461
|
return "Use \"".concat(functionName, "\" from \"@bigbinary/neeto-commons-frontend/").concat(utilType, "\" instead. Refer: ").concat(url);
|
|
441
462
|
};
|
|
463
|
+
var suggestCommonConstants = function suggestCommonConstants(constantName, repository) {
|
|
464
|
+
return "Use \"".concat(constantName, "\" from \"@bigbinary/").concat(repository, "/constants\"");
|
|
465
|
+
};
|
|
442
466
|
var addRequiredPeerDependencies$1 = function addRequiredPeerDependencies(packageName) {
|
|
443
467
|
return "".concat(packageName, " should be added to peerDependencies");
|
|
444
468
|
};
|
|
@@ -1252,7 +1276,7 @@
|
|
|
1252
1276
|
}
|
|
1253
1277
|
};
|
|
1254
1278
|
|
|
1255
|
-
var checkAndReport$
|
|
1279
|
+
var checkAndReport$6 = function checkAndReport(context, node) {
|
|
1256
1280
|
if (!isInsideApisDirectory(context)) return;
|
|
1257
1281
|
context.report({
|
|
1258
1282
|
node: node,
|
|
@@ -1270,11 +1294,11 @@
|
|
|
1270
1294
|
create: function create(context) {
|
|
1271
1295
|
return {
|
|
1272
1296
|
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
1273
|
-
checkAndReport$
|
|
1297
|
+
checkAndReport$6(context, node);
|
|
1274
1298
|
},
|
|
1275
1299
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
|
1276
1300
|
if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
|
|
1277
|
-
checkAndReport$
|
|
1301
|
+
checkAndReport$6(context, node);
|
|
1278
1302
|
}
|
|
1279
1303
|
};
|
|
1280
1304
|
}
|
|
@@ -1376,7 +1400,7 @@
|
|
|
1376
1400
|
}
|
|
1377
1401
|
});
|
|
1378
1402
|
};
|
|
1379
|
-
var checkAndReport$
|
|
1403
|
+
var checkAndReport$5 = function checkAndReport(context, node) {
|
|
1380
1404
|
if (!node.async) return;
|
|
1381
1405
|
var subsequentAwaits = getIndependentAwaits(node);
|
|
1382
1406
|
if (subsequentAwaits.length === 0) return;
|
|
@@ -1397,15 +1421,15 @@
|
|
|
1397
1421
|
return {
|
|
1398
1422
|
// const sum = (a, b) => a + b;
|
|
1399
1423
|
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
1400
|
-
checkAndReport$
|
|
1424
|
+
checkAndReport$5(context, node);
|
|
1401
1425
|
},
|
|
1402
1426
|
// const sum = function (a, b) { return a + b };
|
|
1403
1427
|
FunctionExpression: function FunctionExpression(node) {
|
|
1404
|
-
checkAndReport$
|
|
1428
|
+
checkAndReport$5(context, node);
|
|
1405
1429
|
},
|
|
1406
1430
|
// function sum (a, b) { return a + b };
|
|
1407
1431
|
FunctionDeclaration: function FunctionDeclaration(node) {
|
|
1408
|
-
checkAndReport$
|
|
1432
|
+
checkAndReport$5(context, node);
|
|
1409
1433
|
}
|
|
1410
1434
|
};
|
|
1411
1435
|
}
|
|
@@ -3988,7 +4012,7 @@
|
|
|
3988
4012
|
}
|
|
3989
4013
|
return false;
|
|
3990
4014
|
};
|
|
3991
|
-
var checkAndReport$
|
|
4015
|
+
var checkAndReport$4 = function checkAndReport(node, context) {
|
|
3992
4016
|
var nodeValue = node.type === TYPES.TEMPLATE_ELEMENT ? node.value.raw : node.value;
|
|
3993
4017
|
if (!shouldReport(node, nodeValue, context)) return;
|
|
3994
4018
|
context.report({
|
|
@@ -4007,13 +4031,13 @@
|
|
|
4007
4031
|
create: function create(context) {
|
|
4008
4032
|
return {
|
|
4009
4033
|
Literal: function Literal(node) {
|
|
4010
|
-
checkAndReport$
|
|
4034
|
+
checkAndReport$4(node, context);
|
|
4011
4035
|
},
|
|
4012
4036
|
TemplateLiteral: function TemplateLiteral(node) {
|
|
4013
|
-
checkAndReport$
|
|
4037
|
+
checkAndReport$4(node, context);
|
|
4014
4038
|
},
|
|
4015
4039
|
JSXText: function JSXText(node) {
|
|
4016
|
-
checkAndReport$
|
|
4040
|
+
checkAndReport$4(node, context);
|
|
4017
4041
|
}
|
|
4018
4042
|
};
|
|
4019
4043
|
}
|
|
@@ -4131,7 +4155,7 @@
|
|
|
4131
4155
|
}, ramda.assoc("content", _objectSpread$3(_objectSpread$3({}, parseJsonData(path$2.join(translationsDirPath, changedFileName))), nanosContent[lng])), translationFiles);
|
|
4132
4156
|
});
|
|
4133
4157
|
};
|
|
4134
|
-
var checkAndReport$
|
|
4158
|
+
var checkAndReport$3 = function checkAndReport(_ref) {
|
|
4135
4159
|
var _config$context, _config$count;
|
|
4136
4160
|
var context = _ref.context,
|
|
4137
4161
|
node = _ref.node,
|
|
@@ -4214,7 +4238,7 @@
|
|
|
4214
4238
|
config.count = getObjectPropValue(node.arguments[1], "count");
|
|
4215
4239
|
config.context = getObjectPropValue(node.arguments[1], "context");
|
|
4216
4240
|
}
|
|
4217
|
-
checkAndReport$
|
|
4241
|
+
checkAndReport$3({
|
|
4218
4242
|
key: node.arguments[0].value,
|
|
4219
4243
|
context: context,
|
|
4220
4244
|
node: node,
|
|
@@ -4232,7 +4256,7 @@
|
|
|
4232
4256
|
count: getCountNode(node),
|
|
4233
4257
|
context: contextAttribute === null || contextAttribute === void 0 ? void 0 : contextAttribute.value
|
|
4234
4258
|
};
|
|
4235
|
-
checkAndReport$
|
|
4259
|
+
checkAndReport$3({
|
|
4236
4260
|
key: keyNode.value,
|
|
4237
4261
|
context: context,
|
|
4238
4262
|
node: node,
|
|
@@ -5868,6 +5892,114 @@
|
|
|
5868
5892
|
}
|
|
5869
5893
|
};
|
|
5870
5894
|
|
|
5895
|
+
function _toArray(arr) {
|
|
5896
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableRest();
|
|
5897
|
+
}
|
|
5898
|
+
|
|
5899
|
+
var REACT_HOOKS_VARIABLE_DECLARATION_PATTERN = {
|
|
5900
|
+
type: TYPES.VARIABLE_DECLARATION,
|
|
5901
|
+
declarations: [{
|
|
5902
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
5903
|
+
init: {
|
|
5904
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5905
|
+
callee: {
|
|
5906
|
+
type: TYPES.IDENTIFIER,
|
|
5907
|
+
name: ramda.test(/use[a-zA-z0-9].+/)
|
|
5908
|
+
}
|
|
5909
|
+
}
|
|
5910
|
+
}]
|
|
5911
|
+
};
|
|
5912
|
+
var REACT_HOOKS_CALL_PATTERN = {
|
|
5913
|
+
type: TYPES.EXPRESSION_STATEMENT,
|
|
5914
|
+
expression: {
|
|
5915
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5916
|
+
callee: {
|
|
5917
|
+
type: TYPES.IDENTIFIER,
|
|
5918
|
+
name: ramda.test(/use[a-zA-z0-9].+/)
|
|
5919
|
+
}
|
|
5920
|
+
}
|
|
5921
|
+
};
|
|
5922
|
+
|
|
5923
|
+
// import { functionName } from "neetocommons/react-utils";
|
|
5924
|
+
var NEETO_COMMONS_REACT_UTILS_IMPORT_PATTERN = {
|
|
5925
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
5926
|
+
source: {
|
|
5927
|
+
type: TYPES.LITERAL,
|
|
5928
|
+
value: "neetocommons/react-utils"
|
|
5929
|
+
},
|
|
5930
|
+
specifiers: [{
|
|
5931
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
5932
|
+
}]
|
|
5933
|
+
};
|
|
5934
|
+
|
|
5935
|
+
var noDumbComponentsWithUseTranslation = {
|
|
5936
|
+
meta: {
|
|
5937
|
+
type: "suggestion",
|
|
5938
|
+
docs: {
|
|
5939
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/no-dumb-components-with-use-translation.md",
|
|
5940
|
+
description: "Disallows creating dumb components with useTranslation hook"
|
|
5941
|
+
},
|
|
5942
|
+
fixable: "code"
|
|
5943
|
+
},
|
|
5944
|
+
create: function create(context) {
|
|
5945
|
+
return {
|
|
5946
|
+
VariableDeclaration: function VariableDeclaration(node) {
|
|
5947
|
+
if (!pure.matches(COMPONENT_PATTERN, node)) return;
|
|
5948
|
+
var _node$declarations = _slicedToArray(node.declarations, 1),
|
|
5949
|
+
arrowFunctionExpression = _node$declarations[0].init;
|
|
5950
|
+
var blockStatement = arrowFunctionExpression.body;
|
|
5951
|
+
if (!blockStatement.body) return;
|
|
5952
|
+
var useTranslationHook = pure.findBy(USE_TRANSLATION_HOOK_PATTERN, blockStatement.body);
|
|
5953
|
+
if (!useTranslationHook) return;
|
|
5954
|
+
var hasHooksOtherThanTranslationHook = blockStatement.body.some(function (node) {
|
|
5955
|
+
return (pure.matches(REACT_HOOKS_CALL_PATTERN, node) || pure.matches(REACT_HOOKS_VARIABLE_DECLARATION_PATTERN, node)) && !pure.matches(USE_TRANSLATION_HOOK_PATTERN, node);
|
|
5956
|
+
});
|
|
5957
|
+
if (hasHooksOtherThanTranslationHook) return;
|
|
5958
|
+
context.report({
|
|
5959
|
+
node: node,
|
|
5960
|
+
message: "Use withT HOC instead of useTranslation hook",
|
|
5961
|
+
fix: function fix(fixer) {
|
|
5962
|
+
var fixers = [];
|
|
5963
|
+
var _arrowFunctionExpress = _toArray(arrowFunctionExpression.params),
|
|
5964
|
+
props = _arrowFunctionExpress[0],
|
|
5965
|
+
restParams = _arrowFunctionExpress.slice(1);
|
|
5966
|
+
var getPropsCode = function getPropsCode() {
|
|
5967
|
+
if (ramda.isEmpty(arrowFunctionExpression.params) || !props) {
|
|
5968
|
+
return "{ t }";
|
|
5969
|
+
}
|
|
5970
|
+
if (props.type === TYPES.IDENTIFIER) {
|
|
5971
|
+
return "{ t, ...".concat(getCode$1(context, props), " }");
|
|
5972
|
+
}
|
|
5973
|
+
if (props.type === TYPES.OBJECT_PATTERN) {
|
|
5974
|
+
return "{ t, ".concat(props.properties.map(function (property) {
|
|
5975
|
+
return getCode$1(context, property);
|
|
5976
|
+
}).join(", "), " }");
|
|
5977
|
+
}
|
|
5978
|
+
return "";
|
|
5979
|
+
};
|
|
5980
|
+
var blockStatementCode = getCode$1(context, blockStatement);
|
|
5981
|
+
var useTranslationHookCode = getCode$1(context, useTranslationHook);
|
|
5982
|
+
var body = blockStatementCode.replace(useTranslationHookCode, "");
|
|
5983
|
+
var withTWrap = "withT((".concat(getPropsCode()).concat(pure.isNotEmpty(restParams) ? ", ".concat(restParams.map(function (param) {
|
|
5984
|
+
return getCode$1(context, param);
|
|
5985
|
+
}).join(", ")) : "", ") => ").concat(body, ")");
|
|
5986
|
+
var wrapWithWithT = fixer.replaceText(arrowFunctionExpression, withTWrap);
|
|
5987
|
+
fixers.push(wrapWithWithT);
|
|
5988
|
+
var importWithT = addFunctionImport({
|
|
5989
|
+
context: context,
|
|
5990
|
+
fixer: fixer,
|
|
5991
|
+
functions: ["withT"],
|
|
5992
|
+
importPattern: NEETO_COMMONS_REACT_UTILS_IMPORT_PATTERN
|
|
5993
|
+
});
|
|
5994
|
+
importWithT && fixers.push(importWithT);
|
|
5995
|
+
return fixers;
|
|
5996
|
+
}
|
|
5997
|
+
});
|
|
5998
|
+
}
|
|
5999
|
+
};
|
|
6000
|
+
}
|
|
6001
|
+
};
|
|
6002
|
+
|
|
5871
6003
|
var nonDefaultParam = function nonDefaultParam(_ref) {
|
|
5872
6004
|
var type = _ref.type;
|
|
5873
6005
|
return type !== TYPES.ASSIGNMENT_PATTERN;
|
|
@@ -5881,7 +6013,7 @@
|
|
|
5881
6013
|
return getCode$1(context, param);
|
|
5882
6014
|
}).join(", ");
|
|
5883
6015
|
};
|
|
5884
|
-
var checkAndReport$
|
|
6016
|
+
var checkAndReport$2 = function checkAndReport(context, params) {
|
|
5885
6017
|
var isApiAction = isInsideApisDirectory(context);
|
|
5886
6018
|
if (!containsExcessArguments(params, isApiAction)) return;
|
|
5887
6019
|
var loc = {
|
|
@@ -5913,15 +6045,15 @@
|
|
|
5913
6045
|
return {
|
|
5914
6046
|
// const sum = (a, b) => a + b;
|
|
5915
6047
|
ArrowFunctionExpression: function ArrowFunctionExpression(node) {
|
|
5916
|
-
checkAndReport$
|
|
6048
|
+
checkAndReport$2(context, node.params);
|
|
5917
6049
|
},
|
|
5918
6050
|
// const sum = function (a, b) { return a + b };
|
|
5919
6051
|
FunctionExpression: function FunctionExpression(node) {
|
|
5920
|
-
checkAndReport$
|
|
6052
|
+
checkAndReport$2(context, node.params);
|
|
5921
6053
|
},
|
|
5922
6054
|
// function sum (a, b) { return a + b };
|
|
5923
6055
|
FunctionDeclaration: function FunctionDeclaration(node) {
|
|
5924
|
-
checkAndReport$
|
|
6056
|
+
checkAndReport$2(context, node.params);
|
|
5925
6057
|
}
|
|
5926
6058
|
};
|
|
5927
6059
|
}
|
|
@@ -7845,7 +7977,7 @@
|
|
|
7845
7977
|
return key.name === name;
|
|
7846
7978
|
})) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
|
|
7847
7979
|
};
|
|
7848
|
-
var checkAndReport = function checkAndReport(_ref6) {
|
|
7980
|
+
var checkAndReport$1 = function checkAndReport(_ref6) {
|
|
7849
7981
|
var context = _ref6.context,
|
|
7850
7982
|
node = _ref6.node,
|
|
7851
7983
|
urlNode = _ref6.urlNode;
|
|
@@ -7882,7 +8014,7 @@
|
|
|
7882
8014
|
return {
|
|
7883
8015
|
CallExpression: function CallExpression(node) {
|
|
7884
8016
|
if (pure.matches(AXIOS_GET_PATTERN, node)) {
|
|
7885
|
-
checkAndReport({
|
|
8017
|
+
checkAndReport$1({
|
|
7886
8018
|
context: context,
|
|
7887
8019
|
node: node,
|
|
7888
8020
|
urlNode: node.arguments[0]
|
|
@@ -7900,7 +8032,7 @@
|
|
|
7900
8032
|
methodNode = getPropValue(node.arguments[1], "method");
|
|
7901
8033
|
}
|
|
7902
8034
|
if (((_methodNode = methodNode) === null || _methodNode === void 0 ? void 0 : _methodNode.value.toLowerCase()) !== "get") return;
|
|
7903
|
-
checkAndReport({
|
|
8035
|
+
checkAndReport$1({
|
|
7904
8036
|
context: context,
|
|
7905
8037
|
node: node,
|
|
7906
8038
|
urlNode: urlNode
|
|
@@ -7963,6 +8095,140 @@
|
|
|
7963
8095
|
}
|
|
7964
8096
|
};
|
|
7965
8097
|
|
|
8098
|
+
var IMPORT_SOURCES = {
|
|
8099
|
+
"neeto-commons-frontend": "neetocommons/constants",
|
|
8100
|
+
"neeto-team-members-frontend": "neetoteam/constants"
|
|
8101
|
+
};
|
|
8102
|
+
var TRANSLATION_VERBS_PATTERN = {
|
|
8103
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
8104
|
+
properties: [{
|
|
8105
|
+
type: TYPES.PROPERTY,
|
|
8106
|
+
key: {
|
|
8107
|
+
type: TYPES.IDENTIFIER,
|
|
8108
|
+
name: "count"
|
|
8109
|
+
},
|
|
8110
|
+
value: {
|
|
8111
|
+
type: TYPES.LITERAL,
|
|
8112
|
+
value: function value(_value) {
|
|
8113
|
+
return ramda.includes(_value, [1, 2]);
|
|
8114
|
+
}
|
|
8115
|
+
}
|
|
8116
|
+
}]
|
|
8117
|
+
};
|
|
8118
|
+
var constantImportPattern = function constantImportPattern(constantName, repository) {
|
|
8119
|
+
return {
|
|
8120
|
+
specifiers: function specifiers(_specifiers) {
|
|
8121
|
+
return pure.findBy(pure.matches({
|
|
8122
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
8123
|
+
local: {
|
|
8124
|
+
type: TYPES.IDENTIFIER,
|
|
8125
|
+
name: constantName
|
|
8126
|
+
}
|
|
8127
|
+
}), _specifiers);
|
|
8128
|
+
},
|
|
8129
|
+
source: {
|
|
8130
|
+
type: TYPES.LITERAL,
|
|
8131
|
+
value: IMPORT_SOURCES[repository]
|
|
8132
|
+
}
|
|
8133
|
+
};
|
|
8134
|
+
};
|
|
8135
|
+
var NEETO_TEAM_MEMBERS_CONSTANTS = {
|
|
8136
|
+
MANAGE_MEMBERS_PERMISSION: "members.manage_members",
|
|
8137
|
+
MANAGE_ROLES_PERMISSION: "settings.manage_roles",
|
|
8138
|
+
VIEW_MEMBERS_PERMISSION: "members.view_members",
|
|
8139
|
+
VIEW_ROLES_PERMISSION: "settings.view_roles"
|
|
8140
|
+
};
|
|
8141
|
+
|
|
8142
|
+
var getKeyByValue = function getKeyByValue(object, targetValue) {
|
|
8143
|
+
return Object.keys(object).find(function (key) {
|
|
8144
|
+
return object[key] === targetValue;
|
|
8145
|
+
});
|
|
8146
|
+
};
|
|
8147
|
+
var reportIssue = function reportIssue(_ref) {
|
|
8148
|
+
var node = _ref.node,
|
|
8149
|
+
repository = _ref.repository,
|
|
8150
|
+
context = _ref.context,
|
|
8151
|
+
constantName = _ref.constantName;
|
|
8152
|
+
context.report({
|
|
8153
|
+
node: node,
|
|
8154
|
+
message: suggestCommonConstants(constantName, repository)
|
|
8155
|
+
});
|
|
8156
|
+
};
|
|
8157
|
+
var checkAndReport = function checkAndReport(_ref2) {
|
|
8158
|
+
var _parentNode$init;
|
|
8159
|
+
var node = _ref2.node,
|
|
8160
|
+
constants = _ref2.constants,
|
|
8161
|
+
repository = _ref2.repository,
|
|
8162
|
+
context = _ref2.context;
|
|
8163
|
+
var nodeName = node.name;
|
|
8164
|
+
var parentNode = node.parent;
|
|
8165
|
+
var parentNodeValue = (_parentNode$init = parentNode.init) === null || _parentNode$init === void 0 ? void 0 : _parentNode$init.value;
|
|
8166
|
+
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)))) {
|
|
8167
|
+
reportIssue({
|
|
8168
|
+
node: node,
|
|
8169
|
+
repository: repository,
|
|
8170
|
+
context: context,
|
|
8171
|
+
constantName: nodeName
|
|
8172
|
+
});
|
|
8173
|
+
} else if (parentNode.type === TYPES.VARIABLE_DECLARATOR && !Number.isInteger(parentNodeValue)) {
|
|
8174
|
+
var key = getKeyByValue(constants, parentNodeValue);
|
|
8175
|
+
if (key) {
|
|
8176
|
+
reportIssue({
|
|
8177
|
+
node: node,
|
|
8178
|
+
repository: repository,
|
|
8179
|
+
context: context,
|
|
8180
|
+
constantName: key
|
|
8181
|
+
});
|
|
8182
|
+
}
|
|
8183
|
+
}
|
|
8184
|
+
};
|
|
8185
|
+
var checkTranslationVerbs = function checkTranslationVerbs(node, context) {
|
|
8186
|
+
var _parentNode$callee;
|
|
8187
|
+
var parentNode = node.parent;
|
|
8188
|
+
var repository = "neeto-commons-frontend";
|
|
8189
|
+
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));
|
|
8190
|
+
if (isCommonConstant) {
|
|
8191
|
+
reportIssue({
|
|
8192
|
+
node: node,
|
|
8193
|
+
repository: repository,
|
|
8194
|
+
context: context,
|
|
8195
|
+
constantName: "TRANSLATION_".concat(node.name)
|
|
8196
|
+
});
|
|
8197
|
+
}
|
|
8198
|
+
};
|
|
8199
|
+
|
|
8200
|
+
var useCommonConstants = {
|
|
8201
|
+
meta: {
|
|
8202
|
+
type: "suggestion",
|
|
8203
|
+
docs: {
|
|
8204
|
+
url: "",
|
|
8205
|
+
description: "Suggests using common constants from neeto-team-members and neeto-commons-frontend repos"
|
|
8206
|
+
}
|
|
8207
|
+
},
|
|
8208
|
+
create: function create(context) {
|
|
8209
|
+
return {
|
|
8210
|
+
Identifier: function Identifier(node) {
|
|
8211
|
+
var nodeName = node.name;
|
|
8212
|
+
if (nodeName === "SINGULAR" || nodeName === "PLURAL") {
|
|
8213
|
+
checkTranslationVerbs(node, context);
|
|
8214
|
+
}
|
|
8215
|
+
checkAndReport({
|
|
8216
|
+
node: node,
|
|
8217
|
+
constants: neetoCommonsConstants__namespace,
|
|
8218
|
+
repository: "neeto-commons-frontend",
|
|
8219
|
+
context: context
|
|
8220
|
+
});
|
|
8221
|
+
checkAndReport({
|
|
8222
|
+
node: node,
|
|
8223
|
+
constants: NEETO_TEAM_MEMBERS_CONSTANTS,
|
|
8224
|
+
repository: "neeto-team-members-frontend",
|
|
8225
|
+
context: context
|
|
8226
|
+
});
|
|
8227
|
+
}
|
|
8228
|
+
};
|
|
8229
|
+
}
|
|
8230
|
+
};
|
|
8231
|
+
|
|
7966
8232
|
// createSubscription();
|
|
7967
8233
|
var CUSTOM_CREATE_SUBSCRIPTION_PATTERN = {
|
|
7968
8234
|
type: TYPES.CALL_EXPRESSION,
|
|
@@ -26269,6 +26535,7 @@
|
|
|
26269
26535
|
|
|
26270
26536
|
var index = {
|
|
26271
26537
|
rules: {
|
|
26538
|
+
"no-dumb-components-with-use-translation": noDumbComponentsWithUseTranslation,
|
|
26272
26539
|
"api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
|
|
26273
26540
|
"api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
|
|
26274
26541
|
"combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
|
|
@@ -26330,7 +26597,8 @@
|
|
|
26330
26597
|
"use-functions-and-hooks-from-neeto-commons-frontend": useFunctionsAndHooksFromNeetoCommonsFrontend,
|
|
26331
26598
|
"no-unnecessary-if-condition": noUnnecessaryIfCondition,
|
|
26332
26599
|
"zustand-use-with-immutable-actions-wrapper-inside-create": useWithImmutableActionsWrapperInsideCreate,
|
|
26333
|
-
"add-required-peer-dependencies": addRequiredPeerDependencies
|
|
26600
|
+
"add-required-peer-dependencies": addRequiredPeerDependencies,
|
|
26601
|
+
"use-common-constants": useCommonConstants
|
|
26334
26602
|
},
|
|
26335
26603
|
configs: {
|
|
26336
26604
|
recommended: recommended,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/eslint-plugin-neeto",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
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.
|
|
39
|
-
"@bigbinary/neeto-commons-frontend": "^2.0.
|
|
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",
|