@rotki/eslint-plugin 1.3.1 → 1.3.2
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/dist/index.mjs +30 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { statSync, readFileSync } from 'node:fs';
|
|
|
7
7
|
import { globSync } from 'tinyglobby';
|
|
8
8
|
import { parse } from 'vue-eslint-parser';
|
|
9
9
|
|
|
10
|
-
const version = "1.3.
|
|
10
|
+
const version = "1.3.2";
|
|
11
11
|
const pkg = {
|
|
12
12
|
version: version};
|
|
13
13
|
|
|
@@ -538,12 +538,17 @@ const composableRequireCleanup = createEslintRule({
|
|
|
538
538
|
});
|
|
539
539
|
|
|
540
540
|
const RULE_NAME$a = "composable-return-readonly";
|
|
541
|
-
const REACTIVE_CREATORS = /* @__PURE__ */ new Set(["ref", "shallowRef"
|
|
541
|
+
const REACTIVE_CREATORS = /* @__PURE__ */ new Set(["ref", "shallowRef"]);
|
|
542
|
+
const READONLY_CREATORS = /* @__PURE__ */ new Set(["computed"]);
|
|
543
|
+
function isReadonlyCall(node) {
|
|
544
|
+
return node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "readonly" && node.arguments.length === 1 && node.arguments[0].type === AST_NODE_TYPES.Identifier;
|
|
545
|
+
}
|
|
542
546
|
const composableReturnReadonly = createEslintRule({
|
|
543
547
|
create(context) {
|
|
544
548
|
const autofix = context.options[0]?.autofix ?? false;
|
|
545
549
|
const source = getSourceCode(context);
|
|
546
550
|
const reactiveVars = /* @__PURE__ */ new Set();
|
|
551
|
+
const readonlyVars = /* @__PURE__ */ new Set();
|
|
547
552
|
return {
|
|
548
553
|
ReturnStatement: (node) => {
|
|
549
554
|
if (!getEnclosingComposable(node))
|
|
@@ -553,6 +558,20 @@ const composableReturnReadonly = createEslintRule({
|
|
|
553
558
|
for (const prop of node.argument.properties) {
|
|
554
559
|
if (prop.type !== AST_NODE_TYPES.Property)
|
|
555
560
|
continue;
|
|
561
|
+
const valueNode = prop.shorthand ? null : prop.value;
|
|
562
|
+
if (valueNode && isReadonlyCall(valueNode)) {
|
|
563
|
+
const innerName = valueNode.arguments[0].name;
|
|
564
|
+
if (readonlyVars.has(innerName)) {
|
|
565
|
+
const fixFn = (fixer) => fixer.replaceText(valueNode, innerName);
|
|
566
|
+
context.report({
|
|
567
|
+
data: { name: innerName },
|
|
568
|
+
...autofix ? { fix: fixFn } : { suggest: [{ data: { name: innerName }, fix: fixFn, messageId: "suggestRemoveReadonly" }] },
|
|
569
|
+
messageId: "unnecessaryReadonly",
|
|
570
|
+
node: prop
|
|
571
|
+
});
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
556
575
|
if (prop.shorthand && prop.key.type === AST_NODE_TYPES.Identifier && reactiveVars.has(prop.key.name)) {
|
|
557
576
|
const keyName = prop.key.name;
|
|
558
577
|
const fixFn = (fixer) => fixer.replaceText(prop, `${keyName}: readonly(${keyName})`);
|
|
@@ -579,8 +598,13 @@ const composableReturnReadonly = createEslintRule({
|
|
|
579
598
|
return;
|
|
580
599
|
if (node.id.type !== AST_NODE_TYPES.Identifier)
|
|
581
600
|
return;
|
|
582
|
-
if (node.init?.type === AST_NODE_TYPES.CallExpression && node.init.callee.type === AST_NODE_TYPES.Identifier
|
|
583
|
-
|
|
601
|
+
if (node.init?.type === AST_NODE_TYPES.CallExpression && node.init.callee.type === AST_NODE_TYPES.Identifier) {
|
|
602
|
+
const calleeName = node.init.callee.name;
|
|
603
|
+
if (REACTIVE_CREATORS.has(calleeName)) {
|
|
604
|
+
reactiveVars.add(node.id.name);
|
|
605
|
+
} else if (READONLY_CREATORS.has(calleeName)) {
|
|
606
|
+
readonlyVars.add(node.id.name);
|
|
607
|
+
}
|
|
584
608
|
}
|
|
585
609
|
}
|
|
586
610
|
};
|
|
@@ -594,7 +618,9 @@ const composableReturnReadonly = createEslintRule({
|
|
|
594
618
|
fixable: "code",
|
|
595
619
|
hasSuggestions: true,
|
|
596
620
|
messages: {
|
|
621
|
+
suggestRemoveReadonly: "Remove unnecessary readonly() from '{{ name }}'.",
|
|
597
622
|
suggestWrapReadonly: "Wrap '{{ name }}' with readonly().",
|
|
623
|
+
unnecessaryReadonly: "Computed ref '{{ name }}' is already readonly and does not need readonly() wrapping.",
|
|
598
624
|
wrapReadonly: "Returned ref '{{ name }}' should be wrapped with readonly()."
|
|
599
625
|
},
|
|
600
626
|
schema: [
|