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

Enable even more rules #3356

Merged
merged 11 commits into from
Feb 12, 2022
28 changes: 26 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ dotnet_diagnostic.IDE0005.severity = warning # not default, increased severity t

# 'using' directive preferences
# Keep this in sync with the related C# rule: csharp_using_directive_placement
dotnet_diagnostic.IDE0065.severity = none
dotnet_diagnostic.IDE0065.severity = warning

# Use simple using statements
# Keep this in sync with th related C# rule: csharp_prefer_simple_using_statement
Expand All @@ -140,6 +140,30 @@ dotnet_diagnostic.IDE0053.severity = warning # not default, increased severity t
# CA2016: Forward the 'CancellationToken' parameter to methods
dotnet_diagnostic.CA2016.severity = warning # not default, increased severity to ensure it is applied

# IDE0059: Remove unnecessary value assignment
dotnet_diagnostic.IDE0059.severity=warning # not default, increased severity to ensure it is applied

# CA2245: Do not assign a property to itself
dotnet_diagnostic.CA2245.severity=warning # not default, increased severity to ensure it is applied

# IDE0077: Avoid legacy format target in global 'SuppressMessageAttribute'
dotnet_diagnostic.IDE0077.severity=warning # not default, increased severity to ensure it is applied

# IDE0076: Remove invalid global 'SuppressMessageAttribute'
dotnet_diagnostic.IDE0076.severity=warning # not default, increased severity to ensure it is applied

# IDE0043: Invalid string format
dotnet_diagnostic.IDE0043.severity=warning # not default, increased severity to ensure it is applied

# CA1805: Do not initialize unnecessarily
dotnet_diagnostic.CA1805.severity=warning # not default, increased severity to ensure it is applied

# CA1507: Use nameof in place of string
dotnet_diagnostic.CA1507.severity=warning # not default, increased severity to ensure it is applied

# CA2215: Dispose methods should call base class dispose
dotnet_diagnostic.CA2215.severity=warning # not default, increased severity to ensure it is applied

#### C# Coding Conventions ####

# var preferences
Expand Down Expand Up @@ -190,7 +214,7 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sil

# 'using' directive preferences
# Keep this in sync with the related .NET rule: IDE0065
csharp_using_directive_placement = outside_namespace:silent
csharp_using_directive_placement = inside_namespace:warning

#### .NET Formatting Rules ####

