Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strengthen EditorConfig to help enforce coding standards #775

Merged
merged 16 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 117 additions & 297 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Project>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000;SA1010</NoWarn>
<NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000</NoWarn>
<Platform>AnyCPU</Platform>
<IsTestProject>$(MSBuildProjectName.Contains('Tests'))</IsTestProject>
<IsBenchmarkProject>$(MSBuildProjectName.Contains('Benchmarks'))</IsBenchmarkProject>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/DynamicData.Tests/AggregationTests/AggregationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@ public void CanHandleUpdatedItem()
accumulator.Dispose();
}

public void Dispose()
{
_source.Dispose();
}
public void Dispose() => _source.Dispose();
}
10 changes: 2 additions & 8 deletions src/DynamicData.Tests/AggregationTests/AverageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class AverageFixture : IDisposable
{
private readonly SourceCache<Person, string> _source;

public AverageFixture()
{
_source = new SourceCache<Person, string>(p => p.Name);
}
public AverageFixture() => _source = new SourceCache<Person, string>(p => p.Name);

[Fact]
public void AddedItemsContributeToSum()
Expand Down Expand Up @@ -178,10 +175,7 @@ public void AddedItemsContributeToSumNullableDecimal()
accumulator.Dispose();
}

public void Dispose()
{
_source.Dispose();
}
public void Dispose() => _source.Dispose();

[Fact]
public void InlineChangeReEvaluatesTotals()
Expand Down
10 changes: 2 additions & 8 deletions src/DynamicData.Tests/AggregationTests/MaxFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class MaxFixture : IDisposable
{
private readonly SourceCache<Person, string> _source;

public MaxFixture()
{
_source = new SourceCache<Person, string>(p => p.Name);
}
public MaxFixture() => _source = new SourceCache<Person, string>(p => p.Name);

[Fact]
public void AddItems()
Expand All @@ -34,10 +31,7 @@ public void AddItems()
accumulator.Dispose();
}

public void Dispose()
{
_source.Dispose();
}
public void Dispose() => _source.Dispose();

[Fact]
public void InlineChangeReEvaluatesTotals()
Expand Down
10 changes: 2 additions & 8 deletions src/DynamicData.Tests/AggregationTests/MinFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class MinFixture : IDisposable
{
private readonly SourceCache<Person, string> _source;

public MinFixture()
{
_source = new SourceCache<Person, string>(p => p.Name);
}
public MinFixture() => _source = new SourceCache<Person, string>(p => p.Name);

[Fact]
public void AddedItemsContributeToSum()
Expand All @@ -34,10 +31,7 @@ public void AddedItemsContributeToSum()
accumulator.Dispose();
}

public void Dispose()
{
_source.Dispose();
}
public void Dispose() => _source.Dispose();

[Fact]
public void InlineChangeReEvaluatesTotals()
Expand Down
10 changes: 2 additions & 8 deletions src/DynamicData.Tests/AggregationTests/SumFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class SumFixture : IDisposable
{
private readonly SourceCache<Person, string> _source;

public SumFixture()
{
_source = new SourceCache<Person, string>(p => p.Name);
}
public SumFixture() => _source = new SourceCache<Person, string>(p => p.Name);

[Fact]
public void AddedItemsContributeToSum()
Expand Down Expand Up @@ -188,10 +185,7 @@ public void AddedItemsContributeToSumDecimalNullable()
accumulator.Dispose();
}

public void Dispose()
{
_source.Dispose();
}
public void Dispose() => _source.Dispose();

[Fact]
public void InlineChangeReEvaluatesTotals()
Expand Down
12 changes: 3 additions & 9 deletions src/DynamicData.Tests/AutoRefreshFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,13 @@ public void AutoRefreshWithObservablePredicate2()
}
}

