Merge pull request #17660 from knewbury01/knewbury01/improve-quality-java-set

Remove unnecessary query
This commit is contained in:
Anders Schack-Mulligen
2025-08-25 08:37:02 +02:00
committed by GitHub
4 changed files with 4 additions and 66 deletions

View File

@@ -1,8 +0,0 @@
public class Cart {
// AVOID: Empty statement
List<Item> items = new ArrayList<Cart>();;
public void applyDiscount(float discount) {
// AVOID: Empty statement as loop body
for (int i = 0; i < items.size(); items.get(i++).applyDiscount(discount));
}
}

View File

@@ -1,39 +0,0 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>An <em>empty statement</em> is a single semicolon <code>;</code> that does not
terminate another statement. Such a statement hinders readability and has no effect on its own.</p>
</overview>
<recommendation>
<p>Avoid empty statements. If a loop is intended to have an empty body, it is better
to mark that fact explicitly by using a pair of braces <code>{}</code> containing an explanatory comment
for the body, rather than a single semicolon.</p>
</recommendation>
<example>
<p>In the following example, there is an empty statement on line 3, where an additional semicolon is
used. On line 6, the <code>for</code> statement has an empty body because the condition is
immediately followed by a semicolon. In this case, it is better to include a pair of braces <code>{}</code> containing
an explanatory comment for the body instead.
</p><sample src="EmptyStatement.java" />
</example>
<references>
<li>
Help - Eclipse Platform:
<a href="https://help.eclipse.org/2020-12/advanced/content.jsp?topic=/org.eclipse.jdt.doc.user/reference/preferences/java/compiler/ref-preferences-errors-warnings.htm">Java Compiler Errors/Warnings Preferences</a>.
</li>
</references>
</qhelp>

View File

@@ -1,19 +0,0 @@
/**
* @name Empty statement
* @description An empty statement hinders readability.
* @kind problem
* @problem.severity recommendation
* @precision low
* @id java/empty-statement
* @tags maintainability
* useless-code
*/
import java
from EmptyStmt empty, string action
where
if exists(LoopStmt l | l.getBody() = empty)
then action = "turned into '{}'"
else action = "deleted"
select empty, "This empty statement should be " + action + "."

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Removed the `java/empty-statement` query that was subsumed by the `java/empty-block` query.