Skip to content

Commit

Permalink
Define var preference
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Apr 11, 2024
1 parent 6bfe87a commit f84b25f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static bool OriginatesInRazorFile(IOperation operation)

private static IEnumerable<INamedTypeSymbol> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private async IAsyncEnumerator<T> 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)
{
Expand Down
2 changes: 2 additions & 0 deletions Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyList<string>> chunked = numbers.Chunk(chunkSize);
#pragma warning restore IDE0007

Assert.Collection(
chunked,
Expand Down
6 changes: 3 additions & 3 deletions Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void GivenAnEmptySequenceOfSequencesInterleaveReturnsAnEmptySequence()
{
IEnumerable<IEnumerable<int>> emptySequence = [];

IEnumerable<int> interleaved = emptySequence.Interleave();
var interleaved = emptySequence.Interleave();

Assert.Empty(interleaved);
}
Expand All @@ -42,7 +42,7 @@ public void GivenTwoSequencesOfUnequalLengthIGetAnInterleavedResult()
IEnumerable<int> evens = [2, 4, 6];
IEnumerable<int> expected = [1, 2, 3, 4, 5, 6, 7, 9, 11];

IEnumerable<int> interleaved = odds.Interleave(evens);
var interleaved = odds.Interleave(evens);

Assert.Equal(expected, interleaved);
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions Funcky.Test/FunctionalClass/FlipTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string> f = (number, text) => side = $"number:{number}, text:{text}";

f(number, text);
Expand All @@ -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<int, string, bool> f = (number, text, p3) => side = $"number:{number}, text:{text}, {p3}";

f(number, text, true);
Expand All @@ -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<int, string, bool, bool> f = (number, text, p3, p4) => side = $"number:{number}, text:{text}, {p3}, {p4}";

f(number, text, true, false);
Expand All @@ -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<int, string, bool, bool, bool> f = (number, text, p3, p4, p5) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}";

f(number, text, true, false, false);
Expand All @@ -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<int, string, bool, bool, bool, bool> f = (number, text, p3, p4, p5, p6) => side = $"number:{number}, text:{text}, {p3}, {p4}, {p5}, {p6}";

f(number, text, true, false, false, true);
Expand All @@ -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<int, string, bool, bool, bool, bool, bool> 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);
Expand All @@ -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<int, string, bool, bool, bool, bool, bool, bool> 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);
Expand Down
2 changes: 2 additions & 0 deletions Funcky.Test/UpCastTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable IDE0007 // Use implicit type

using System.Collections.Immutable;

namespace Funcky.Test;
Expand Down
2 changes: 1 addition & 1 deletion Funcky/Sequence/Sequence.CycleRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private IEnumerator<T> 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)
{
Expand Down

0 comments on commit f84b25f

Please sign in to comment.