public class Item : INotifyPropertyChanged
public class Item(string name) : INotifyPropertyChanged
{
private string _name;

public Item(string name)
{
Id = Guid.NewGuid();
_name = name;
}
private string _name = name;

public event PropertyChangedEventHandler? PropertyChanged;

public Guid Id { get; }
public Guid Id { get; } = Guid.NewGuid();

public string Name
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BindingListBindCacheSortedFixture : IDisposable

private readonly IComparer<Person> _comparer = SortExpressionComparer<Person>.Ascending(p => p.Name);

private readonly RandomPersonGenerator _generator = new RandomPersonGenerator();
private readonly RandomPersonGenerator _generator = new();

private readonly ISourceCache<Person, string> _source;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ public void InsertInto()

private class TestBindingList<T> : BindingList<T>
{
public void Reset()
{
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
public void Reset() => OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public void WithoutInitialValue()

// [Fact]
// [Trait("Manual run for benchmarking","xx")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Accetable for test.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Manual run for benchmarking")]
private void StressIt()
{
var list = new SourceList<ClassA>();
Expand All @@ -266,9 +268,7 @@ private void StressIt()

if (items.Length > 1 && items[1].Child is not null)
{
#pragma warning disable CS8602 // Dereference of a possibly null reference.
items[1].Child.Age = -1;
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}
else
{
Expand Down Expand Up @@ -300,23 +300,17 @@ public class ClassA : AbstractNotifyPropertyChanged, IEquatable<ClassA>
/// <param name="left">The first value to compare.</param>
/// <param name="right">The second value to compare.</param>
/// <returns>true if the <paramref name="left" /> and <paramref name="right" /> parameters have the same value; otherwise, false.</returns>
public static bool operator ==(ClassA left, ClassA right)
{
return Equals(left, right);
}
public static bool operator ==(ClassA left, ClassA right) => Equals(left, right);

/// <summary>Returns a value that indicates whether two <see cref="T:DynamicData.Tests.Binding.DeeplyNestedNotifyPropertyChangedFixture: IDisposable.ClassA" /> objects have different values.</summary>
/// <param name="left">The first value to compare.</param>
/// <param name="right">The second value to compare.</param>
/// <returns>true if <paramref name="left" /> and <paramref name="right" /> are not equal; otherwise, false.</returns>
public static bool operator !=(ClassA left, ClassA right)
{
return !Equals(left, right);
}
public static bool operator !=(ClassA left, ClassA right) => !Equals(left, right);

public bool Equals(ClassA? other)
{
if (ReferenceEquals(null, other))
if (other is null)
{
return false;
}
Expand All @@ -331,7 +325,7 @@ public bool Equals(ClassA? other)

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
if (obj is null)
{
return false;
}
Expand All @@ -357,10 +351,7 @@ public override int GetHashCode()
}
}

public override string ToString()
{
return $"ClassA: Name={Name}, {nameof(Child)}: {Child}";
}
public override string ToString() => $"ClassA: Name={Name}, {nameof(Child)}: {Child}";
}

public class ClassB : AbstractNotifyPropertyChanged, IEquatable<ClassB>
Expand All @@ -377,23 +368,17 @@ public int Age
/// <param name="left">The first value to compare.</param>
/// <param name="right">The second value to compare.</param>
/// <returns>true if the <paramref name="left" /> and <paramref name="right" /> parameters have the same value; otherwise, false.</returns>
public static bool operator ==(ClassB left, ClassB right)
{
return Equals(left, right);
}
public static bool operator ==(ClassB left, ClassB right) => Equals(left, right);

/// <summary>Returns a value that indicates whether two <see cref="T:DynamicData.Tests.Binding.DeeplyNestedNotifyPropertyChangedFixture: IDisposable.ClassB" /> objects have different values.</summary>
/// <param name="left">The first value to compare.</param>
/// <param name="right">The second value to compare.</param>
/// <returns>true if <paramref name="left" /> and <paramref name="right" /> are not equal; otherwise, false.</returns>
public static bool operator !=(ClassB left, ClassB right)
{
return !Equals(left, right);
}
public static bool operator !=(ClassB left, ClassB right) => !Equals(left, right);

public bool Equals(ClassB? other)
{
if (ReferenceEquals(null, other))
if (other is null)
{
return false;
}
Expand All @@ -408,7 +393,7 @@ public bool Equals(ClassB? other)

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
if (obj is null)
{
return false;
}
Expand All @@ -426,15 +411,9 @@ public override bool Equals(object? obj)
return Equals((ClassB)obj);
}

public override int GetHashCode()
{
return _age;
}
public override int GetHashCode() => _age;

public override string ToString()
{
return $"{nameof(Age)}: {Age}";
}
public override string ToString() => $"{nameof(Age)}: {Age}";
}

public class ClassC : AbstractNotifyPropertyChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void ListRecievesRefresh()

person.Age = 60;

_listNotifications.Messages.Count().Should().Be(2);
_listNotifications.Messages.Count.Should().Be(2);
_listNotifications.Messages.Last().First().Reason.Should().Be(ListChangeReason.Refresh);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class IObservableListBindCacheSortedFixture : IDisposable

private static readonly IComparer<Person> _comparerNameDesc = SortExpressionComparer<Person>.Descending(p => p.Name);

private readonly BehaviorSubject<IComparer<Person>> _comparer = new BehaviorSubject<IComparer<Person>>(_comparerAgeAscThanNameAsc);
private readonly BehaviorSubject<IComparer<Person>> _comparer = new(_comparerAgeAscThanNameAsc);

private readonly RandomPersonGenerator _generator = new RandomPersonGenerator();
private readonly RandomPersonGenerator _generator = new();

private readonly IObservableList<Person> _list;

Expand Down Expand Up @@ -82,6 +82,7 @@ public void Dispose()
_sourceCacheNotifications.Dispose();
_listNotifications.Dispose();
_source.Dispose();
_comparer.Dispose();
}

[Fact]
Expand All @@ -100,7 +101,7 @@ public void InitialBindWithExistingData()
var listNotifications = list.Connect().AsAggregator();

// Assert
listNotifications.Messages.Count().Should().Be(1);
listNotifications.Messages.Count.Should().Be(1);
listNotifications.Messages.First().First().Reason.Should().Be(ListChangeReason.AddRange);
list.Items.Should().Equal(person1, person2);

Expand All @@ -124,7 +125,7 @@ public void ListRecievesMoves()
person3.Age = 1;

// 1 ChangeSet with AddRange & 1 ChangeSet with Refresh & Move
_listNotifications.Messages.Count().Should().Be(2);
_listNotifications.Messages.Count.Should().Be(2);

// Assert AddRange
var addChangeSet = _listNotifications.Messages.First();
Expand Down Expand Up @@ -154,7 +155,7 @@ public void ListRecievesRefresh()

person.Age = 60;

_listNotifications.Messages.Count().Should().Be(2);
_listNotifications.Messages.Count.Should().Be(2);
_listNotifications.Messages.Last().First().Reason.Should().Be(ListChangeReason.Refresh);
}

