Skip to content

Commit

Permalink
Fix false-positive in no-ambiguity-target, fixes #133
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Mar 29, 2023
1 parent ef09732 commit e0ac240
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions rules/no-ambiguity-target/examples/correct-example-issue-133.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Examples were found in production code-base with exception on 0.10.3
// https://github.com/igorkamyshev/eslint-plugin-effector/issues/133

import { createStore, createEvent, sample } from "effector";

const obj = {
fn: () => {
const $store = createStore(0);
const event = createEvent();
// warning Method `sample` returns `target` and assigns the result to a variable. Consider removing one of them effector/no-ambiguity-target
sample({
source: event,
target: $store,
});
},
};
3 changes: 2 additions & 1 deletion rules/no-ambiguity-target/no-ambiguity-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ module.exports = {
);
const resultPartOfChain = traverseParentByType(
node,
"ObjectExpression"
"ObjectExpression",
{ stopOnTypes: ["BlockStatement"] }
);

if (resultAssignedInVariable || resultPartOfChain) {
Expand Down
23 changes: 23 additions & 0 deletions rules/no-ambiguity-target/no-ambiguity-target.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { RuleTester } = require("eslint");
const { join } = require("path");

const { readExample } = require("../../utils/read-example");
const rule = require("./no-ambiguity-target");

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
});

const readExampleForTheRule = (name) => ({
code: readExample(__dirname, name),
filename: join(__dirname, "examples", name),
});

ruleTester.run("effector/no-ambiguity-target.js.test", rule, {
valid: ["correct-example-issue-133.js"].map(readExampleForTheRule),

invalid: [],
});

0 comments on commit e0ac240

Please sign in to comment.