Skip to content

Introduce EmptyString and StringIdentity Refaster rules#1755

Merged
rickie merged 2 commits intoPicnicSupermarket:masterfrom
timtebeek:empty-string-literal
Jul 16, 2025
Merged

Introduce EmptyString and StringIdentity Refaster rules#1755
rickie merged 2 commits intoPicnicSupermarket:masterfrom
timtebeek:empty-string-literal

Conversation

@timtebeek
Copy link
Contributor

@timtebeek timtebeek commented Jul 11, 2025

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @Stephan202's comment I'd say we can generalize this one right? 🤔

@timtebeek
Copy link
Contributor Author

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.

@Stephan202 Stephan202 force-pushed the empty-string-literal branch from 93997d6 to e544b14 Compare July 15, 2025 19:06
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😅.)

@Stephan202 Stephan202 added this to the 0.24.0 milestone Jul 15, 2025
@Stephan202 Stephan202 changed the title Add rule for converting new String("") to "" Introduce EmptyString and StringIdentity Refaster rules Jul 15, 2025
@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickie rickie merged commit 753060e into PicnicSupermarket:master Jul 16, 2025
16 checks passed
@timtebeek timtebeek deleted the empty-string-literal branch July 16, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Avoid calling new String with String literal as argument

3 participants