Skip to content

Commit 0ce703d

Browse files
authored
Fix false-positive in no-duplicate-on (#86)
* Add test case for bug * fix bug
1 parent 76f4e3c commit 0ce703d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Examples were found in production code-base with false-poitive detection on 0.5.2
2+
// https://github.com/effector/eslint-plugin/issues/85
3+
4+
import { createEvent, createStore } from "effector";
5+
6+
const $first = createStore("");
7+
const $second = createStore("");
8+
9+
const change = createEvent();
10+
11+
const service = {
12+
inputs: { $first, $second },
13+
};
14+
15+
service.inputs.$first.on(change, () => "HI");
16+
service.inputs.$second.on(change, () => "BYE");
17+
18+
export { service };

rules/no-duplicate-on/no-duplicate-on.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const { createLinkToRule } = require("../../utils/create-link-to-rule");
22
const { getNestedObjectName } = require("../../utils/get-nested-object-name");
3+
const {
4+
traverseNestedObjectNode,
5+
} = require("../../utils/traverse-nested-object-node");
36
const { is } = require("../../utils/is");
47

58
module.exports = {
@@ -56,7 +59,9 @@ module.exports = {
5659

5760
return {
5861
'CallExpression[callee.property.name="on"]'(node) {
59-
const storeObject = getNestedCallee(node) ?? getAssignedVariable(node);
62+
const storeObject = traverseNestedObjectNode(
63+
getNestedCallee(node) ?? getAssignedVariable(node)
64+
);
6065
const storeName = getStoreName(storeObject);
6166

6267
if (!is.store({ context, node: storeObject })) {

rules/no-duplicate-on/no-duplicate-on.ts.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const readExampleForTheRule = (name) => ({
2121
});
2222

2323
ruleTester.run("effector/no-duplicate-on.ts.test", rule, {
24-
valid: ["correct.ts", "correct-with-scopes.ts"].map(readExampleForTheRule),
24+
valid: [
25+
"correct.ts",
26+
"correct-with-scopes.ts",
27+
"correct-with-nesting.ts",
28+
].map(readExampleForTheRule),
2529
invalid: ["incorrect-with-invalid-naming.ts"]
2630
.map(readExampleForTheRule)
2731
.map((example) => ({

0 commit comments

Comments
 (0)