Skip to content

Commit

Permalink
refactor: some fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanSilke committed Dec 27, 2023
1 parent ac9a9b6 commit 436080e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 0 additions & 2 deletions packages/eslint-config/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* config/eslint/index.js */

const projectName = "salute-rules";

const fs = require("fs");
Expand Down
18 changes: 9 additions & 9 deletions packages/eslint-config/rules/no-redundant-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ module.exports = {
meta: {
type: null, // `problem`, `suggestion`, or `layout`
docs: {
description: "asdf",
recommended: false,
url: null, // URL to the documentation page for this rule
description: "This forbid synchronous setting of state in effect to prevent redundant commits",
recommended: true,
url: "https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes",
},
fixable: null, // Or `code` or `whitespace`
schema: [], // Add a schema if the rule has options
Expand All @@ -109,16 +109,16 @@ module.exports = {
) {
context.report({
node,
message: "Don't use synchronous state settlers in effects",
message: "Avoid using synchronous state setters within effects",
});
}

// checking is it is useEffect call
// Checking if the invoked function is useEffect
if (node.callee.type === "Identifier" && node.callee.name === "useEffect" && currentComponent) {
isInUseEffect = true;
}

// checking is it is useState call
// Checking if the function call is useState
if (node.callee.type === "Identifier" && node.callee.name === "useState" && currentComponent) {
const isDestructuringDeclarator =
node.parent &&
Expand Down Expand Up @@ -160,7 +160,7 @@ module.exports = {
isInUseEffect = false;
}

// Current implementation don't take into account nested setTimeout
// The current implementation does not consider nested setTimeout calls.
if (
node.callee.type === "Identifier" &&
(node.callee.name === "setTimeout" || node.callee.name === "setInterval")
Expand All @@ -186,7 +186,7 @@ module.exports = {
const name = getFunctionName(node);

if (name && isComponentName(name)) {
// We doesn't take into account nested component declaration
// We doesn't consider nested component declaration
currentComponent = node;
}
},
Expand All @@ -206,7 +206,7 @@ module.exports = {
const name = getFunctionName(node);

if (name && isComponentName(name)) {
// We doesn't take into account nested component declaration
// We doesn't consider nested component declaration
currentComponent = node;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-config/rules/no-redundant-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const tests = {
return <Page/>
}
`,
errors: [{ message: "Don't use synchronous state settlers in effects" }],
errors: [{ message: "Avoid using synchronous state setters within effects" }],
},
{
code: `
Expand All @@ -127,7 +127,7 @@ const tests = {
return <Page/>
}
`,
errors: [{ message: "Don't use synchronous state settlers in effects" }],
errors: [{ message: "Avoid using synchronous state setters within effects" }],
},
{
code: `
Expand All @@ -146,7 +146,7 @@ const tests = {
return <Loader />;
}
`,
errors: [{ message: "Don't use synchronous state settlers in effects" }],
errors: [{ message: "Avoid using synchronous state setters within effects" }],
},
{
code: `
Expand All @@ -165,7 +165,7 @@ const tests = {
return <Loader />;
}
`,
errors: [{ message: "Don't use synchronous state settlers in effects" }],
errors: [{ message: "Avoid using synchronous state setters within effects" }],
},
],
};
Expand Down

0 comments on commit 436080e

Please sign in to comment.