-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor (rule/receiver-naming): replace AST walker by iteration over declarations #1169
Conversation
if name == "_" { | ||
failures = append(failures, lint.Failure{ | ||
Node: decl, | ||
Confidence: 1, | ||
Category: "naming", | ||
Failure: "receiver name should not be an underscore, omit the name if it is unused", | ||
}) | ||
continue | ||
} | ||
|
||
if name == "this" || name == "self" { | ||
failures = append(failures, lint.Failure{ | ||
Node: decl, | ||
Confidence: 1, | ||
Category: "naming", | ||
Failure: `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`, | ||
}) | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a switch
You are checking the same variable three times, also it would allow to remove the two continue, as they will be useless
if name == "_" { | |
failures = append(failures, lint.Failure{ | |
Node: decl, | |
Confidence: 1, | |
Category: "naming", | |
Failure: "receiver name should not be an underscore, omit the name if it is unused", | |
}) | |
continue | |
} | |
if name == "this" || name == "self" { | |
failures = append(failures, lint.Failure{ | |
Node: decl, | |
Confidence: 1, | |
Category: "naming", | |
Failure: `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`, | |
}) | |
continue | |
} | |
switch name { | |
case "_": | |
failures = append(failures, lint.Failure{ | |
Node: decl, | |
Confidence: 1, | |
Category: "naming", | |
Failure: "receiver name should not be an underscore, omit the name if it is unused", | |
}) | |
case "this", "self": | |
failures = append(failures, lint.Failure{ | |
Node: decl, | |
Confidence: 1, | |
Category: "naming", | |
Failure: `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`, | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch on name will cope with the first two conditions for failure, the other conditions are not just on name thus IMO, adding a switch will not help in clarity (further, even with a switch continue
is needed after adding a failure to do not evaluate the not-in-the-switch conditions)
Simplifies receiver-naming rule by replacing AST walker by an iteration over global declarations