Skip to content

Use dotnet format and roslynator fix to automatically apply fixes #1743

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

Merged
merged 5 commits into from
Mar 16, 2022
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
137 changes: 131 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ insert_final_newline = true
[*.{cs}]
indent_size = 4
trim_trailing_whitespace = true
file_header_template = Copyright (c) Microsoft Corporation.\nLicensed under the MIT License.
csharp_space_before_open_square_brackets = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_before_open_square_brackets = false
csharp_style_expression_bodied_constructors = when_on_single_line
csharp_style_expression_bodied_methods = when_on_single_line
csharp_style_expression_bodied_operators = when_on_single_line
csharp_style_expression_bodied_properties = true
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_accessors = true
csharp_style_expression_bodied_lambdas = when_on_single_line

# CS0168: The variable 'var' is declared but never used
dotnet_diagnostic.CS0168.severity = error
Expand All @@ -22,6 +30,8 @@ dotnet_diagnostic.CS0169.severity = error
dotnet_diagnostic.CS0219.severity = error
# CS0414: The private field 'field' is assigned but its value is never used
dotnet_diagnostic.CS0414.severity = error
# CA1067: Should override Equals because it implements IEquatable<T>
dotnet_diagnostic.CA1067.severity = silent
# CA1068: CancellationToken parameters must come last
dotnet_diagnostic.CA1068.severity = error
# CA1822: Mark members as static
Expand All @@ -32,6 +42,8 @@ dotnet_diagnostic.CA1823.severity = error
dotnet_diagnostic.CA2007.severity = error
# CA2016: Forward the CancellationToken parameter to methods that take one
dotnet_diagnostic.CA2016.severity = error
# CA2254: The logging message template should not vary between calls to 'LoggerExtensions.*'
dotnet_diagnostic.CA2254.severity = silent

# TODO: Enable all maintainability issues (dead code etc.) and enforce
# See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/maintainability-warnings
Expand All @@ -40,26 +52,30 @@ dotnet_analyzer_diagnostic.category-Maintainability.severity = error
# TODO: Fix all of these issues and explicitly ignore the intentional ones!

# CA2016: Forward the CancellationToken parameter to methods that take one
dotnet_diagnostic.CA2016.severity = suggestion
dotnet_diagnostic.CA2016.severity = error
# CS0618: A class member was marked with the Obsolete attribute
dotnet_diagnostic.CS0618.severity = suggestion
# CS0649: Uninitialized private or internal field declaration that is never assigned a value
dotnet_diagnostic.CS0649.severity = suggestion
dotnet_diagnostic.CS0649.severity = warning
# CS1998: This async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = suggestion
# CS4014: Consider applying the await operator to the result of the call
dotnet_diagnostic.CS4014.severity = suggestion

# RCS1102: Make class static
dotnet_diagnostic.RCS1102.severity = suggestion
dotnet_diagnostic.RCS1102.severity = warning
# RCS1139: Add summary element to documentation comment
dotnet_diagnostic.RCS1139.severity = suggestion
# RCS1194: Implement exception constructors
dotnet_diagnostic.RCS1194.severity = suggestion
# RCS1210: Return completed task instead of returning null
dotnet_diagnostic.RCS1210.severity = suggestion
# RCS1036: Remove unnecessary blank line
dotnet_diagnostic.RCS1036.severity = warning
# RCS1075: Avoid empty catch clause that catches System.Exception
dotnet_diagnostic.RCS1075.severity = suggestion
# RCS1170: Use read-only auto-implemented property
dotnet_diagnostic.RCS1170.severity = warning

# VSTHRD002: Avoid problematic synchronous waits
dotnet_diagnostic.VSTHRD002.severity = suggestion
Expand All @@ -79,9 +95,118 @@ dotnet_diagnostic.VSTHRD114.severity = suggestion
dotnet_diagnostic.VSTHRD200.severity = suggestion

# xUnit2013: Do not use equality check to check for collection size
dotnet_diagnostic.xUnit2013.severity = suggestion
# IDE0003: this and Me preferences
dotnet_diagnostic.IDE0003.severity = suggestion
dotnet_diagnostic.xUnit2013.severity = warning
# xUnit1004: Test methods should not be skipped
dotnet_diagnostic.xUnit1004.severity = suggestion

