rspec/rules/S117/java/rule.adoc

104 lines
2.6 KiB
Plaintext
Raw Normal View History

:identifier_capital_plural: Local variables and method parameters
:identifier: local variable and method parameter
:identifier_plural: local variables and method parameters
:identifier_or: local variable or method parameter
:regex: ^[a-z][a-zA-Z0-9]*$
include::../introduction.adoc[]
2020-06-30 10:16:44 +02:00
include::../why-is-this-an-issue.adoc[]
2020-06-30 10:16:44 +02:00
include::../what-is-the-potential-impact.adoc[]
=== Exceptions
Loop counters are ignored by this rule.
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 10:16:44 +02:00
----
for (int i_1 = 0; i_1 < limit; i_1++) { // Compliant
// ...
2020-06-30 10:16:44 +02:00
}
----
as well as one-character ``++catch++`` variables:
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 10:16:44 +02:00
----
try {
//...
} catch (Exception e) { // Compliant
2020-06-30 10:16:44 +02:00
}
----
include::../how-to-fix-it.adoc[]
2020-06-30 10:16:44 +02:00
=== Code examples
==== Noncompliant code example
With the default regular expression ``{regex}``:
[source,java,diff-id=1,diff-type=noncompliant]
2020-06-30 10:16:44 +02:00
----
public class MyClass {
public void doSomething(int myParam) {
int LOCAL; // Noncompliant
// ...
}
2020-06-30 10:16:44 +02:00
}
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
2020-06-30 10:16:44 +02:00
----
public class MyClass {
public void doSomething(int my_param) {
int local;
// ...
}
2020-06-30 10:16:44 +02:00
}
----
== Resources
=== Documentation
* Oracle - https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html[Java SE Naming Conventions]
* Geeksforgeeks - https://www.geeksforgeeks.org/java-naming-conventions/[Java Naming Conventions]
* Wikipedia - https://en.wikipedia.org/wiki/Naming_convention_(programming)[Naming Convention (programming)]
=== Related rules
* S100 - Method names should comply with a naming convention
* S101 - Class names should comply with a naming convention
* S114 - Interface names should comply with a naming convention
* S115 - Constant names should comply with a naming convention
* S116 - Field names should comply with a naming convention
* S118 - Abstract class names should comply with a naming convention
* S119 - Type parameter names should comply with a naming convention
* S120 - Package names should comply with a naming convention
* S1312 - Loggers should be "private static final" and should share a naming convention
* S3008 - Static non-final field names should comply with a naming convention
* S3577 - Test classes should comply with a naming convention
* S3578 - Test methods should comply with a naming convention
* S4174 - Local constants should follow naming conventions for constants
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../parameters.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]