@bigbinary/eslint-plugin-neeto 1.0.63 → 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 +173 -0
- 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
|
@@ -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",
|
|
@@ -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";
|
|
@@ -7620,6 +7626,172 @@
|
|
|
7620
7626
|
}
|
|
7621
7627
|
};
|
|
7622
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
|
+
|
|
7623
7795
|
const defaultOpts$2 = {
|
|
7624
7796
|
xml: false,
|
|
7625
7797
|
decodeEntities: true,
|
|
@@ -25740,6 +25912,7 @@
|
|
|
25740
25912
|
"use-camel-case-or-pascal-case-for-function-names": useCamelCaseOrPascalCaseForFunctionNames,
|
|
25741
25913
|
"use-common-routes": useCommonRoutes,
|
|
25742
25914
|
"use-components-children-prop-in-trans": useComponentsChildrenPropInTrans,
|
|
25915
|
+
"use-create-subscription-util-function": useCreateSubscriptionUtilFunction,
|
|
25743
25916
|
"use-i18next-plurals": useI18nextPlurals,
|
|
25744
25917
|
"use-inline-svg-for-render": useInlineSvgForRender,
|
|
25745
25918
|
"use-neeto-in-strings": useNeetoInStrings,
|