switch statement cleanup (#148382)

This PR is step 12 in the journey to solve issue #136139 and make the
entire Flutter repo more readable.

Most of it involves implementing switch expressions, and there's also a
few other random things that I wanted to clean up a bit.
This commit is contained in:
Nate
2024-05-16 18:16:06 -06:00
committed by GitHub
parent c4ad1dc1e9
commit fa9992eff6
39 changed files with 301 additions and 529 deletions

View File

@@ -385,23 +385,12 @@ class StartContext extends Context {
/// Determine this release's version number from the [lastVersion] and the [incrementLetter].
Version calculateNextVersion(Version lastVersion, ReleaseType releaseType) {
late final Version nextVersion;
switch (releaseType) {
case ReleaseType.STABLE_INITIAL:
nextVersion = Version(
x: lastVersion.x,
y: lastVersion.y,
z: 0,
type: VersionType.stable,
);
case ReleaseType.STABLE_HOTFIX:
nextVersion = Version.increment(lastVersion, 'z');
case ReleaseType.BETA_INITIAL:
nextVersion = Version.fromCandidateBranch(candidateBranch);
case ReleaseType.BETA_HOTFIX:
nextVersion = Version.increment(lastVersion, 'n');
}
return nextVersion;
return switch (releaseType) {
ReleaseType.STABLE_INITIAL => Version(x: lastVersion.x, y: lastVersion.y, z: 0, type: VersionType.stable),
ReleaseType.STABLE_HOTFIX => Version.increment(lastVersion, 'z'),
ReleaseType.BETA_INITIAL => Version.fromCandidateBranch(candidateBranch),
ReleaseType.BETA_HOTFIX || _ => Version.increment(lastVersion, 'n'),
};
}
/// Ensures the branch point [candidateBranch] and `master` has a version tag.