Skip to content

Commit

Permalink
altered logic
Browse files Browse the repository at this point in the history
  • Loading branch information
imjordanxd committed Sep 15, 2024
1 parent d6a6fb4 commit 825c2fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
10 changes: 4 additions & 6 deletions lib/rules/no-useless-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict";

const astUtils = require("./utils/ast-utils");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -185,14 +187,10 @@ module.exports = {
{
messageId: "removeConstructor",
*fix(fixer) {
const previousToken = context.sourceCode.getTokenBefore(node);
const nextToken = context.sourceCode.getTokenAfter(node);
const addSemiColon = nextToken.type === "Punctuator" && nextToken.value === "[" && astUtils.needsPrecedingSemicolon(context.sourceCode, node);

if (previousToken && previousToken.type !== "Punctuator" && nextToken && nextToken.type !== "Punctuator") {
yield fixer.insertTextAfter(previousToken, ";");
}

yield fixer.remove(node);
yield fixer.replaceText(node, addSemiColon ? ";" : "");
}
}
]
Expand Down
11 changes: 0 additions & 11 deletions tests/lib/rules/no-useless-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,6 @@ ruleTester.run("no-useless-constructor", rule, {
}]
}]
},
{
code: "class A {\nfoo = 5\nconstructor() {}\nbar() {}\n}",
languageOptions: { ecmaVersion: 2022 },
errors: [{
...error,
suggestions: [{
messageId: "removeConstructor",
output: "class A {\nfoo = 5;\n\nbar() {}\n}"
}]
}]
},
{
code: "class A { foo = \"bar\"\nconstructor() { }\n[0]() { } }",
languageOptions: { ecmaVersion: 2022 },
Expand Down

0 comments on commit 825c2fc

Please sign in to comment.