# IDE0001: Simplify name
dotnet_diagnostic.IDE0001.severity = warning
# IDE0002: Simplify member access
dotnet_diagnostic.IDE0001.severity = warning
# IDE0003: Remove this or Me qualification
dotnet_diagnostic.IDE0003.severity = warning
# IDE0004: Remove unnecessary cast
dotnet_diagnostic.IDE0004.severity = warning
# IDE0005: Remove unnecessary import
dotnet_diagnostic.IDE0005.severity = suggestion
# IDE0008: Use explicit type instead of var
dotnet_diagnostic.IDE0008.severity = warning
# IDE0011: Add braces
dotnet_diagnostic.IDE0011.severity = warning
# IDE0016: Use throw expression
dotnet_diagnostic.IDE0016.severity = warning
# IDE0017: Use object initializers
dotnet_diagnostic.IDE0017.severity = warning
# IDE0018: Inline variable declaration
dotnet_diagnostic.IDE0018.severity = warning
# IDE0019: Use pattern matching to avoid 'as' followed by a 'null' check
dotnet_diagnostic.IDE0019.severity = warning
# IDE0020: Use pattern matching to avoid 'is' check followed by a cast (with variable)
dotnet_diagnostic.IDE0020.severity = warning
# IDE0021: Use expression body for constructors
dotnet_diagnostic.IDE0021.severity = warning
# IDE0022: Use expression body for methods
dotnet_diagnostic.IDE0022.severity = warning
# IDE0023: Use expression body for conversion operators
dotnet_diagnostic.IDE0023.severity = warning
# IDE0024: Use expression body for operators
dotnet_diagnostic.IDE0024.severity = warning
# IDE0025: Use expression body for properties
dotnet_diagnostic.IDE0025.severity = warning
# IDE0026: Use expression body for indexers
dotnet_diagnostic.IDE0026.severity = warning
# IDE0027: Use expression body for accessors
dotnet_diagnostic.IDE0027.severity = warning
# IDE0028: Use collection initializers
dotnet_diagnostic.IDE0028.severity = warning
# IDE0029: Use coalesce expression (non-nullable types)
dotnet_diagnostic.IDE0029.severity = warning
# IDE0030: Use coalesce expression (nullable types)
dotnet_diagnostic.IDE0030.severity = warning
# IDE0031: Use null propagation
dotnet_diagnostic.IDE0031.severity = warning
# IDE0032: Use auto property
dotnet_diagnostic.IDE0032.severity = warning
# IDE0033: Use explicitly provided tuple name
dotnet_diagnostic.IDE0033.severity = warning
# IDE0034: Simplify 'default' expression
dotnet_diagnostic.IDE0034.severity = warning
# IDE0035: Remove unreachable code
dotnet_diagnostic.IDE0035.severity = warning
# IDE0036: Order modifiers
dotnet_diagnostic.IDE0036.severity = warning
# IDE0037: Use inferred member name
dotnet_diagnostic.IDE0037.severity = warning
# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
dotnet_diagnostic.IDE0038.severity = suggestion
# IDE0040: Add accessibility modifiers
dotnet_diagnostic.IDE0040.severity = warning
# IDE0041: Use is null check
dotnet_diagnostic.IDE0041.severity = warning
# IDE0042: Deconstruct variable declaration
dotnet_diagnostic.IDE0042.severity = warning
# IDE0044: Add readonly modifier
dotnet_diagnostic.IDE0044.severity = warning
# IDE0045: Use conditional expression for assignment
dotnet_diagnostic.IDE0045.severity = warning
# IDE0046: Use conditional expression for return
dotnet_diagnostic.IDE0046.severity = silent
# IDE0047: Remove unnecessary parentheses
dotnet_diagnostic.IDE0047.severity = warning
# IDE0049: Use language keywords instead of framework type names for type references
dotnet_diagnostic.IDE0049.severity = warning
# IDE0051: Remove unused private member
dotnet_diagnostic.IDE0051.severity = warning
# IDE0052: Remove unread private member
dotnet_diagnostic.IDE0052.severity = suggestion
# IDE0053: Use expression body for lambdas
dotnet_diagnostic.IDE0053.severity = warning
# IDE0054: Use compound assignment
dotnet_diagnostic.IDE0054.severity = warning
# IDE0063: Use simple 'using' statement
dotnet_diagnostic.IDE0063.severity = warning
# IDE0066: Use switch expression
dotnet_diagnostic.IDE0066.severity = warning
# IDE0071: Simplify interpolation
dotnet_diagnostic.IDE0071.severity = warning
# IDE0073: Require file header
dotnet_diagnostic.IDE0073.severity = warning
# IDE0075: Simplify conditional expression
dotnet_diagnostic.IDE0075.severity = warning
# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = warning
# IDE0082: Convert typeof to nameof
dotnet_diagnostic.IDE0082.severity = warning
# IDE0083: Use pattern matching (not operator)
dotnet_diagnostic.IDE0083.severity = warning
# IDE0090: Simplify new expression
dotnet_diagnostic.IDE0090.severity = warning
# IDE0100: Remove unnecessary equality operator
dotnet_diagnostic.IDE0100.severity = warning
# IDE0110: Remove unnecessary discard
dotnet_diagnostic.IDE0110.severity = warning
# IDE1005: Use conditional delegate call
dotnet_diagnostic.IDE1005.severity = warning

