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

Set simple field naming rules with this qualifier #1050

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ dotnet_analyzer_diagnostic.category-Style.severity = warning
# IDE0022: Use expression/block body for methods
dotnet_diagnostic.IDE0022.severity = suggestion

# IDE1006: Naming rule violation
dotnet_diagnostic.IDE1006.severity = warning

# Naming capitalization styles
dotnet_naming_style.camel_case_style.capitalization = camel_case
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Naming rule that private instance fields must use camel case
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_rule.camel_case_private_fields.severity = warning
dotnet_naming_rule.camel_case_private_fields.symbols = private_fields
dotnet_naming_rule.camel_case_private_fields.style = camel_case_style

# Naming rule that static read-only fields must use Pascal case
dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.static_readonly_fields.applicable_accessibilities = *
dotnet_naming_symbols.static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_rule.pascal_case_static_readonly_fields.severity = warning
dotnet_naming_rule.pascal_case_static_readonly_fields.symbols = static_readonly_fields
dotnet_naming_rule.pascal_case_static_readonly_fields.style = pascal_case_style

# Naming rule that const fields must use Pascal case
dotnet_naming_symbols.const_fields.applicable_kinds = field
dotnet_naming_symbols.const_fields.applicable_accessibilities = *
dotnet_naming_symbols.const_fields.required_modifiers = const
dotnet_naming_rule.pascal_case_const_fields.severity = warning
dotnet_naming_rule.pascal_case_const_fields.symbols = const_fields
dotnet_naming_rule.pascal_case_const_fields.style = pascal_case_style

# this. preferences
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = true
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_property = false

# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true
Expand Down
14 changes: 7 additions & 7 deletions MoreLinq.Test/Async/MergeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ sealed class AsyncControl<T>
{
sealed record State(TaskCompletionSource<T> TaskCompletionSource, T Result);

State? _state;
State? state;

public Task<T> Result(T result)
{
if (_state is not null)
if (this.state is not null)
throw new InvalidOperationException();
_state = new State(new TaskCompletionSource<T>(), result);
return _state.TaskCompletionSource.Task;
this.state = new State(new TaskCompletionSource<T>(), result);
return this.state.TaskCompletionSource.Task;
}

public void Complete()
{
if (_state is not { } state)
if (this.state is not { } someState)
throw new InvalidOperationException();
_state = null;
state.TaskCompletionSource.SetResult(state.Result);
this.state = null;
someState.TaskCompletionSource.SetResult(someState.Result);
}
}

Expand Down
32 changes: 16 additions & 16 deletions MoreLinq.Test/Async/TestingAsyncSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ source is not null

sealed class TestingAsyncSequence<T> : IAsyncEnumerable<T>, IDisposable
{
bool? _disposed;
IAsyncEnumerable<T>? _source;
ExceptionDispatchInfo? _disposeErrorInfo;
bool? disposed;
IAsyncEnumerable<T>? source;
ExceptionDispatchInfo? disposeErrorInfo;

internal TestingAsyncSequence(IAsyncEnumerable<T> sequence) =>
_source = sequence;
this.source = sequence;

public bool IsDisposed => _disposed == true;
public bool IsDisposed => this.disposed == true;
public int MoveNextCallCount { get; private set; }

void IDisposable.Dispose() =>
Expand All @@ -62,24 +62,24 @@ void IDisposable.Dispose() =>

void AssertDisposed()
{
_disposeErrorInfo?.Throw();
this.disposeErrorInfo?.Throw();

if (_disposed is null)
if (this.disposed is null)
return;

Assert.IsTrue(_disposed, "Expected sequence to be disposed.");
_disposed = null;
Assert.IsTrue(this.disposed, "Expected sequence to be disposed.");
this.disposed = null;
}

public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
Assert.That(_source, Is.Not.Null,
Assert.That(this.source, Is.Not.Null,
"LINQ operators should not enumerate a sequence more than once.");

// Dammit (!) below is okay since we assert above it's not null.
var enumerator = _source!.GetAsyncEnumerator(cancellationToken).AsWatchable();
var enumerator = this.source!.GetAsyncEnumerator(cancellationToken).AsWatchable();

_disposed = false;
this.disposed = false;
enumerator.Disposed += delegate
{
// If the following assertion fails the capture the error
Expand All @@ -90,14 +90,14 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke

try
{
Assert.That(_disposed, Is.False, "LINQ operators should not dispose a sequence more than once.");
Assert.That(this.disposed, Is.False, "LINQ operators should not dispose a sequence more than once.");
}
catch (AssertionException e)
{
_disposeErrorInfo = ExceptionDispatchInfo.Capture(e);
this.disposeErrorInfo = ExceptionDispatchInfo.Capture(e);
}

_disposed = true;
this.disposed = true;
};

var ended = false;
Expand All @@ -108,7 +108,7 @@ public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToke
MoveNextCallCount++;
};

_source = null;
this.source = null;
return enumerator;
}
}
Expand Down
8 changes: 4 additions & 4 deletions MoreLinq.Test/Async/WatchableEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ partial class TestExtensions
sealed class WatchableEnumerator<T>(IAsyncEnumerator<T> source) :
IAsyncEnumerator<T>
{
readonly IAsyncEnumerator<T> _source = source ?? throw new ArgumentNullException(nameof(source));
readonly IAsyncEnumerator<T> source = source ?? throw new ArgumentNullException(nameof(source));

public event EventHandler? Disposed;
public event EventHandler<bool>? MoveNextCalled;

public T Current => _source.Current;
public T Current => this.source.Current;

public async ValueTask<bool> MoveNextAsync()
{
var moved = await _source.MoveNextAsync();
var moved = await this.source.MoveNextAsync();
MoveNextCalled?.Invoke(this, moved);
return moved;
}

public async ValueTask DisposeAsync()
{
await _source.DisposeAsync();
await this.source.DisposeAsync();
Disposed?.Invoke(this, EventArgs.Empty);
}
}
Expand Down
24 changes: 12 additions & 12 deletions MoreLinq.Test/BatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,34 +375,34 @@ public void BatchBucketSelectorCurrentList()

