Skip to content

Commit

Permalink
Enable nullable (#2392)
Browse files Browse the repository at this point in the history
* Enable nullable

* Several nullable fixes

* Fix dot-dsl

* calculator-conundrum: fix nullable

* developer-privileges: fix nullable

* face-id2: fix

* zebra-puzzle: fix

* pov: fix

* zipper: fix

* tournament: fix

* simple-linked-list: fix

* sgf-parsing: fix

* rest-api: fix

* react: fix

* robot-name: fix

* say: fix

* satellite: fix

* change: fix

* custom-set: fix

* grep: fix

* binary-search-tree: fix

* linked-list: fix

* alphametics: fix

* hangman: fix

* wizards-and-warriors-2: fix

* remote-control-cleanup: fix

* land-grab-in-space: fix

* instruments-of-texas: fix

* markdown: fix

* Dont remove nullable in new exercise

* More fixes

* remote-control: fix

[no important files changed]
  • Loading branch information
ErikSchierboom committed Feb 18, 2025
1 parent 0deaef3 commit 9003883
Show file tree
Hide file tree
Showing 219 changed files with 439 additions and 247 deletions.
5 changes: 0 additions & 5 deletions bin/add-practice-exercise.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ $project = "${exerciseDir}/${ExerciseName}.csproj"
& dotnet new xunit --force -lang "C#" --target-framework-override net9.0 -o $exerciseDir -n $ExerciseName
& dotnet sln exercises/Exercises.sln add $project

# Cleanup project file
[xml]$projectXml = Get-Content "${project}"
$projectXml.Project.PropertyGroup.RemoveChild($projectXml.Project.PropertyGroup.SelectSingleNode("Nullable"))
$projectXml.Save("${project}")

# Update project packages
& dotnet remove $project package coverlet.collector
& dotnet add $project package Exercism.Tests --version 0.1.0-beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/bird-watcher/BirdWatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/calculator-conundrum/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public static class SimpleCalculator
{
public static string Calculate(int operand1, int operand2, string operation)
public static string Calculate(int operand1, int operand2, string? operation)
{
int result;
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public static class SimpleCalculator
{
public static string Calculate(int operand1, int operand2, string operation)
public static string Calculate(int operand1, int operand2, string? operation)
{
throw new NotImplementedException("Please implement the SimpleCalculator.Calculate() method");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/cars-assemble/CarsAssemble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions exercises/concept/developer-privileges/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class Authenticator
//**** please do not modify the FacialFeatures class ****
public class FacialFeatures
{
public string EyeColor { get; set; }
public decimal PhiltrumWidth { get; set; }
public required string EyeColor { get; set; }
public required decimal PhiltrumWidth { get; set; }
}

//**** please do not modify the Identity class ****
public class Identity
{
public string Email { get; set; }
public FacialFeatures FacialFeatures { get; set; }
public IList<string> NameAndAddress { get; set; }
public required string Email { get; set; }
public required FacialFeatures FacialFeatures { get; set; }
public required IList<string> NameAndAddress { get; set; }
}
10 changes: 5 additions & 5 deletions exercises/concept/developer-privileges/DeveloperPrivileges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class Authenticator
//**** please do not modify the FacialFeatures class ****
public class FacialFeatures
{
public string EyeColor { get; set; }
public decimal PhiltrumWidth { get; set; }
public required string EyeColor { get; set; }
public required decimal PhiltrumWidth { get; set; }
}

//**** please do not modify the Identity class ****
public class Identity
{
public string Email { get; set; }
public FacialFeatures FacialFeatures { get; set; }
public IList<string> NameAndAddress { get; set; }
public required string Email { get; set; }
public required FacialFeatures FacialFeatures { get; set; }
public required IList<string> NameAndAddress { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/elons-toys/ElonsToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/faceid-2/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected bool Equals(FacialFeatures other)
return EyeColor == other.EyeColor && PhiltrumWidth.Equals(other.PhiltrumWidth);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
Expand Down Expand Up @@ -44,7 +44,7 @@ protected bool Equals(Identity other)
return Email == other.Email && Equals(FacialFeatures, other.FacialFeatures);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
Expand Down
1 change: 1 addition & 0 deletions exercises/concept/faceid-2/Faceid2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/hyperia-forex/HyperiaForex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/instruments-of-texas/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public string TestMultiplication(int x, int y)
}
catch (CalculationException cex) when (cex.Operand1 < 0 && cex.Operand2 < 0)
{
return "Multiply failed for negative operands. " + cex.InnerException.Message;
return "Multiply failed for negative operands. " + cex.InnerException!.Message;
}
catch (CalculationException cex)
{
return "Multiply failed for mixed or positive operands. " + cex.InnerException.Message;
return "Multiply failed for mixed or positive operands. " + cex.InnerException!.Message;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
11 changes: 4 additions & 7 deletions exercises/concept/land-grab-in-space/LandGrabInSpaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ public void GetLongestSideReverseInsertionOrder()
private Plot CreatePlot(Coord coord1, Coord coord2, Coord coord3, Coord coord4)
{
Type plotType = typeof(Plot);
Type[] types = new Type[] { typeof(Coord), typeof(Coord), typeof(Coord), typeof(Coord) };
ConstructorInfo constructorInfoObj = plotType.GetConstructor(types);
Type[] types = [typeof(Coord), typeof(Coord), typeof(Coord), typeof(Coord)];
ConstructorInfo? constructorInfoObj = plotType.GetConstructor(types);
if (constructorInfoObj != null)
{
return (Plot)constructorInfoObj.Invoke(new object[] { coord1, coord2, coord3, coord4 });
return (Plot)constructorInfoObj.Invoke([coord1, coord2, coord3, coord4]);
}

else
{
throw new InvalidOperationException("You need to implement a constructor for the struct Plot. The constructor must take 4 co-ordinates. No such constructor can be found.");
}
throw new InvalidOperationException("You need to implement a constructor for the struct Plot. The constructor must take 4 co-ordinates. No such constructor can be found.");
}
}
1 change: 1 addition & 0 deletions exercises/concept/log-analysis/LogAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/log-levels/LogLevels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/logs-logs-logs/LogsLogsLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/need-for-speed/NeedForSpeed.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/orm-in-one-go/OrmInOneGo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/parsing-log-files/ParsingLogFiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions exercises/concept/remote-control-cleanup/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS8618

public class RemoteControlCar
{
private enum SpeedUnits
Expand Down Expand Up @@ -95,3 +97,5 @@ private void SetSpeed(Speed speed)
currentSpeed = speed;
}
}

#pragma warning restore CS8618
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Drive()
DistanceTravelled += 10;
}

public int CompareTo(ProductionRemoteControlCar other)
public int CompareTo(ProductionRemoteControlCar? other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
Expand Down
Loading

0 comments on commit 9003883

Please sign in to comment.