rspec/rules/S3030/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

52 lines
1.4 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
Importing a class statically allows you to use its ``++public static++`` members without qualifying them with the class name. That can be handy, but if you import too many classes statically, your code can become confusing and difficult to maintain.
=== Noncompliant code example
With the default threshold value: 4
[source,java]
----
import static java.lang.Math.*;
import static java.util.Collections.*;
import static com.myco.corporate.Constants.*;
import static com.myco.division.Constants.*;
import static com.myco.department.Constants.*; // Noncompliant
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Reduce the number of "static" imports in this class from x to the maximum allowed y.
=== Parameters
.threshold
****
----
4
----
The maximum number of static imports allowed
****
'''
== Comments And Links
(visible only on this page)
=== on 5 May 2021, 23:43:52 Caleb Ciampaglia wrote:
Consider ignoring static imports of all capital letters (constants) when processing this rule.  It can be less confusing to statically import constants from other classes than to specify the class name first.  This is especially true when writing code that use Jooq (or other libraries) which regularly use constants for defining tables, columns, and other DB objects.
endif::env-github,rspecator-view[]