@bigbinary/eslint-plugin-neeto 1.1.24 → 1.1.25
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 +105 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ module.exports = {
|
|
|
46
46
|
|
|
47
47
|
## Exported rules
|
|
48
48
|
|
|
49
|
+
- [use-use-query-client-hook](./docs/src/rules/use-use-query-client-hook.md)
|
|
49
50
|
|
|
50
51
|
- [use-classnames-for-dynamic-classes](./docs/src/rules/use-classnames-for-dynamic-classes.md)
|
|
51
52
|
- [use-use-mutation-with-invalidation-hook](./docs/src/rules/use-use-mutation-with-invalidation-hook.md)
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
var commonResolve$2 = loadJS$2("node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
|
|
43
43
|
var resolve$2 = ramda.mergeDeepLeft(projectResolve$2, commonResolve$2);
|
|
44
44
|
var rules = {
|
|
45
|
+
"@bigbinary/neeto/use-use-query-client-hook": "error",
|
|
45
46
|
"@bigbinary/neeto/use-classnames-for-dynamic-classes": "error",
|
|
46
47
|
"@bigbinary/neeto/use-use-mutation-with-invalidation-hook": "error",
|
|
47
48
|
"@bigbinary/neeto/no-withT-for-smart-components": "error",
|
|
@@ -553,6 +554,7 @@
|
|
|
553
554
|
var MOVE_SPREAD_ATTRIBUTES_TO_TOP = "Move spread attribute to top";
|
|
554
555
|
var USE_USE_MUTATION_WITH_INVALIDATION = "Use useMutationWithInvalidation from 'neetocommons/react-utils'";
|
|
555
556
|
var USE_CLASSNAMES_PACKAGE = "Use classnames package for dynamic classes";
|
|
557
|
+
var USE_USE_QUERY_CLIENT_HOOK = "Use 'useQueryClient' hook from 'react-query'";
|
|
556
558
|
|
|
557
559
|
var PACKAGES_TO_CHECK = ["@bigbinary/neeto-molecules", "@bigbinary/neetoui", "@bigbinary/neeto-commons-frontend"];
|
|
558
560
|
|
|
@@ -26665,6 +26667,108 @@
|
|
|
26665
26667
|
}
|
|
26666
26668
|
};
|
|
26667
26669
|
|
|
26670
|
+
// import queryClient from "..";
|
|
26671
|
+
var QUERY_CLIENT_IMPORT_PATTERN = {
|
|
26672
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
26673
|
+
specifiers: [{
|
|
26674
|
+
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
26675
|
+
local: {
|
|
26676
|
+
type: TYPES.IDENTIFIER,
|
|
26677
|
+
name: "queryClient"
|
|
26678
|
+
}
|
|
26679
|
+
}]
|
|
26680
|
+
};
|
|
26681
|
+
|
|
26682
|
+
// import { useQueryClient } from "react-query";
|
|
26683
|
+
var USE_QUERY_CLIENT_IMPORT_PATTERN = {
|
|
26684
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
26685
|
+
source: {
|
|
26686
|
+
type: TYPES.LITERAL,
|
|
26687
|
+
value: "react-query"
|
|
26688
|
+
},
|
|
26689
|
+
specifiers: pure.existsBy({
|
|
26690
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
26691
|
+
local: {
|
|
26692
|
+
type: TYPES.IDENTIFIER,
|
|
26693
|
+
name: "useQueryClient"
|
|
26694
|
+
}
|
|
26695
|
+
})
|
|
26696
|
+
};
|
|
26697
|
+
|
|
26698
|
+
// import {...} from "react-query";
|
|
26699
|
+
var REACT_QUERY_IMPORT_PATTERN = {
|
|
26700
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
26701
|
+
source: {
|
|
26702
|
+
type: TYPES.LITERAL,
|
|
26703
|
+
value: "react-query"
|
|
26704
|
+
},
|
|
26705
|
+
specifiers: [{
|
|
26706
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
26707
|
+
}]
|
|
26708
|
+
};
|
|
26709
|
+
|
|
26710
|
+
var getQueryClientInitializationFix = function getQueryClientInitializationFix(context, fixer, body) {
|
|
26711
|
+
if (body.type === TYPES.BLOCK_STATEMENT) {
|
|
26712
|
+
var indentLevel = context.getSourceCode().getFirstToken(body.body[0]).loc.start.column;
|
|
26713
|
+
return fixer.insertTextBefore(body.body[0], "const queryClient = useQueryClient();\n".concat(" ".repeat(indentLevel)));
|
|
26714
|
+
}
|
|
26715
|
+
return fixer.replaceText(body, "{ const queryClient = useQueryClient(); return (".concat(context.getSourceCode().getText(body), ") }"));
|
|
26716
|
+
};
|
|
26717
|
+
|
|
26718
|
+
var useUseQueryClientHook = {
|
|
26719
|
+
meta: {
|
|
26720
|
+
type: "problem",
|
|
26721
|
+
docs: {
|
|
26722
|
+
url: "https://github.com/bigbinary/eslint-plugin-neeto/blob/main/docs/src/rules/use-use-query-client-hook.md",
|
|
26723
|
+
description: "Enforce use of useQueryClient hook instead of direct queryClient import"
|
|
26724
|
+
},
|
|
26725
|
+
fixable: "code"
|
|
26726
|
+
},
|
|
26727
|
+
create: function create(context) {
|
|
26728
|
+
return {
|
|
26729
|
+
VariableDeclarator: function VariableDeclarator(node) {
|
|
26730
|
+
var _node$parent, _findBy2;
|
|
26731
|
+
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.parent.type) !== TYPES.PROGRAM) return;
|
|
26732
|
+
var text = context.getSourceCode().getText(node);
|
|
26733
|
+
if (!text.includes("queryClient.") || text.includes("const queryClient = useQueryClient();")) {
|
|
26734
|
+
return;
|
|
26735
|
+
}
|
|
26736
|
+
var body = node.init.body || ((_findBy2 = pure._findBy({
|
|
26737
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION
|
|
26738
|
+
}, node.init.arguments)) === null || _findBy2 === void 0 ? void 0 : _findBy2.body);
|
|
26739
|
+
var allImports = getAllImports(node);
|
|
26740
|
+
var queryClientImport = pure.findBy(QUERY_CLIENT_IMPORT_PATTERN, allImports);
|
|
26741
|
+
if (!queryClientImport || !body) return;
|
|
26742
|
+
if (!(/^[A-Z]/.test(node.id.name) || node.id.name.startsWith("use"))) {
|
|
26743
|
+
context.report({
|
|
26744
|
+
node: queryClientImport,
|
|
26745
|
+
message: USE_USE_QUERY_CLIENT_HOOK
|
|
26746
|
+
});
|
|
26747
|
+
return;
|
|
26748
|
+
}
|
|
26749
|
+
context.report({
|
|
26750
|
+
node: queryClientImport,
|
|
26751
|
+
message: USE_USE_QUERY_CLIENT_HOOK,
|
|
26752
|
+
fix: function fix(fixer) {
|
|
26753
|
+
var initializeQueryClient = getQueryClientInitializationFix(context, fixer, body);
|
|
26754
|
+
var importExists = pure.existsBy(USE_QUERY_CLIENT_IMPORT_PATTERN, allImports);
|
|
26755
|
+
if (!importExists) {
|
|
26756
|
+
var addImport = addFunctionImport({
|
|
26757
|
+
context: context,
|
|
26758
|
+
fixer: fixer,
|
|
26759
|
+
functions: ["useQueryClient"],
|
|
26760
|
+
importPattern: REACT_QUERY_IMPORT_PATTERN
|
|
26761
|
+
});
|
|
26762
|
+
return [initializeQueryClient, addImport];
|
|
26763
|
+
}
|
|
26764
|
+
return initializeQueryClient;
|
|
26765
|
+
}
|
|
26766
|
+
});
|
|
26767
|
+
}
|
|
26768
|
+
};
|
|
26769
|
+
}
|
|
26770
|
+
};
|
|
26771
|
+
|
|
26668
26772
|
var useWebpackAlias = {
|
|
26669
26773
|
meta: {
|
|
26670
26774
|
type: "suggestion",
|
|
@@ -27248,6 +27352,7 @@
|
|
|
27248
27352
|
|
|
27249
27353
|
var index = {
|
|
27250
27354
|
rules: {
|
|
27355
|
+
"use-use-query-client-hook": useUseQueryClientHook,
|
|
27251
27356
|
"use-classnames-for-dynamic-classes": useClassnamesForDynamicClasses,
|
|
27252
27357
|
"use-use-mutation-with-invalidation-hook": useUseMutationWithInvalidationHook,
|
|
27253
27358
|
"no-withT-for-smart-components": noWithTForSmartComponents,
|