Skip to content

abbreviation-in-name

Javastyleno fixdefault: offjava/google

Reports a name with two or more capital letters in a row (XMLParser), for type, method, parameter, field and local variable names that match the names option. Names that match ignored (constants and overridden methods by default) are not reported. With an empty names the rule checks nothing.

A run of capitals hides where one word ends and the next starts: XMLHTTPRequest does not show if it is XML HTTP or XMLH TTP, and tools that split names into words get it wrong. Treating an abbreviation as a word (XmlHttpRequest) keeps the name readable and its camel case regular.

To fix, write the abbreviation as a word: XmlParser.

Reported
class XMLParser {
static final int MAX_SIZE = 1;
int fooBAR;
int goodName;
int endsWithB;
void getURL(int httpID) {
int myURL = 1;
int fine = 2;
}
...
java:
lint:
rules:
abbreviation-in-name:
level: warn # off (default), warn, error
options:
names: ""
ignored: "^.*$"
Option Type Default Description
names string "" Regular expression a type, method, parameter, field or local variable name must match; empty: not checked.
ignored string "^.*$" Regular expression matched for the names that are left out (constants, overridden methods): every name by default.

Enabled by the presets: java/google.

Suppress one line with sudsy-disable-next-line abbreviation-in-name in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
checkstyle AbbreviationAsWordInName partial Only more than one capital in a row; no allowed length or ignore options.