sealed class TestArrayPool<T> : ArrayPool<T>, IDisposable
{
T[]? _pooledArray;
T[]? _rentedArray;
T[]? pooledArray;
T[]? rentedArray;

public override T[] Rent(int minimumLength)
{
if (_pooledArray is null && _rentedArray is null)
_pooledArray = new T[minimumLength * 2];
if (this.pooledArray is null && this.rentedArray is null)
this.pooledArray = new T[minimumLength * 2];

(_pooledArray, _rentedArray) =
(null, _pooledArray ?? throw new InvalidOperationException("The pool is exhausted."));
(this.pooledArray, this.rentedArray) =
(null, this.pooledArray ?? throw new InvalidOperationException("The pool is exhausted."));

return _rentedArray;
return this.rentedArray;
}

public override void Return(T[] array, bool clearArray = false)
{
if (_rentedArray is null)
if (this.rentedArray is null)
throw new InvalidOperationException("Cannot return when nothing has been rented from this pool.");

if (array != _rentedArray)
if (array != this.rentedArray)
throw new InvalidOperationException("Cannot return what has not been rented from this pool.");

_pooledArray = array;
_rentedArray = null;
this.pooledArray = array;
this.rentedArray = null;
}

public void Dispose() =>
Assert.That(_rentedArray, Is.Null);
Assert.That(this.rentedArray, Is.Null);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/BreakingCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace MoreLinq.Test
class BreakingCollection<T>(IList<T> list) :
BreakingSequence<T>, ICollection<T>
{
protected readonly IList<T> List = list;

public BreakingCollection(params T[] values) : this((IList<T>)values) { }

protected IList<T> List { get; } = list;

public int Count => List.Count;

public void Add(T item) => throw new NotImplementedException();
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/BreakingReadOnlyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace MoreLinq.Test
class BreakingReadOnlyCollection<T>(IReadOnlyCollection<T> collection) :
BreakingSequence<T>, IReadOnlyCollection<T>
{
readonly IReadOnlyCollection<T> _collection = collection;
readonly IReadOnlyCollection<T> collection = collection;

public BreakingReadOnlyCollection(params T[] values) : this((IReadOnlyCollection<T>)values) { }

public int Count => _collection.Count;
public int Count => this.collection.Count;
}
}
4 changes: 2 additions & 2 deletions MoreLinq.Test/BreakingReadOnlyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ sealed class BreakingReadOnlyList<T>(IReadOnlyList<T> list) :
BreakingReadOnlyCollection<T>(list),
IReadOnlyList<T>
{
readonly IReadOnlyList<T> _list = list;
readonly IReadOnlyList<T> list = list;

public BreakingReadOnlyList(params T[] values) : this((IReadOnlyList<T>)values) { }

public T this[int index] => _list[index];
public T this[int index] => this.list[index];
}
}
24 changes: 12 additions & 12 deletions MoreLinq.Test/CountDownTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ public static IReadOnlyCollection<T>

