diff --git a/.editorconfig b/.editorconfig index 69c17b8f..ac93d200 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,3 +17,13 @@ indent_size = 2 [*.verified.cs] trim_trailing_whitespace = false insert_final_newline = false + +# We have to set the severity via dotnet_diagnostic.ID.severity because +# otherwise the warnings are only shown in the IDE, not in the build: +# See: https://github.com/dotnet/roslyn/issues/49439 + +[*.cs] +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_elsewhere = true:warning +dotnet_diagnostic.IDE0007.severity = warning diff --git a/Funcky.Analyzers/Funcky.BuiltinAnalyzers/TryGetValueAnalyzer.cs b/Funcky.Analyzers/Funcky.BuiltinAnalyzers/TryGetValueAnalyzer.cs index 2bb93742..ed496dba 100644 --- a/Funcky.Analyzers/Funcky.BuiltinAnalyzers/TryGetValueAnalyzer.cs +++ b/Funcky.Analyzers/Funcky.BuiltinAnalyzers/TryGetValueAnalyzer.cs @@ -100,7 +100,7 @@ private static bool OriginatesInRazorFile(IOperation operation) private static IEnumerable GetBaseTypes(INamedTypeSymbol type) { - for (INamedTypeSymbol? baseType = type.BaseType; baseType is not null; baseType = baseType.BaseType) + for (var baseType = type.BaseType; baseType is not null; baseType = baseType.BaseType) { yield return baseType; } diff --git a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/InterleaveTest.cs b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/InterleaveTest.cs index ac6b8d71..d23a432f 100644 --- a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/InterleaveTest.cs +++ b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/InterleaveTest.cs @@ -89,7 +89,7 @@ public async Task GivenASequenceOfSequencesInterleaveReturnsTheExpectedSequence( var innerSum = sequences.Select(async element => await element.CountAsync()).Aggregate(0, (total, part) => total + part.Result); Assert.Equal(innerSum, await sequences.Interleave().CountAsync()); - int expected = 1; + var expected = 1; await foreach (var element in sequences.Interleave()) { Assert.Equal(expected, element); diff --git a/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs b/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs index 59bebd9b..2beec9c6 100644 --- a/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs +++ b/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs @@ -84,7 +84,7 @@ private async IAsyncEnumerator GetEnumeratorInternal() // this can change on Dispose! var bufferCount = _buffer.Count; - for (int cycle = 1; IsCycling(cycle); ++cycle) + for (var cycle = 1; IsCycling(cycle); ++cycle) { for (var index = 0; index < bufferCount; ++index) { diff --git a/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs index 90f273cc..847e82ef 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs @@ -80,7 +80,9 @@ public void GivenAnEnumerableNotAMultipleOfSizeWeHaveASmallerLastSlice() var numbers = Sequence.Return("a", "b", "c", "d", "e", "g", "h", "i", "j").ToList(); const int chunkSize = 4; + #pragma warning disable IDE0007 // False positive IEnumerable> chunked = numbers.Chunk(chunkSize); + #pragma warning restore IDE0007 Assert.Collection( chunked, diff --git a/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs index 1a75f00b..5f541440 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs @@ -18,7 +18,7 @@ public void GivenAnEmptySequenceOfSequencesInterleaveReturnsAnEmptySequence() { IEnumerable> emptySequence = []; - IEnumerable interleaved = emptySequence.Interleave(); + var interleaved = emptySequence.Interleave(); Assert.Empty(interleaved); } @@ -42,7 +42,7 @@ public void GivenTwoSequencesOfUnequalLengthIGetAnInterleavedResult() IEnumerable evens = [2, 4, 6]; IEnumerable expected = [1, 2, 3, 4, 5, 6, 7, 9, 11]; - IEnumerable interleaved = odds.Interleave(evens); + var interleaved = odds.Interleave(evens); Assert.Equal(expected, interleaved); } @@ -99,7 +99,7 @@ public void GivenASequenceOfSequencesInterleaveReturnsTheExpectedSequence() Assert.Equal(sequences.Select(s => s.Count()).Sum(), sequences.Interleave().Count()); - int expected = 1; + var expected = 1; foreach (var element in sequences.Interleave()) { Assert.Equal(expected, element); diff --git a/Funcky.Test/FunctionalClass/FlipTest.cs b/Funcky.Test/FunctionalClass/FlipTest.cs index def0b380..7a952c63 100644 --- a/Funcky.Test/FunctionalClass/FlipTest.cs +++ b/Funcky.Test/FunctionalClass/FlipTest.cs @@ -60,7 +60,7 @@ public Property GivenAFunctionWith8ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith2ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text) => side = $"number:{number}, text:{text}"; f(number, text); @@ -73,7 +73,7 @@ public Property GivenAnActionWith2ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith3ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3) => side = $"number:{number}, text:{text}, {p3}"; f(number, text, true); @@ -86,7 +86,7 @@ public Property GivenAnActionWith3ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith4ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3, p4) => side = $"number:{number}, text:{text}, {p3}, {p4}"; f(number, text, true, false); @@ -99,7 +99,7 @@ public Property GivenAnActionWith4ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith5ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3, p4, p5) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}"; f(number, text, true, false, false); @@ -112,7 +112,7 @@ public Property GivenAnActionWith5ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith6ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3, p4, p5, p6) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}, {p6}"; f(number, text, true, false, false, true); @@ -125,7 +125,7 @@ public Property GivenAnActionWith6ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith7ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3, p4, p5, p6, p7) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}, {p6}, {p7}"; f(number, text, true, false, false, true, true); @@ -138,7 +138,7 @@ public Property GivenAnActionWith7ParametersTheFirstTwoParametersGetFlipped(int [Property] public Property GivenAnActionWith8ParametersTheFirstTwoParametersGetFlipped(int number, string text) { - string side = string.Empty; + var side = string.Empty; Action f = (number, text, p3, p4, p5, p6, p7, p8) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}, {p6}, {p7}, {p8}"; f(number, text, true, false, false, true, true, true); diff --git a/Funcky.Test/UpCastTest.cs b/Funcky.Test/UpCastTest.cs index 3aca74f6..28c442a1 100644 --- a/Funcky.Test/UpCastTest.cs +++ b/Funcky.Test/UpCastTest.cs @@ -1,3 +1,5 @@ +#pragma warning disable IDE0007 // Use implicit type + using System.Collections.Immutable; namespace Funcky.Test; diff --git a/Funcky/Sequence/Sequence.CycleRange.cs b/Funcky/Sequence/Sequence.CycleRange.cs index 912da0e4..a1f117db 100644 --- a/Funcky/Sequence/Sequence.CycleRange.cs +++ b/Funcky/Sequence/Sequence.CycleRange.cs @@ -92,7 +92,7 @@ private IEnumerator GetEnumeratorInternal() // this can change on Dispose! var bufferCount = _buffer.Count; - for (int cycle = 1; IsCycling(cycle); ++cycle) + for (var cycle = 1; IsCycling(cycle); ++cycle) { for (var index = 0; index < bufferCount; ++index) {