Skip to content

Commit

Permalink
Make variable naming conventions skip unnamed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed May 11, 2024
1 parent e5f55c0 commit f1b2cda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ private ModifierOwner getModifierOwnerParent() {
return (ModifierOwner) parent;
}

/**
* Return true if this variable has no name. The name is then equal to {@code "_"}.
* A variable declaration with this name does not actually declare a variable in
* the current scope.
*/
public boolean isUnnamed() {
return "_".equals(name);
}

/** Returns the name of the variable. */
public String getName() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public FormalParameterNamingConventionsRule() {

@Override
public Object visit(ASTVariableId node, Object data) {
if (node.isUnnamed()) {
// unnamed variables do not have to match the regexes.
return null;
}

if (node.isLambdaParameter()) {
checkMatches(node, node.isTypeInferred() ? lambdaParamRegex : explicitLambdaParamRegex, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public LocalVariableNamingConventionsRule() {

@Override
public Object visit(ASTVariableId node, Object data) {
if (node.isUnnamed()) {
// unnamed variables do not have to match the regexes.
return null;
}

if (node.isExceptionBlockParameter()) {
checkMatches(node, exceptionBlockParameterRegex, data);
Expand Down

0 comments on commit f1b2cda

Please sign in to comment.