Skip to content

Commit

Permalink
fix sonarlint warnings and issues from review
Browse files Browse the repository at this point in the history
  • Loading branch information
floribe2000 committed Oct 14, 2023
1 parent 039ad41 commit 69866f7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace WoWsShipBuilder.Data.Generator.Test;

[AttributeUsage(AttributeTargets.Method)]
public class AssertionMethodAttribute : Attribute
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public partial record TestRecord : DataContainerBase
await CreateTest(source).RunAsync();
}

[AssertionMethod]
private static CSharpAnalyzerTest<DataElementAnalyzer, NUnitVerifier> CreateTest(string source)
{
const string baseClass = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace Test;
[DataContainer]
public partial record TestRecord : DataContainerBase
{
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "Test", ArgumentsTextKind = TextKind.LocalizationKey)]
[DataElementType(DataElementTypes.KeyValueUnit, UnitKey = "Test", ArgumentsTextKind = TextKind.AppLocalizationKey)]
public decimal {|SB1003:Prop1|} { get; set; }
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace WoWsShipBuilder.Data.Generator.Test.DataElementGeneratorTests;
[SuppressMessage("Maintainability", "S2699", Justification = "false-positive since sonarlint does not recognize custom CreateTest method")]
public partial class DataElementGeneratorTest
{
[AssertionMethod]
private static CSharpSourceGeneratorTest<DataElementGenerator.DataElementGenerator, NUnitVerifier> CreateTest(string source, string expected)
{
const string baseClass = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using WoWsShipBuilder.Data.Generator.PropertyChangedGenerator;

namespace WoWsShipBuilder.Data.Generator.Test.PropertyChangedGeneratorTests;

[TestFixture]
[SuppressMessage("Maintainability", "S2699", Justification = "false-positive since sonarlint does not recognize RunAsync method from generator test framework")]
public class PropertyChangedGeneratorTest
{
private const string AttributeClass = """
Expand Down
8 changes: 4 additions & 4 deletions WoWsShipBuilder.Data.Generator/Utilities/SourceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class SourceBuilder

private readonly StringBuilder sb;

private int indent;
private int currentIndent;

private LastAction lastAction;

Expand Down Expand Up @@ -141,13 +141,13 @@ private void BlockOpen(string? line = null)

private SourceBuilder DecreaseIndent()
{
--this.indent;
--this.currentIndent;
return this;
}

private SourceBuilder IncreaseIndent()

Check warning on line 148 in WoWsShipBuilder.Data.Generator/Utilities/SourceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Change return type to 'void'; not a single caller uses the returned value. (https://rules.sonarsource.com/csharp/RSPEC-3241)
{
++this.indent;
++this.currentIndent;
return this;
}

Expand All @@ -174,7 +174,7 @@ private SourceBuilder Append(string? text)

private SourceBuilder AppendIndent()
{
this.sb.Append(' ', this.indent * IndentSize);
this.sb.Append(' ', this.currentIndent * IndentSize);
return this;
}

Expand Down

0 comments on commit 69866f7

Please sign in to comment.