[*.{json}]
indent_size = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Microsoft.PowerShell.EditorServices.Commands
public sealed class StartEditorServicesCommand : PSCmdlet
{
// TODO: Remove this when we drop support for PS6.
private readonly static bool s_isWindows =
private static readonly bool s_isWindows =
#if CoreCLR
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
Expand Down Expand Up @@ -237,15 +237,13 @@ protected override void EndProcessing()
// Create the configuration from parameters
EditorServicesConfig editorServicesConfig = CreateConfigObject();

var sessionFileWriter = new SessionFileWriter(_logger, SessionDetailsPath);
SessionFileWriter sessionFileWriter = new(_logger, SessionDetailsPath);
_logger.Log(PsesLogLevel.Diagnostic, "Session file writer created");

using (var psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers))
{
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
// Start editor services and wait here until it shuts down
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
}
using EditorServicesLoader psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers);
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
// Start editor services and wait here until it shuts down
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
}
catch (Exception e)
{
Expand Down Expand Up @@ -277,7 +275,7 @@ private void StartLogging()
// if it's being used as a protocol transport
if (!Stdio)
{
var hostLogger = new PSHostLogger(Host.UI);
PSHostLogger hostLogger = new(Host.UI);
_loggerUnsubscribers.Add(_logger.Subscribe(hostLogger));
}

Expand All @@ -292,7 +290,7 @@ private void StartLogging()
logPath = Path.Combine(logDirPath, $"StartEditorServices-temp{randomInt.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}.log");
}

var fileLogger = StreamLogger.CreateWithNewFile(logPath);
StreamLogger fileLogger = StreamLogger.CreateWithNewFile(logPath);
_disposableResources.Add(fileLogger);
IDisposable fileLoggerUnsubscriber = _logger.Subscribe(fileLogger);
fileLogger.AddUnsubscriber(fileLoggerUnsubscriber);
Expand All @@ -316,23 +314,21 @@ private string GetLogDirPath()
private void RemovePSReadLineForStartup()
{
_logger.Log(PsesLogLevel.Verbose, "Removing PSReadLine");
using (var pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace))
{
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
.AddParameter("Name", "PSReadLine")
.Invoke()
.Any();
using SMA.PowerShell pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace);
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
.AddParameter("Name", "PSReadLine")
.Invoke()
.Any();

if (hasPSReadLine)
{
pwsh.Commands.Clear();
if (hasPSReadLine)
{
pwsh.Commands.Clear();

pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Remove-Module", typeof(RemoveModuleCommand)))
.AddParameter("Name", "PSReadLine")
.AddParameter("ErrorAction", "SilentlyContinue");
pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Remove-Module", typeof(RemoveModuleCommand)))
.AddParameter("Name", "PSReadLine")
.AddParameter("ErrorAction", "SilentlyContinue");

_logger.Log(PsesLogLevel.Verbose, "Removed PSReadLine");
}
_logger.Log(PsesLogLevel.Verbose, "Removed PSReadLine");
}
}

Expand All @@ -352,14 +348,14 @@ private EditorServicesConfig CreateConfigObject()
bundledModulesPath));
}

var profile = (PSObject)GetVariableValue("profile");
PSObject profile = (PSObject)GetVariableValue("profile");

var hostInfo = new HostInfo(HostName, HostProfileId, HostVersion);
HostInfo hostInfo = new(HostName, HostProfileId, HostVersion);

var initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
InitialSessionState initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
initialSessionState.LanguageMode = Runspace.DefaultRunspace.SessionStateProxy.LanguageMode;

var editorServicesConfig = new EditorServicesConfig(
EditorServicesConfig editorServicesConfig = new(
hostInfo,
Host,
SessionDetailsPath,
Expand Down Expand Up @@ -425,9 +421,9 @@ private ConsoleReplKind GetReplKind()
}

// TODO: Remove this when we drop support for PS6.
var psVersionTable = (Hashtable) this.SessionState.PSVariable.GetValue("PSVersionTable");
Hashtable psVersionTable = (Hashtable)SessionState.PSVariable.GetValue("PSVersionTable");
dynamic version = psVersionTable["PSVersion"];
var majorVersion = (int) version.Major;
int majorVersion = (int)version.Major;

if (UseLegacyReadLine || (!s_isWindows && majorVersion == 6))
{
Expand Down
Loading