Skip to content
Closed
85 changes: 84 additions & 1 deletion dotnet/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
[*.cs]
csharp_style_namespace_declarations=file_scoped:suggestion
# See all defaults set in selenium/.editorconfig

# dotnet format whitespace

# New lines and braces (Allman-style)
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
dotnet_style_operator_placement_when_wrapping = end_of_line

# Preserve compact formatting where used
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

# Indentation
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# Spacing
csharp_space_after_cast = false
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_after_keywords_in_control_flow_statements = true

# dotnet format style

# Namespace
csharp_style_namespace_declarations=file_scoped:warning

# Using directives
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false
csharp_using_directive_placement = outside_namespace:warning

# Roslyn
dotnet_diagnostic.IDE1006.severity = suggestion # Naming rule violation
dotnet_diagnostic.IDE0059.severity = warning # Unnecessary assignment
dotnet_diagnostic.IDE0044.severity = warning # Make field readonly
dotnet_diagnostic.IDE0076.severity = warning # Invalid suppression
dotnet_diagnostic.IDE1005.severity = warning # Delegate invocation

# TODO: Additional violations to investigate
# The following are the number of violations for each diagnostic;
# They currently fail at info, the goal is to fix and explicitly set to warning above
# Investigate with `dotnet format style --diagnostics IDEXXXX --severity info`
# 1183 IDE0090
# 633 IDE0028
# 252 IDE0290
# 169 IDE0077
# 66 IDE0130
# 65 IDE0300
# 57 IDE1005
# 42 IDE0017
# 39 IDE0039
# 36 IDE0063
# 33 IDE0306
# 31 IDE0083
# 30 IDE0016
# 26 IDE0305
# 18 IDE0031
# 12 IDE0270
# 11 IDE0057
# 11 IDE0054
# 9 IDE0350
# 9 IDE0074
# 7 IDE0060
# 3 IDE0150
# 2 IDE0038
# 1 IDE0056
# 1 IDE0034
# 1 IDE0018
85 changes: 17 additions & 68 deletions dotnet/src/support/Events/EventFiringWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,7 @@ protected virtual void Dispose(bool disposing)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigating(WebDriverNavigationEventArgs e)
{
if (this.Navigating != null)
{
this.Navigating(this, e);
}
this.Navigating?.Invoke(this, e);
}

