Recipe to remove underscores in private field names
What problem are you trying to solve?
Apply modern code standards.
I think it used to be a bit of a common practice to denote private class fields with names which either started with or ended with underscores. While technically allowed, I don't think this is mainstream in Java. Thus it makes sense to have a recipe to rename the fields not to have these _ prefixes/suffixes.
Describe the situation before applying the recipe
public class ParseLocation {
private String _ruleName;
public String getRuleName() {
return _ruleName;
}
public void setRuleName(String ruleName) {
_ruleName = ruleName;
}
}
Describe the situation after applying the recipe
public class ParseLocation {
private String ruleName;
public String getRuleName() {
return ruleName;
}
public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}
}
Any additional context
- When making the changes, beware of name clashes. Even visible in the simple setter example above.
- For this reason, not marking this is a good-first-issue.
OSS repro
- leading underscores: https://github.com/apache/pinot/blob/a02253d671d7781acc16b81628e51bd11a3005a0/pinot-spi/src/main/java/org/apache/pinot/spi/utils/builder/TableConfigBuilder.java#L90-L140
- trailing underscores: https://github.com/rstudio/rstudio/blob/0baa88b0d03238603c1adaa1fe96241cd54b1ba7/src/gwt/src/org/rstudio/studio/client/rmarkdown/events/RenderRmdEvent.java#L120-L129
Hi @greg-at-moderne,
I would like to work on this issue. Could you please assign it to me? Thank you!
hi @jhl221123 welcome back and thanks for the offer to help! Feel free to open up a draft PR containing just the tests and then we'll assign the issue to you. 🙏🏻
#643 looks like a good start.
Hi, would love to work on this issue , can you assign it to me?
Hi @Shiven04123, thank you for your interest in contributing to this issue.
I'm the one currently assigned to it and have an open pull request at #643. However, it's proving to be a bit more challenging than I first anticipated, which is why it's taking some time. While I do intend to continue my work, I believe the most important thing is that we resolve this issue promptly. So please feel free to build upon my PR if you have better ideas.
Yes the open pull request is here; if you see any areas for improvement feel free to chime in on the PR:
- https://github.com/openrewrite/rewrite-static-analysis/pull/643/