abstract class Sequence<T> : IEnumerable<T>
{
readonly Func<IEnumerator<T>, IEnumerator<T>> _em;
readonly Func<IEnumerator<T>, IEnumerator<T>> em;

protected Sequence(Func<IEnumerator<T>, IEnumerator<T>>? em) =>
_em = em ?? (e => e);
this.em = em ?? (e => e);

public IEnumerator<T> GetEnumerator() =>
_em(Items.GetEnumerator());
this.em(Items.GetEnumerator());

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand All @@ -174,15 +174,15 @@ sealed class Collection<T>(ICollection<T> collection,
Func<IEnumerator<T>, IEnumerator<T>>? em = null) :
Sequence<T>(em), ICollection<T>
{
readonly ICollection<T> _collection = collection ?? throw new ArgumentNullException(nameof(collection));
readonly ICollection<T> collection = collection ?? throw new ArgumentNullException(nameof(collection));

public int Count => _collection.Count;
public bool IsReadOnly => _collection.IsReadOnly;
public int Count => this.collection.Count;
public bool IsReadOnly => this.collection.IsReadOnly;

protected override IEnumerable<T> Items => _collection;
protected override IEnumerable<T> Items => this.collection;

public bool Contains(T item) => _collection.Contains(item);
public void CopyTo(T[] array, int arrayIndex) => _collection.CopyTo(array, arrayIndex);
public bool Contains(T item) => this.collection.Contains(item);
public void CopyTo(T[] array, int arrayIndex) => this.collection.CopyTo(array, arrayIndex);

public void Add(T item) => throw new NotImplementedException();
public void Clear() => throw new NotImplementedException();
Expand All @@ -198,11 +198,11 @@ sealed class ReadOnlyCollection<T>(ICollection<T> collection,
Func<IEnumerator<T>, IEnumerator<T>>? em = null) :
Sequence<T>(em), IReadOnlyCollection<T>
{
readonly ICollection<T> _collection = collection ?? throw new ArgumentNullException(nameof(collection));
readonly ICollection<T> collection = collection ?? throw new ArgumentNullException(nameof(collection));

public int Count => _collection.Count;
public int Count => this.collection.Count;

protected override IEnumerable<T> Items => _collection;
protected override IEnumerable<T> Items => this.collection;
}
}

Expand Down
12 changes: 6 additions & 6 deletions MoreLinq.Test/EqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ public static IEqualityComparer<T> Create<T>(Func<T?, T?, bool> comparer) =>

sealed class DelegatingComparer<T> : IEqualityComparer<T>
{
readonly Func<T?, T?, bool> _comparer;
readonly Func<T, int> _hasher;
readonly Func<T?, T?, bool> comparer;
readonly Func<T, int> hasher;

public DelegatingComparer(Func<T?, T?, bool> comparer)
: this(comparer, x => x == null ? 0 : x.GetHashCode()) { }

DelegatingComparer(Func<T?, T?, bool> comparer, Func<T, int> hasher)
{
_comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
_hasher = hasher ?? throw new ArgumentNullException(nameof(hasher));
this.comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
this.hasher = hasher ?? throw new ArgumentNullException(nameof(hasher));
}

public bool Equals(T? x, T? y) => _comparer(x, y);
public int GetHashCode(T obj) => _hasher(obj);
public bool Equals(T? x, T? y) => this.comparer(x, y);
public int GetHashCode(T obj) => this.hasher(obj);
}
}
}
6 changes: 3 additions & 3 deletions MoreLinq.Test/ReadOnlyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ sealed class ListCollection<TList, T>(TList list) :
IReadOnlyCollection<T>
where TList : IList<T>
{
readonly TList _list = list;
readonly TList list = list;

public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
public IEnumerator<T> GetEnumerator() => this.list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public int Count => _list.Count;
public int Count => this.list.Count;
}
}
}
6 changes: 3 additions & 3 deletions MoreLinq.Test/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace MoreLinq.Test

abstract class Scope<T> : IDisposable
{
readonly T _old;
readonly T old;

protected Scope(T current) => _old = current;
public virtual void Dispose() => Restore(_old);
protected Scope(T current) => this.old = current;
public virtual void Dispose() => Restore(this.old);
protected abstract void Restore(T old);
}
}
Loading