/// <summary>
Expand All @@ -615,10 +612,7 @@ protected virtual void OnNavigating(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigated(WebDriverNavigationEventArgs e)
{
if (this.Navigated != null)
{
this.Navigated(this, e);
}
this.Navigated?.Invoke(this, e);
}

/// <summary>
Expand All @@ -627,10 +621,7 @@ protected virtual void OnNavigated(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigatingBack(WebDriverNavigationEventArgs e)
{
if (this.NavigatingBack != null)
{
this.NavigatingBack(this, e);
}
this.NavigatingBack?.Invoke(this, e);
}

/// <summary>
Expand All @@ -639,10 +630,7 @@ protected virtual void OnNavigatingBack(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigatedBack(WebDriverNavigationEventArgs e)
{
if (this.NavigatedBack != null)
{
this.NavigatedBack(this, e);
}
this.NavigatedBack?.Invoke(this, e);
}

/// <summary>
Expand All @@ -651,10 +639,7 @@ protected virtual void OnNavigatedBack(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigatingForward(WebDriverNavigationEventArgs e)
{
if (this.NavigatingForward != null)
{
this.NavigatingForward(this, e);
}
this.NavigatingForward?.Invoke(this, e);
}

/// <summary>
Expand All @@ -663,10 +648,7 @@ protected virtual void OnNavigatingForward(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebDriverNavigationEventArgs"/> that contains the event data.</param>
protected virtual void OnNavigatedForward(WebDriverNavigationEventArgs e)
{
if (this.NavigatedForward != null)
{
this.NavigatedForward(this, e);
}
this.NavigatedForward?.Invoke(this, e);
}

/// <summary>
Expand All @@ -675,10 +657,7 @@ protected virtual void OnNavigatedForward(WebDriverNavigationEventArgs e)
/// <param name="e">A <see cref="WebElementEventArgs"/> that contains the event data.</param>
protected virtual void OnElementClicking(WebElementEventArgs e)
{
if (this.ElementClicking != null)
{
this.ElementClicking(this, e);
}
this.ElementClicking?.Invoke(this, e);
}

/// <summary>
Expand All @@ -687,10 +666,7 @@ protected virtual void OnElementClicking(WebElementEventArgs e)
/// <param name="e">A <see cref="WebElementEventArgs"/> that contains the event data.</param>
protected virtual void OnElementClicked(WebElementEventArgs e)
{
if (this.ElementClicked != null)
{
this.ElementClicked(this, e);
}
this.ElementClicked?.Invoke(this, e);
}

/// <summary>
Expand All @@ -699,10 +675,7 @@ protected virtual void OnElementClicked(WebElementEventArgs e)
/// <param name="e">A <see cref="WebElementValueEventArgs"/> that contains the event data.</param>
protected virtual void OnElementValueChanging(WebElementValueEventArgs e)
{
if (this.ElementValueChanging != null)
{
this.ElementValueChanging(this, e);
}
this.ElementValueChanging?.Invoke(this, e);
}

/// <summary>
Expand All @@ -711,10 +684,7 @@ protected virtual void OnElementValueChanging(WebElementValueEventArgs e)
/// <param name="e">A <see cref="WebElementValueEventArgs"/> that contains the event data.</param>
protected virtual void OnElementValueChanged(WebElementValueEventArgs e)
{
if (this.ElementValueChanged != null)
{
this.ElementValueChanged(this, e);
}
this.ElementValueChanged?.Invoke(this, e);
}

/// <summary>
Expand All @@ -723,10 +693,7 @@ protected virtual void OnElementValueChanged(WebElementValueEventArgs e)
/// <param name="e">A <see cref="FindElementEventArgs"/> that contains the event data.</param>
protected virtual void OnFindingElement(FindElementEventArgs e)
{
if (this.FindingElement != null)
{
this.FindingElement(this, e);
}
this.FindingElement?.Invoke(this, e);
}

/// <summary>
Expand All @@ -735,10 +702,7 @@ protected virtual void OnFindingElement(FindElementEventArgs e)
/// <param name="e">A <see cref="FindElementEventArgs"/> that contains the event data.</param>
protected virtual void OnFindElementCompleted(FindElementEventArgs e)
{
if (this.FindElementCompleted != null)
{
this.FindElementCompleted(this, e);
}
this.FindElementCompleted?.Invoke(this, e);
}

/// <summary>
Expand All @@ -747,10 +711,7 @@ protected virtual void OnFindElementCompleted(FindElementEventArgs e)
/// <param name="e">A <see cref="GetShadowRootEventArgs"/> that contains the event data.</param>
protected virtual void OnGettingShadowRoot(GetShadowRootEventArgs e)
{
if (this.GettingShadowRoot != null)
{
this.GettingShadowRoot(this, e);
}
this.GettingShadowRoot?.Invoke(this, e);
}

/// <summary>
Expand All @@ -759,10 +720,7 @@ protected virtual void OnGettingShadowRoot(GetShadowRootEventArgs e)
/// <param name="e">A <see cref="GetShadowRootEventArgs"/> that contains the event data.</param>
protected virtual void OnGetShadowRootCompleted(GetShadowRootEventArgs e)
{
if (this.GetShadowRootCompleted != null)
{
this.GetShadowRootCompleted(this, e);
}
this.GetShadowRootCompleted?.Invoke(this, e);
}

/// <summary>
Expand All @@ -771,10 +729,7 @@ protected virtual void OnGetShadowRootCompleted(GetShadowRootEventArgs e)
/// <param name="e">A <see cref="WebDriverScriptEventArgs"/> that contains the event data.</param>
protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e)
{
if (this.ScriptExecuting != null)
{
this.ScriptExecuting(this, e);
}
this.ScriptExecuting?.Invoke(this, e);
}

/// <summary>
Expand All @@ -783,10 +738,7 @@ protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e)
/// <param name="e">A <see cref="WebDriverScriptEventArgs"/> that contains the event data.</param>
protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e)
{
if (this.ScriptExecuted != null)
{
this.ScriptExecuted(this, e);
}
this.ScriptExecuted?.Invoke(this, e);
}

/// <summary>
Expand All @@ -795,10 +747,7 @@ protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e)
/// <param name="e">A <see cref="WebDriverExceptionEventArgs"/> that contains the event data.</param>
protected virtual void OnException(WebDriverExceptionEventArgs e)
{
if (this.ExceptionThrown != null)
{
this.ExceptionThrown(this, e);
}
this.ExceptionThrown?.Invoke(this, e);
}

private static object?[] UnwrapElementArguments(object?[] args)
Expand Down
12 changes: 0 additions & 12 deletions dotnet/src/support/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
[assembly: System.CLSCompliant(true)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely as a follow-up given the mechanical and titanic nature of this PR:

This is the only useful attribute in this file; the various old-school global suppressions should be addressed or folded into the editorconfig.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#VisibilityOfAllElementsLocatedBy(OpenQA.Selenium.By)", Justification = "Nested generic types is appropriate for this type")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#VisibilityOfAllElementsLocatedBy(System.Collections.ObjectModel.ReadOnlyCollection`1<OpenQA.Selenium.IWebElement>)", Justification = "Nested generic types is appropriate for this type")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#PresenceOfAllElementsLocatedBy(OpenQA.Selenium.By)", Justification = "Nested generic types is appropriate for this type")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.PageFactory.#InitElements`1(OpenQA.Selenium.IWebDriver)", Justification = "Page Object pattern enforces IWebDriver in constructor for generic InitElements call.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.PageFactory.#InitElements`1(OpenQA.Selenium.IWebDriver,OpenQA.Selenium.Support.PageObjects.IElementLocatorFactory)", Justification = "Page Object pattern enforces IWebDriver in constructor for generic InitElements call.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "OpenQA.Selenium.Support.Extensions", Justification = "This namespace will likely grow over time.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "OpenQA.Selenium.Support.Events.EventFiringWebDriver.#Close()", Justification = "Firing event on all execptions, so catching generic Exception is appropriate.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "OpenQA.Selenium.Support.Events.EventFiringWebDriver.#CurrentWindowHandle", Justification = "Firing event on all execptions, so catching generic Exception is appropriate.")]
Expand Down Expand Up @@ -73,16 +68,9 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "OpenQA.Selenium.Support.Events.EventFiringWebDriver+EventFiringWebElement.#Text", Justification = "Firing event on all execptions, so catching generic Exception is appropriate.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "OpenQA.Selenium.Support.UI.DefaultWait`1.#Until`1(System.Func`2<!0,!!0>)", Justification = "Analyzing and handling all exceptions that occur, so catching generic Exception is appropriate.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Scope = "member", Target = "OpenQA.Selenium.Support.Events.WebDriverNavigationEventArgs.#.ctor(OpenQA.Selenium.IWebDriver,System.String)", Justification = "Using string to preserve user input.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#UrlToBe(System.String)", Justification = "Using string to preserve user input.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Scope = "member", Target = "OpenQA.Selenium.Support.Events.WebDriverNavigationEventArgs.#Url", Justification = "Using string to preserve user input.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations", Scope = "member", Target = "OpenQA.Selenium.Support.UI.SelectElement.#SelectedOption", Justification = "Exception should be thrown in this property.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "OpenQA.Selenium.Support.UI.SelectElement.#.ctor(OpenQA.Selenium.IWebElement)", Justification = "WebDriver normalizes strings to lowercase.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#UrlToBe(System.String)", Justification = "WebDriver normalizes strings to lowercase.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "OpenQA.Selenium.Support.UI.ExpectedConditions.#UrlContains(System.String)", Justification = "WebDriver normalizes strings to lowercase.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "bys", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.ByAll.#.ctor(OpenQA.Selenium.By[])", Justification = "Parameter is correctly named")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "bys", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.ByChained.#.ctor(OpenQA.Selenium.By[])", Justification = "Parameter is correctly named")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "bys", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.IElementLocator.#LocateElement(System.Collections.Generic.IEnumerable`1<OpenQA.Selenium.By>)", Justification = "Parameter is correctly named")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "bys", Scope = "member", Target = "OpenQA.Selenium.Support.PageObjects.IElementLocator.#LocateElements(System.Collections.Generic.IEnumerable`1<OpenQA.Selenium.By>)", Justification = "Parameter is correctly named")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "OpenQA.Selenium.Support.Events.EventFiringWebDriver+EventFiringWebElement.#ParentDriver", Justification = "Method must be available for subclasses.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "IJavaScriptExecutor", Scope = "member", Target = "OpenQA.Selenium.Support.Extensions.WebDriverExtensions.#ExecuteJavaScript`1(OpenQA.Selenium.IWebDriver,System.String,System.Object[])", Justification = "Interface name is correct")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "IHasCapabilities", Scope = "member", Target = "OpenQA.Selenium.Support.Extensions.WebDriverExtensions.#TakeScreenshot(OpenQA.Selenium.IWebDriver)", Justification = "Interface name is correct")]
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/BiDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Json.Converters;
using System;
using System.Collections.Concurrent;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// under the License.
// </copyright>

using OpenQA.Selenium.Internal.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand All @@ -26,6 +25,7 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using OpenQA.Selenium.Internal.Logging;

namespace OpenQA.Selenium.BiDi;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Json.Converters;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi.Browser;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Browser/ClientWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Json.Converters;
using System.Text.Json.Serialization;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi.Browser;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Browser/ClientWindowInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Json.Converters;
using System.Text.Json.Serialization;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi.Browser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Input;
using System.Collections.Generic;

namespace OpenQA.Selenium.BiDi.BrowsingContext;

Expand Down
Loading