Expand Down
4 changes: 2 additions & 2 deletions playground/MSTest1/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest1;

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class UnitTest1
{
Expand Down
4 changes: 2 additions & 2 deletions playground/TestPlatform.Playground/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace TestPlatform.Playground;

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
Expand All @@ -15,8 +17,6 @@
using System.Reflection;
using System.Threading;

namespace TestPlatform.Playground;

internal class Program
{
static void Main(string[] args)
Expand Down
4 changes: 2 additions & 2 deletions src/AttachVS/AttachVs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.AttachVS;

using System;
using System.Diagnostics;
using System.Linq;
Expand All @@ -10,8 +12,6 @@
using System.Runtime.InteropServices.ComTypes;
using System.Threading;

namespace Microsoft.TestPlatform.AttachVS;

internal class DebuggerUtility
{
internal static bool AttachVSToProcess(int? pid, int? vsPid)
Expand Down
4 changes: 2 additions & 2 deletions src/AttachVS/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.AttachVS;

using System;
using System.Diagnostics;
using System.Linq;

namespace Microsoft.TestPlatform.AttachVS;

internal class Program
{
static void Main(string[] args)
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollectors/DumpMinitool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
namespace DumpMinitool;

using System;
using System.Diagnostics;
Expand All @@ -10,7 +10,7 @@
using System.Runtime.InteropServices;
using System.Threading;

namespace DumpMinitool;
using Microsoft.Win32.SafeHandles;

internal class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ internal string WriteEventLogs(List<EventLogEntry> eventLogEntries, int maxLogEn
/// <param name="disposing">Not used since this class does not have a finalizer.</param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

// Unregister events
_events.SessionStart -= _sessionStartEventHandler;
_events.SessionEnd -= _sessionEndEventHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class TestIdProvider
internal const int DigestBytes = DigestBits / 8;

private Guid _id = Guid.Empty;
private byte[] _hash = null;
MarcoRossignoli marked this conversation as resolved.
Show resolved Hide resolved
private byte[] _hash;
private byte[] _lastBlock = new byte[BlockBytes];
private int _position = 0;
private int _position;

private readonly Sha1Implementation _hasher;

Expand Down Expand Up @@ -121,8 +121,8 @@ internal class Sha1Implementation
* For more information please refer to https://tools.ietf.org/html/rfc3174.
*/

private int _streamSize = 0;
private bool _messagePadded = false;
private int _streamSize;
private bool _messagePadded;

public Sha1Implementation()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.TestPlatform.Build/ArgumentEscaper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.TestPlatform.Build.Utils;

using System;
using System.Text;

namespace Microsoft.TestPlatform.Build.Utils;

public static class ArgumentEscaper
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.TestPlatform.Build/Tracing.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Microsoft.TestPlatform.Build.Trace;

using System;

public static class Tracing
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Part of the public API.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;
using CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using CoreUtilities.Helpers;
using CrossPlatEngine;
using ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads;
Expand Down Expand Up @@ -562,7 +561,7 @@ private void StopTestSession(StopTestSessionPayload payload, ITestRequestManager

#region IDisposable Support

private bool _disposedValue = false; // To detect redundant calls
private bool _disposedValue; // To detect redundant calls

protected virtual void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private void Dispose(bool disposing)
/// <summary>
/// If this request has been disposed.
/// </summary>
private bool _disposed = false;
private bool _disposed;

/// <summary>
/// It get set when current discovery request is completed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.Common.DataCollector.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
namespace Microsoft.VisualStudio.TestPlatform.Common.DataCollector;

using System;
using System.Linq;

namespace Microsoft.VisualStudio.TestPlatform.Common.DataCollector;
using Microsoft.VisualStudio.TestPlatform.Common.DataCollector.Interfaces;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

/// <summary>
/// Stores and provides telemetry information for data collection.
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ internal static Builder CreateBuilder()

internal sealed class Builder
{
private bool _operatorEncountered = false;
private bool _operatorEncountered;
private Operator _fastFilterOperator = Operator.None;

private bool _conditionEncountered = false;
private bool _conditionEncountered;
private Operation _fastFilterOperation;
private readonly ImmutableDictionary<string, ImmutableHashSet<string>.Builder>.Builder _filterDictionaryBuilder = ImmutableDictionary.CreateBuilder<string, ImmutableHashSet<string>.Builder>(StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

internal interface IArtifactProcessingManager
{
void CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs, string runSettingsXml);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

using System;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

/// <summary>
/// Creates and return a list of available attachments processor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

/// <summary>
/// Orchestrates test run attachments processing operations.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class InternalTestLoggerEvents : TestLoggerEvents, IDisposable
/// <summary>
/// Keeps track if we are disposed.
/// </summary>
private bool _isDisposed = false;
private bool _isDisposed;

/// <summary>
/// Specifies whether logger event queue is bounded or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#if !NETSTANDARD1_0

namespace Microsoft.VisualStudio.TestPlatform.Utilities;

using System;
using System.Collections.Generic;

namespace Microsoft.VisualStudio.TestPlatform.Utilities;

internal partial class FeatureFlag : IFeatureFlag
{
private static readonly Dictionary<string, bool> FeatureFlags = new();
Expand Down Expand Up @@ -39,4 +39,4 @@ public bool IsEnabled(string featureName) =>
FeatureFlags.TryGetValue(featureName, out bool isEnabled) && isEnabled;
}

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#if !NETSTANDARD1_0

namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;

using System;

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

namespace Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;

internal class EnvironmentVariableHelper : IEnvironmentVariableHelper
{
public string GetEnvironmentVariable(string variable)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces;

using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;

/// <summary>
/// Helper class for getting info about dotnet host.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


#if !NETSTANDARD1_0

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

using System;

using Microsoft.Win32;

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

internal interface IWindowsRegistryHelper
{
IRegistryKey OpenBaseKey(RegistryHive hKey, RegistryView view);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

/// <summary>
/// RunSettingsHelper is used to globally share additional informations about the state of runsettings.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#if !NETSTANDARD1_0

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.Win32;

namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;

internal class WindowsRegistryHelper : IWindowsRegistryHelper
{
public IRegistryKey OpenBaseKey(RegistryHive hKey, RegistryView view)
Expand Down
Loading