rspec/rules/S2039/java/rule.adoc

65 lines
1.2 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
The default access level modifier may be intentional; in that case, this rule can report false positives.
=== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
class Ball {
String color = "red"; // Noncompliant
}
enum A {
B;
int a; // Noncompliant
}
----
=== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
class Ball {
private String color = "red"; // Compliant
}
enum A {
B;
private int a; // Compliant
}
----
=== Exceptions
* Members with comments containing the word `modifier` are ignored, as it indicates the modifier is intentionally omitted.
* Members annotated with the `@VisibleForTesting` annotation are ignored, as it indicates that visibility has been purposely relaxed to make the code testable.
[source,java]
----
class Cone {
@VisibleForTesting
Logger logger; // Compliant
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]