Expand All @@ -181,7 +182,7 @@ public void Reset()

_list.Items.Should().Equal(sorted);

_listNotifications.Messages.Count().Should().Be(2); // Initial loading change set and a reset change due to a change over the reset threshold.
_listNotifications.Messages.Count.Should().Be(2); // Initial loading change set and a reset change due to a change over the reset threshold.
_listNotifications.Messages[0].First().Reason.Should().Be(ListChangeReason.AddRange); // initial loading
_listNotifications.Messages[1].Count.Should().Be(2); // Reset
_listNotifications.Messages[1].First().Reason.Should().Be(ListChangeReason.Clear); // reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void ListRecievesRefresh()

person.Age = 60;

_observableListNotifications.Messages.Count().Should().Be(2);
_observableListNotifications.Messages.Count.Should().Be(2);
_observableListNotifications.Messages.Last().First().Reason.Should().Be(ListChangeReason.Refresh);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public void Add()
_results.Data.Items.First().Should().Be(1);
}

public void Dispose()
{
_results.Dispose();
}
public void Dispose() => _results.Dispose();

[Fact]
public void Duplicates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public void Add()
_results.Data.Items.First().Should().Be(1);
}

public void Dispose()
{
_results.Dispose();
}
public void Dispose() => _results.Dispose();

[Fact]
public void Duplicates()
Expand Down Expand Up @@ -96,9 +93,6 @@ public void ResetFiresClearsAndAdds()

private class TestObservableCollection<T> : ObservableCollection<T>
{
public void Reset()
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public void Reset() => OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
Loading