Skip to content

Commit

Permalink
Fix false-positive in enforce-store-naming-convention (#137)
Browse files Browse the repository at this point in the history
* Add test case

* Fix bug
  • Loading branch information
igorkamyshev committed Mar 29, 2023
1 parent c2ce25a commit 1bf87cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ module.exports = {
continue;
}

const parentNode = traverseParentByType(node, "VariableDeclarator", [
"Program",
]);
const parentNode = traverseParentByType(node, "VariableDeclarator", {
stopOnTypes: ["Program", "BlockStatement"],
});

const resultSavedInVariable =
parentNode?.type === "VariableDeclarator";
Expand Down Expand Up @@ -145,9 +145,9 @@ module.exports = {
if (
STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
) {
const parentNode = traverseParentByType(node, "VariableDeclarator", [
"Program",
]);
const parentNode = traverseParentByType(node, "VariableDeclarator", {
stopOnTypes: ["Program", "BlockStatement"],
});

const resultSavedInVariable =
parentNode?.type === "VariableDeclarator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ruleTester.run("effector/enforce-store-naming-convention-prefix.test", rule, {
"correct-store-naming-in-domain.js",
"correct-examples-issue-23.js",
"correct-examples-issue-128.js",
"correct-examples-issue-136.js",
"correct-store-naming-with-handlers.js",
"correct-store-naming-in-domain-with-handlers.js",
"correct-factory.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Examples were found in production code-base with exception on 0.10.3
// https://github.com/igorkamyshev/eslint-plugin-effector/issues/136

import { combine, sample } from "effector";
import { modelFactory } from "effector-factorio";

export const factory = modelFactory(() => {
sample({
clock: combine([createStore("")]),
fn: ([fieldType, customFieldId]) => customFieldId || fieldType,
target: createStore(""),
});

return {};
});

0 comments on commit 1bf87cb

Please sign in to comment.