Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2305: do not apply UnnecessaryBlock for the ECMAScript (JavaScript) destructuring assignments #4829

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ be misleading. Considering removing this unnecessary Block.
<value>
<![CDATA[
//Block[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)]
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)
and not(ancestor::VariableDeclarator) and not(ancestor::ImportDeclaration)]
|
//Scope[not(parent::FunctionNode or parent::IfStatement or parent::ForLoop or parent::ForInLoop
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)]
or parent::WhileLoop or parent::DoLoop or parent::TryStatement or parent::CatchClause)
and not(ancestor::VariableDeclarator) and not(ancestor::ImportDeclaration)]
]]>
</value>
</property>
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes in this file completely

Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;

import net.sourceforge.pmd.testframework.PmdRuleTst;

class UnnecessaryBlockTest extends PmdRuleTst {
// no additional unit tests
public class UnnecessaryBlockTest extends PmdRuleTst {
@Override
public void setUp() {
// Set up any required configurations or resources before running the tests
}


public void testUnnecessaryBlockInImportStatement() {
String code = "import { foo } from 'bar';\n" +
"{\n" +
" // Unnecessary block\n" +
"}\n";

// Assert that the PMD rule does not flag the unnecessary block within import statement
addSourceCodeTest(code, 0);
}

public void testUnnecessaryBlockInDestructuringAssignment() {
String code = "const { a, b } = obj;\n" +
"{\n" +
" // Unnecessary block\n" +
"}\n";

// Assert that the PMD rule does not flag the unnecessary block within destructuring assignment
addSourceCodeTest(code, 0);
}
jsotuyod marked this conversation as resolved.
Show resolved Hide resolved

}