rspec/rules/S3008/java/rule.adoc

71 lines
1.7 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
The Java Language Specification defines a set of rules called naming conventions that apply to Java programs.
These conventions provide recommendations for naming packages, classes, methods, and variables.
2021-04-28 16:49:39 +02:00
By following shared naming conventions, teams can collaborate more efficiently.
This rule checks that static non-final field names match a provided regular expression.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
The default regular expression applied by the rule is `^[a-z][a-zA-Z0-9]*$`:
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
private static String foo_bar; // Noncompliant
2021-04-28 16:49:39 +02:00
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
public class MyClass {
2021-04-28 16:49:39 +02:00
private static String fooBar;
}
----
== Resources
* https://www.oreilly.com/library/view/java-8-pocket/9781491901083/ch01.html[O'Reilly - Java 8 in pocket - Naming Conventions]
* https://www.educative.io/answers/what-are-the-naming-conventions-in-java[Educative - Naming conventions in Java]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Rename this field "XXX" to match the regular expression ${format}.
=== Parameters
.format
****
----
^[a-z][a-zA-Z0-9]*$
----
Regular expression used to check the field names against.
****
'''
== Comments And Links
(visible only on this page)
=== on 9 Jun 2015, 13:45:21 Ann Campbell wrote:
FYI [~alexandre.gigleux] I've made a few updates.
=== on 9 Jun 2015, 13:48:13 Ann Campbell wrote:
Note for Java: same as RSPEC-116 but for static non-final fields
=== on 12 Jun 2015, 16:04:59 Ann Campbell wrote:
CodePro: Static Field Naming Convention
endif::env-github,rspecator-view[]