@bigbinary/eslint-plugin-neeto 1.0.62 → 1.0.64
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 +1 -0
- package/dist/index.js +306 -26
- 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
|
@@ -96,10 +96,11 @@
|
|
|
96
96
|
"@bigbinary/neeto/routes-should-be-declared-and-default-exported": "error",
|
|
97
97
|
"@bigbinary/neeto/routes-should-match-object-path": "error",
|
|
98
98
|
"@bigbinary/neeto/use-array-methods": "warn",
|
|
99
|
-
"@bigbinary/neeto/use-axios-config-for-passing-query-parameters": "
|
|
99
|
+
"@bigbinary/neeto/use-axios-config-for-passing-query-parameters": "warn",
|
|
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",
|
|
@@ -167,19 +168,19 @@
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
function _arrayLikeToArray(arr, len) {
|
|
171
|
+
function _arrayLikeToArray$1(arr, len) {
|
|
171
172
|
if (len == null || len > arr.length) len = arr.length;
|
|
172
173
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
173
174
|
return arr2;
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
177
|
+
function _unsupportedIterableToArray$1(o, minLen) {
|
|
177
178
|
if (!o) return;
|
|
178
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
179
|
+
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
|
|
179
180
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
180
181
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
181
182
|
if (n === "Map" || n === "Set") return Array.from(o);
|
|
182
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
183
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
function _nonIterableRest() {
|
|
@@ -187,7 +188,7 @@
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
function _slicedToArray(arr, i) {
|
|
190
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
191
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
var regeneratorRuntime$1 = {exports: {}};
|
|
@@ -891,6 +892,9 @@
|
|
|
891
892
|
var moveToConstantsJs = function moveToConstantsJs(constantName) {
|
|
892
893
|
return "Move the constant ".concat(constantName, " to a constants.js file.");
|
|
893
894
|
};
|
|
895
|
+
var preferSubscriptionUnsubscribe = function preferSubscriptionUnsubscribe(replacerText) {
|
|
896
|
+
return "Prefer to use ".concat(replacerText, ".unsubscribe() to prevent consumer creation boilerplate.");
|
|
897
|
+
};
|
|
894
898
|
var renameFile = function renameFile(filename) {
|
|
895
899
|
return "Rename this file to ".concat(filename);
|
|
896
900
|
};
|
|
@@ -940,8 +944,10 @@
|
|
|
940
944
|
var ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
|
|
941
945
|
var ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
|
|
942
946
|
var ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
|
|
947
|
+
var UNNECESSARY_CREATE_CONSUMER = "`createSubscription` function from `neetocommon/utils` invalidates the need of `createConsumer`";
|
|
943
948
|
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
949
|
var USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
|
|
950
|
+
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
951
|
var USE_INLINE_SVG_FOR_RENDER = "Use inline SVG instead of img tag for rendering SVGs";
|
|
946
952
|
var USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
|
|
947
953
|
var USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
|
|
@@ -1412,7 +1418,7 @@
|
|
|
1412
1418
|
};
|
|
1413
1419
|
|
|
1414
1420
|
function _arrayWithoutHoles(arr) {
|
|
1415
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
1421
|
+
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
|
|
1416
1422
|
}
|
|
1417
1423
|
|
|
1418
1424
|
function _iterableToArray(iter) {
|
|
@@ -1424,7 +1430,7 @@
|
|
|
1424
1430
|
}
|
|
1425
1431
|
|
|
1426
1432
|
function _toConsumableArray(arr) {
|
|
1427
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
1433
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
|
|
1428
1434
|
}
|
|
1429
1435
|
|
|
1430
1436
|
var camelize = function camelize(text) {
|
|
@@ -7395,38 +7401,145 @@
|
|
|
7395
7401
|
}]
|
|
7396
7402
|
};
|
|
7397
7403
|
|
|
7404
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
7405
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7406
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7407
|
+
var extractVariableValue = function extractVariableValue(inputValue) {
|
|
7408
|
+
var match = inputValue.match(/\${([^}]+)}/);
|
|
7409
|
+
return match ? match[1] : "\"".concat(inputValue, "\"");
|
|
7410
|
+
};
|
|
7411
|
+
var getUrlSearchParams = function getUrlSearchParams(urlString) {
|
|
7412
|
+
var params = {};
|
|
7413
|
+
var queryString = urlString.split("?")[1].slice(0, -1);
|
|
7414
|
+
if (queryString) {
|
|
7415
|
+
var searchParams = new URLSearchParams(queryString);
|
|
7416
|
+
var _iterator = _createForOfIteratorHelper(searchParams),
|
|
7417
|
+
_step;
|
|
7418
|
+
try {
|
|
7419
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7420
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
7421
|
+
key = _step$value[0],
|
|
7422
|
+
value = _step$value[1];
|
|
7423
|
+
if (ramda.isEmpty(value)) return {};
|
|
7424
|
+
params[key] = extractVariableValue(value);
|
|
7425
|
+
}
|
|
7426
|
+
} catch (err) {
|
|
7427
|
+
_iterator.e(err);
|
|
7428
|
+
} finally {
|
|
7429
|
+
_iterator.f();
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
return params;
|
|
7433
|
+
};
|
|
7434
|
+
var getParamsFixString = function getParamsFixString(params, paramsString) {
|
|
7435
|
+
var keys = Object.keys(params);
|
|
7436
|
+
if (keys.length === 1 && keys[0] === params[keys[0]]) {
|
|
7437
|
+
return "params: ".concat(keys[0]);
|
|
7438
|
+
}
|
|
7439
|
+
return "params: { ".concat(paramsString, "}");
|
|
7440
|
+
};
|
|
7441
|
+
var getFixForParamsObjectAlreadyPresent = function getFixForParamsObjectAlreadyPresent(paramsNode, fixer, paramsString) {
|
|
7442
|
+
if (paramsNode.value.type === TYPES.IDENTIFIER) {
|
|
7443
|
+
return fixer.replaceText(paramsNode, "params: { ...".concat(paramsNode.value.name, ", ").concat(paramsString, " }"));
|
|
7444
|
+
}
|
|
7445
|
+
return fixer.insertTextAfter(ramda.last(paramsNode.value.properties), ", ".concat(paramsString));
|
|
7446
|
+
};
|
|
7447
|
+
var getFix = function getFix(_ref) {
|
|
7448
|
+
var urlNode = _ref.urlNode,
|
|
7449
|
+
context = _ref.context,
|
|
7450
|
+
node = _ref.node,
|
|
7451
|
+
fixer = _ref.fixer;
|
|
7452
|
+
var urlString = context.getSourceCode().getText(urlNode);
|
|
7453
|
+
var fixForParams = getFixForParams({
|
|
7454
|
+
urlNode: urlNode,
|
|
7455
|
+
urlString: urlString,
|
|
7456
|
+
node: node,
|
|
7457
|
+
fixer: fixer
|
|
7458
|
+
});
|
|
7459
|
+
if (!fixForParams) return null;
|
|
7460
|
+
return [getFixForUrl(fixer, urlString, urlNode), fixForParams];
|
|
7461
|
+
};
|
|
7462
|
+
var getFixForUrl = function getFixForUrl(fixer, urlString, urlNode) {
|
|
7463
|
+
var urlWithoutSearchParams = urlString.split("?")[0].slice(1);
|
|
7464
|
+
var match = urlWithoutSearchParams.match(/^\${([^}]+)}$/);
|
|
7465
|
+
var urlFixString = "";
|
|
7466
|
+
if (match) {
|
|
7467
|
+
urlFixString = match[1];
|
|
7468
|
+
} else {
|
|
7469
|
+
urlFixString = urlWithoutSearchParams.includes("${") ? "`".concat(urlWithoutSearchParams, "`") : "\"".concat(urlWithoutSearchParams, "\"");
|
|
7470
|
+
}
|
|
7471
|
+
return fixer.replaceText(urlNode, urlFixString);
|
|
7472
|
+
};
|
|
7473
|
+
var getFixForParams = function getFixForParams(_ref2) {
|
|
7474
|
+
var urlNode = _ref2.urlNode,
|
|
7475
|
+
urlString = _ref2.urlString,
|
|
7476
|
+
node = _ref2.node,
|
|
7477
|
+
fixer = _ref2.fixer;
|
|
7478
|
+
var objectNode = pure.findBy({
|
|
7479
|
+
type: TYPES.OBJECT_EXPRESSION
|
|
7480
|
+
}, node.arguments);
|
|
7481
|
+
var objectProperties = objectNode === null || objectNode === void 0 ? void 0 : objectNode.properties;
|
|
7482
|
+
var paramsNode = objectProperties === null || objectProperties === void 0 ? void 0 : objectProperties.find(function (prop) {
|
|
7483
|
+
return prop.key.name === "params";
|
|
7484
|
+
});
|
|
7485
|
+
var params = getUrlSearchParams(urlString);
|
|
7486
|
+
if (ramda.isEmpty(params)) return null;
|
|
7487
|
+
var paramsString = Object.entries(params).map(function (_ref3) {
|
|
7488
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
7489
|
+
key = _ref4[0],
|
|
7490
|
+
value = _ref4[1];
|
|
7491
|
+
return "".concat(key, ": ").concat(value);
|
|
7492
|
+
}).join(", ");
|
|
7493
|
+
if (objectNode) {
|
|
7494
|
+
if (paramsNode) {
|
|
7495
|
+
return getFixForParamsObjectAlreadyPresent(paramsNode, fixer, paramsString);
|
|
7496
|
+
}
|
|
7497
|
+
var positionToInsert = ramda.last(objectProperties);
|
|
7498
|
+
var _fixString = getParamsFixString(params, paramsString);
|
|
7499
|
+
return fixer.insertTextAfter(positionToInsert, ", ".concat(_fixString));
|
|
7500
|
+
}
|
|
7501
|
+
var fixString = getParamsFixString(params, paramsString);
|
|
7502
|
+
return fixer.insertTextAfter(urlNode, ", { ".concat(fixString, "}"));
|
|
7503
|
+
};
|
|
7398
7504
|
var getPropValue = function getPropValue(configNode, name) {
|
|
7399
7505
|
var _configNode$propertie;
|
|
7400
|
-
return (_configNode$propertie = configNode.properties.find(function (
|
|
7401
|
-
var key =
|
|
7506
|
+
return (_configNode$propertie = configNode.properties.find(function (_ref5) {
|
|
7507
|
+
var key = _ref5.key;
|
|
7402
7508
|
return key.name === name;
|
|
7403
7509
|
})) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
|
|
7404
7510
|
};
|
|
7405
|
-
var checkAndReport = function checkAndReport(
|
|
7406
|
-
var context =
|
|
7407
|
-
node =
|
|
7408
|
-
urlNode =
|
|
7409
|
-
var isQuestionMarkPresent =
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
}
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7511
|
+
var checkAndReport = function checkAndReport(_ref6) {
|
|
7512
|
+
var context = _ref6.context,
|
|
7513
|
+
node = _ref6.node,
|
|
7514
|
+
urlNode = _ref6.urlNode;
|
|
7515
|
+
var isQuestionMarkPresent = urlNode.type === TYPES.LITERAL ? urlNode.value.includes("?") : urlNode.quasis.some(function (_ref7) {
|
|
7516
|
+
var value = _ref7.value;
|
|
7517
|
+
return value.cooked.includes("?");
|
|
7518
|
+
});
|
|
7519
|
+
if (isQuestionMarkPresent) {
|
|
7520
|
+
context.report({
|
|
7521
|
+
node: node,
|
|
7522
|
+
message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE,
|
|
7523
|
+
fix: function fix(fixer) {
|
|
7524
|
+
return getFix({
|
|
7525
|
+
urlNode: urlNode,
|
|
7526
|
+
context: context,
|
|
7527
|
+
node: node,
|
|
7528
|
+
fixer: fixer
|
|
7529
|
+
});
|
|
7530
|
+
}
|
|
7416
7531
|
});
|
|
7417
7532
|
}
|
|
7418
|
-
if (isQuestionMarkPresent) context.report({
|
|
7419
|
-
node: node,
|
|
7420
|
-
message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE
|
|
7421
|
-
});
|
|
7422
7533
|
};
|
|
7534
|
+
|
|
7423
7535
|
var useAxiosConfigForPassingQueryParameters = {
|
|
7424
7536
|
meta: {
|
|
7425
7537
|
type: "problem",
|
|
7426
7538
|
docs: {
|
|
7427
7539
|
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-axios-config-for-passing-query-parameters.md",
|
|
7428
7540
|
description: "Enforces using the config parameter of axios to send query parameters through axios"
|
|
7429
|
-
}
|
|
7541
|
+
},
|
|
7542
|
+
fixable: "code"
|
|
7430
7543
|
},
|
|
7431
7544
|
create: function create(context) {
|
|
7432
7545
|
return {
|
|
@@ -7513,6 +7626,172 @@
|
|
|
7513
7626
|
}
|
|
7514
7627
|
};
|
|
7515
7628
|
|
|
7629
|
+
// createSubscription();
|
|
7630
|
+
var CUSTOM_CREATE_SUBSCRIPTION_PATTERN = {
|
|
7631
|
+
type: TYPES.CALL_EXPRESSION,
|
|
7632
|
+
callee: {
|
|
7633
|
+
type: TYPES.IDENTIFIER,
|
|
7634
|
+
name: "createSubscription"
|
|
7635
|
+
}
|
|
7636
|
+
};
|
|
7637
|
+
|
|
7638
|
+
// [variableName].subscriptions.create();
|
|
7639
|
+
var SUBSCRIPTION_CREATE_PATTERN = {
|
|
7640
|
+
type: TYPES.CALL_EXPRESSION,
|
|
7641
|
+
callee: {
|
|
7642
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
7643
|
+
object: {
|
|
7644
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
7645
|
+
property: {
|
|
7646
|
+
type: TYPES.IDENTIFIER,
|
|
7647
|
+
name: "subscriptions"
|
|
7648
|
+
}
|
|
7649
|
+
},
|
|
7650
|
+
property: {
|
|
7651
|
+
type: TYPES.IDENTIFIER,
|
|
7652
|
+
name: "create"
|
|
7653
|
+
}
|
|
7654
|
+
}
|
|
7655
|
+
};
|
|
7656
|
+
|
|
7657
|
+
// [variableName].subscriptions.remove(subscriptionObject);
|
|
7658
|
+
var SUBSCRIPTION_REMOVE_PATTERN = {
|
|
7659
|
+
type: TYPES.CALL_EXPRESSION,
|
|
7660
|
+
callee: {
|
|
7661
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
7662
|
+
object: {
|
|
7663
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
7664
|
+
property: {
|
|
7665
|
+
type: TYPES.IDENTIFIER,
|
|
7666
|
+
name: "subscriptions"
|
|
7667
|
+
}
|
|
7668
|
+
},
|
|
7669
|
+
property: {
|
|
7670
|
+
type: TYPES.IDENTIFIER,
|
|
7671
|
+
name: "remove"
|
|
7672
|
+
}
|
|
7673
|
+
}
|
|
7674
|
+
};
|
|
7675
|
+
|
|
7676
|
+
// import { createConsumer } from "@rails/actioncable";
|
|
7677
|
+
var CREATE_CONSUMER_IMPORT_PATTERN = {
|
|
7678
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
7679
|
+
source: {
|
|
7680
|
+
type: TYPES.LITERAL,
|
|
7681
|
+
value: "@rails/actioncable"
|
|
7682
|
+
},
|
|
7683
|
+
specifiers: pure.existsBy({
|
|
7684
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
7685
|
+
imported: {
|
|
7686
|
+
type: TYPES.IDENTIFIER,
|
|
7687
|
+
name: "createConsumer"
|
|
7688
|
+
}
|
|
7689
|
+
})
|
|
7690
|
+
};
|
|
7691
|
+
|
|
7692
|
+
// import { functionName } from neetocommons/utils;
|
|
7693
|
+
var NEETO_COMMONS_UTILS_IMPORT_PATTERN = {
|
|
7694
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
7695
|
+
source: {
|
|
7696
|
+
type: TYPES.LITERAL,
|
|
7697
|
+
value: "neetocommons/utils"
|
|
7698
|
+
},
|
|
7699
|
+
specifiers: [{
|
|
7700
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
7701
|
+
}]
|
|
7702
|
+
};
|
|
7703
|
+
|
|
7704
|
+
var createSubscriptionImportPattern = function createSubscriptionImportPattern(functionName) {
|
|
7705
|
+
return {
|
|
7706
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
7707
|
+
source: {
|
|
7708
|
+
type: TYPES.LITERAL,
|
|
7709
|
+
value: pure.isNot("neetocommons/utils")
|
|
7710
|
+
},
|
|
7711
|
+
specifiers: ramda.any(matchesAny([{
|
|
7712
|
+
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
7713
|
+
local: {
|
|
7714
|
+
type: TYPES.IDENTIFIER,
|
|
7715
|
+
name: functionName
|
|
7716
|
+
}
|
|
7717
|
+
}, {
|
|
7718
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
7719
|
+
local: {
|
|
7720
|
+
type: TYPES.IDENTIFIER,
|
|
7721
|
+
name: functionName
|
|
7722
|
+
}
|
|
7723
|
+
}]))
|
|
7724
|
+
};
|
|
7725
|
+
};
|
|
7726
|
+
var importExists = function importExists(context, functionName) {
|
|
7727
|
+
var ast = context.getSourceCode().ast;
|
|
7728
|
+
return pure.existsBy(createSubscriptionImportPattern(functionName), ast.body);
|
|
7729
|
+
};
|
|
7730
|
+
|
|
7731
|
+
var useCreateSubscriptionUtilFunction = {
|
|
7732
|
+
meta: {
|
|
7733
|
+
type: "problem",
|
|
7734
|
+
docs: {
|
|
7735
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-create-subscription-util-function.md",
|
|
7736
|
+
description: "Suggests the use of createSubscription function rather than a custom implementation to create a channel"
|
|
7737
|
+
},
|
|
7738
|
+
fixable: "code"
|
|
7739
|
+
},
|
|
7740
|
+
create: function create(context) {
|
|
7741
|
+
var createSubscriptionImportExists = importExists(context, "createSubscription");
|
|
7742
|
+
return {
|
|
7743
|
+
CallExpression: function CallExpression(node) {
|
|
7744
|
+
if (createSubscriptionImportExists && pure.matches(CUSTOM_CREATE_SUBSCRIPTION_PATTERN, node)) {
|
|
7745
|
+
return context.report({
|
|
7746
|
+
node: node.callee,
|
|
7747
|
+
message: USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS
|
|
7748
|
+
});
|
|
7749
|
+
}
|
|
7750
|
+
if (pure.matches(SUBSCRIPTION_CREATE_PATTERN, node)) {
|
|
7751
|
+
return context.report({
|
|
7752
|
+
node: node.callee,
|
|
7753
|
+
fix: function fix(fixer) {
|
|
7754
|
+
var fixerArray = [fixer.replaceTextRange(node.callee.range.splice(0, 2), "createSubscription")];
|
|
7755
|
+
var addedImport = addFunctionImport({
|
|
7756
|
+
context: context,
|
|
7757
|
+
fixer: fixer,
|
|
7758
|
+
functions: ["createSubscription"],
|
|
7759
|
+
importPattern: NEETO_COMMONS_UTILS_IMPORT_PATTERN
|
|
7760
|
+
});
|
|
7761
|
+
if (addedImport) fixerArray.push(addedImport);
|
|
7762
|
+
return fixerArray;
|
|
7763
|
+
},
|
|
7764
|
+
message: USE_CREATE_SUBSCRIPTION_FROM_NEETO_COMMONS
|
|
7765
|
+
});
|
|
7766
|
+
}
|
|
7767
|
+
if (pure.matches(SUBSCRIPTION_REMOVE_PATTERN, node)) {
|
|
7768
|
+
var replacerText = context.getSourceCode().getText(node.arguments[0]);
|
|
7769
|
+
var replacerRange = node.range.splice(0, 2);
|
|
7770
|
+
return context.report({
|
|
7771
|
+
node: node.callee,
|
|
7772
|
+
fix: function fix(fixer) {
|
|
7773
|
+
return fixer.replaceTextRange(replacerRange, "".concat(replacerText, ".unsubscribe()"));
|
|
7774
|
+
},
|
|
7775
|
+
message: preferSubscriptionUnsubscribe(replacerText)
|
|
7776
|
+
});
|
|
7777
|
+
}
|
|
7778
|
+
return undefined;
|
|
7779
|
+
},
|
|
7780
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
7781
|
+
if (!pure.matches(CREATE_CONSUMER_IMPORT_PATTERN, node)) return;
|
|
7782
|
+
context.report({
|
|
7783
|
+
node: pure.findBy({
|
|
7784
|
+
imported: {
|
|
7785
|
+
name: "createConsumer"
|
|
7786
|
+
}
|
|
7787
|
+
}, node.specifiers),
|
|
7788
|
+
message: UNNECESSARY_CREATE_CONSUMER
|
|
7789
|
+
});
|
|
7790
|
+
}
|
|
7791
|
+
};
|
|
7792
|
+
}
|
|
7793
|
+
};
|
|
7794
|
+
|
|
7516
7795
|
const defaultOpts$2 = {
|
|
7517
7796
|
xml: false,
|
|
7518
7797
|
decodeEntities: true,
|
|
@@ -25633,6 +25912,7 @@
|
|
|
25633
25912
|
"use-camel-case-or-pascal-case-for-function-names": useCamelCaseOrPascalCaseForFunctionNames,
|
|
25634
25913
|
"use-common-routes": useCommonRoutes,
|
|
25635
25914
|
"use-components-children-prop-in-trans": useComponentsChildrenPropInTrans,
|
|
25915
|
+
"use-create-subscription-util-function": useCreateSubscriptionUtilFunction,
|
|
25636
25916
|
"use-i18next-plurals": useI18nextPlurals,
|
|
25637
25917
|
"use-inline-svg-for-render": useInlineSvgForRender,
|
|
25638
25918
|
"use-neeto-in-strings": useNeetoInStrings,
|