-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify rule S115: Extend LaYC content (#3199)
- Loading branch information
1 parent
f45132d
commit e12217f
Showing
17 changed files
with
204 additions
and
60 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
First, familiarize yourself with the particular naming convention of the project | ||
in question. | ||
Then, update the name of the constant to match the convention, as well as all | ||
usages of the name. | ||
For many IDEs, you can use built-in renaming and refactoring features to update | ||
all usages of a constant at once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Constants should be named consistently to communicate intent and improve | ||
maintainability. | ||
Rename your constants to follow your project's naming convention to address this | ||
issue. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This rule checks that all constant names match a given regular expression. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Ignoring the naming convention for constants makes the code less readable since | ||
constants and variables are harder to tell apart. | ||
Code that is hard to understand is also difficult to maintain between different | ||
team members. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Or, in the case of primitive constants, that accessing the constant is | ||
thread-safe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Constants are variables whose value does not change during the runtime of a | ||
program after initialization. | ||
Oftentimes, constants are used in multiple locations across different | ||
subroutines. | ||
|
||
It is important that the names of constants follow a consistent and easily | ||
recognizable pattern. | ||
This way, readers immediately understand that the referenced value does not | ||
change, which simplifies debugging. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,82 @@ | ||
include::../common/introduction.adoc[] | ||
|
||
== Why is this an issue? | ||
|
||
include::../description.adoc[] | ||
include::../common/why-is-this-an-issue.adoc[] | ||
|
||
include::../common/why-is-this-an-issue-thread-safety.adoc[] | ||
|
||
include::../common/rule-behaviour.adoc[] | ||
|
||
=== What is the potential impact? | ||
|
||
include::../common/what-is-the-potential-impact.adoc[] | ||
|
||
== How to fix it | ||
|
||
include::../common/how-to-fix-it.adoc[] | ||
|
||
=== Noncompliant code example | ||
=== Code examples | ||
|
||
With the default regular expression ``++^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$++``: | ||
==== Noncompliant code example | ||
|
||
[source,java] | ||
The following example assumes that constant names should match the default | ||
regular expression ``++^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$++``: | ||
|
||
[source,java,diff-id=1,diff-type=noncompliant] | ||
---- | ||
public class MyClass { | ||
public static final int first = 1; | ||
public static final float pi = 3.14159f; // Noncompliant: Constant is not capitalized | ||
void myMethod() { | ||
System.out.println(pi); | ||
} | ||
} | ||
public enum MyEnum { | ||
first; | ||
optionOne, // Noncompliant | ||
optionTwo; // Noncompliant | ||
} | ||
---- | ||
|
||
=== Compliant solution | ||
==== Compliant solution | ||
|
||
[source,java] | ||
[source,java,diff-id=1,diff-type=compliant] | ||
---- | ||
public class MyClass { | ||
public static final int FIRST = 1; | ||
public static final float PI = 3.14159f; | ||
void myMethod() { | ||
System.out.println(PI); | ||
} | ||
} | ||
public enum MyEnum { | ||
FIRST; | ||
OPTION_ONE, | ||
OPTION_TWO; | ||
} | ||
---- | ||
|
||
== Resources | ||
|
||
=== External coding guidelines | ||
|
||
* https://google.github.io/styleguide/javaguide.html#s5.2.4-constant-names[The Google Java Style Guide on Constant Names]. | ||
|
||
ifdef::env-github,rspecator-view[] | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
include::../common/message.adoc[] | ||
|
||
include::../parameters.adoc[] | ||
include::../common/parameters.adoc[] | ||
|
||
''' | ||
== Comments And Links | ||
(visible only on this page) | ||
|
||
include::../comments-and-links.adoc[] | ||
include::../common/comments-and-links.adoc[] | ||
|
||
endif::env-github,rspecator-view[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.