Introduce EmptyString and StringIdentity Refaster rules#1755
Introduce EmptyString and StringIdentity Refaster rules#1755rickie merged 2 commits intoPicnicSupermarket:masterfrom
EmptyString and StringIdentity Refaster rules#1755Conversation
|
Looks good. No mutations were possible for these changes. |
rickie
left a comment
There was a problem hiding this comment.
Based on @Stephan202's comment I'd say we can generalize this one right? 🤔
|
We could; that would pull it into potentially breaking. You all are a little more opinionated, and I'd be fine with that as well, but figured start small and safe. Can adjust if desired. |
93997d6 to
e544b14
Compare
Stephan202
left a comment
There was a problem hiding this comment.
I rebased and added a commit with the suggested generalization, but also introduced an alternative variant to the originally suggested rule. 😄
Suggested commit message:
Introduce `EmptyString` and `StringIdentity` Refaster rules (#1755)
| } | ||
|
|
||
| /** Prefer empty string literals over creating new empty String objects. */ | ||
| static final class EmptyStringLiteral { |
There was a problem hiding this comment.
We don't really have a good heuristic for the ordering of rules inside a rules collection, but roughly speaking right now the simplest / "most fundamental" go at the top. Let me move it there.
(Perhaps at some point we'll just automatically order them lexicographically 😅.)
new String("") to ""EmptyString and StringIdentity Refaster rules
|
Looks good. No mutations were possible for these changes. |
As discussed on
new Stringwith String literal as argument openrewrite/rewrite-static-analysis#620 (comment)