Skip to content

Commit

Permalink
Issue checkstyle#12409: Inconsistent allowedAbbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
arinmodi committed Nov 29, 2022
1 parent 690031b commit ed41342
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 9 deletions.
Expand Up @@ -297,6 +297,38 @@
* }
* </pre>
* <p>
* To configure to check variables, enforce
* no abbreviations (essentially camel case) except for
* words like 'ORDERS', 'OBSERVATION', 'UNDERSCORE', 'TEST'.
* </p>
* <p>Configuration:</p>
* <pre>
* &lt;module name="AbbreviationAsWordInName"&gt;
* &lt;property name="allowedAbbreviations" value="ORDER, OBSERVATION, UNDERSCORE, TEST"/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* public class InputAbbreviationAsWordInNameType7 {
* void getTEST() {
* } // OK
*
* void getORDER_OBSERVATION() {} // OK
*
* void getUNDERSCORE() {} // OK
*
* void getTEST_OBSERVATION() {} // OK
*
* void getTEST_UNDERSCORE() {} // OK
*
* void getORDER() {} // OK
*
* void getOBSERVATION() {} // OK
*
* void getORDER_UNDERSCORE() {} // OK
* }
* </pre>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
* </p>
* <p>
Expand Down Expand Up @@ -583,7 +615,13 @@ private String getDisallowedAbbreviation(String str) {
else if (abbrStarted) {
abbrStarted = false;

final int endIndex = Character.isLetterOrDigit(symbol) ? index-1 : index;
final int endIndex;
if (Character.isLetterOrDigit(symbol)) {
endIndex = index - 1;
}
else {
endIndex = index;
}
result = getAbbreviationIfIllegal(str, beginIndex, endIndex);
if (result != null) {
break;
Expand Down
Expand Up @@ -10,19 +10,19 @@

public class InputAbbreviationAsWordInNameType7 {
void getTEST() {
}
} // OK

void getORDER_OBSERVATION() {}
void getORDER_OBSERVATION() {} // ok

void getUNDERSCORE() {}
void getUNDERSCORE() {} // ok

void getTEST_OBSERVATION() {}
void getTEST_OBSERVATION() {} // ok

void getTEST_UNDERSCORE() {}
void getTEST_UNDERSCORE() {} // ok

void getORDER() {}
void getORDER() {} // ok

void getOBSERVATION() {}
void getOBSERVATION() {} // ok

void getORDER_UNDERSCORE() {}
void getORDER_UNDERSCORE() {} // ok
}
32 changes: 32 additions & 0 deletions src/xdocs/config_naming.xml
Expand Up @@ -344,6 +344,38 @@ public class MyClass {
public final int customerID = 2; // violation
public static int nextID = 3; // OK, ignored
public static final int MAX_ALLOWED = 4; // violation
}
</source>
<p>
To configure to check variables, enforce
no abbreviations (essentially camel case) except for
words like 'ORDERS', 'OBSERVATION', 'UNDERSCORE', 'TEST'.
</p>
<p>Configuration:</p>
<source>
&lt;module name="AbbreviationAsWordInName"&gt;
&lt;property name="allowedAbbreviations" value="ORDER, OBSERVATION, UNDERSCORE, TEST"/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<source>
public class InputAbbreviationAsWordInNameType7 {
void getTEST() {
} // OK

void getORDER_OBSERVATION() {} // OK

void getUNDERSCORE() {} // OK

void getTEST_OBSERVATION() {} // OK

void getTEST_UNDERSCORE() {} // OK

void getORDER() {} // OK

void getOBSERVATION() {} // OK

void getORDER_UNDERSCORE() {} // OK
}
</source>
</subsection>
Expand Down

0 comments on commit ed41342

Please sign in to comment.