-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update NimbleBlazor NI.CSharp.Analyzers to v2.0.21 (with code fixes) (#…
…1867) # Pull Request ## 🤨 Rationale - Update NimbleBlazor NI.CSharp.Analyzers to v2.0.21 (as Renovate started in [!1696](#1696) ) - Add an `.editorconfig` that allows us to further customize rules/standards ([Microsoft docs](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options)). Most of the rules I have in this one were added based on the specific failed rules/ errors triggered for the Nimble Blazor code ## 👩💻 Implementation Most of the file diffs are from standardizing on file-scoped namespace declarations (as previously discussed with Meyer). I opted to disable these rules for the same of this PR, to keep the number of changes to review smaller: - Rules requiring pattern matching - Rules for [expression-bodied members](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members) - Rules covering ['var' preferences](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008) There were some additional spurious errors/warnings being triggered for our .razor.cs files, for which I included comments in the editorconfig. For reference, [the .editorconfig from the ASW repo root](https://dev.azure.com/ni/DevCentral/_git/ASW?path=%2F.editorconfig&_a=contents&version=GBmain) ## 🧪 Testing PR build, glanced over Blazor example app in Storybook. Release build in Visual Studio ## ✅ Checklist <!--- Review the list and put an x in the boxes that apply or ~~strike through~~ around items that don't (along with an explanation). --> - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1739946
commit c60a533
Showing
40 changed files
with
763 additions
and
727 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-blazor-2f401368-17a1-4382-99d5-3eff4d6752dc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Uptake new code analyzer rules, minor code cleanup", | ||
"packageName": "@ni/nimble-blazor", | ||
"email": "20709258+msmithNI@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[*.cs] | ||
|
||
csharp_style_namespace_declarations = file_scoped:warning | ||
csharp_prefer_simple_using_statement = false | ||
dotnet_style_prefer_conditional_expression_over_return = false | ||
|
||
# Disable: Remove unnecessary expression value (_/discard not required) | ||
dotnet_diagnostic.IDE0058.severity = none | ||
|
||
# Rules for the use of 'var': | ||
dotnet_diagnostic.IDE0007.severity = none | ||
dotnet_diagnostic.IDE0008.severity = none | ||
# Note: ASW generally uses the settings below, may opt in in the future. | ||
# csharp_style_var_for_built_in_types = false | ||
# csharp_style_var_when_type_is_apparent = true | ||
# csharp_style_var_elsewhere = false | ||
|
||
# Expression-bodied members | ||
# Note: May switch to when_on_single_line for methods/properties/accessors | ||
# in the future | ||
# csharp_style_expression_bodied_methods | ||
dotnet_diagnostic.IDE0022.severity = none | ||
# csharp_style_expression_bodied_properties | ||
dotnet_diagnostic.IDE0025.severity = none | ||
# csharp_style_expression_bodied_indexers | ||
dotnet_diagnostic.IDE0026.severity = none | ||
# csharp_style_expression_bodied_accessors | ||
dotnet_diagnostic.IDE0027.severity = none | ||
|
||
# Use 'switch' expression | ||
dotnet_diagnostic.IDE0066.severity = none | ||
|
||
# Pattern matching | ||
# Disable general pattern matching rule for now, may opt in in the future | ||
dotnet_diagnostic.IDE0078.severity = none | ||
|
||
[*.razor.cs] | ||
# Spurious 'unused' warnings when properties/methods are only used from Razor files | ||
dotnet_diagnostic.IDE0051.severity = none | ||
dotnet_diagnostic.IDE0052.severity = none | ||
# 'Make field readonly' incorrectly triggered for component _refs | ||
dotnet_diagnostic.IDE0044.severity = none | ||
|
||
[Program.cs] | ||
# Spurious 'unnecessary using' warnings | ||
dotnet_diagnostic.IDE0005.severity = none | ||
|
||
[Tests/NimbleBlazor.Tests.Acceptance/Tests/*.cs] | ||
dotnet_style_namespace_match_folder = false | ||
# Disable 'Namespace does not match folder structure' | ||
dotnet_diagnostic.IDE0130.severity = none | ||
|
||
[Examples/Demo.Shared/Shared/*.cs] | ||
dotnet_style_namespace_match_folder = false | ||
# Disable 'Namespace does not match folder structure' | ||
dotnet_diagnostic.IDE0130.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
namespace Demo.Hybrid | ||
{ | ||
using System.Windows; | ||
using System.Windows; | ||
|
||
namespace Demo.Hybrid; | ||
|
||
/// <summary> | ||
/// Interaction logic for App.xaml. | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
/// <summary> | ||
/// Interaction logic for App.xaml. | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 26 additions & 29 deletions
55
packages/nimble-blazor/Examples/Demo.Hybrid/MainWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
namespace Demo.Hybrid | ||
{ | ||
using System.Windows; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Windows; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Demo.Hybrid; | ||
|
||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml. | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml. | ||
/// Initializes a new instance of the <see cref="MainWindow"/> class. | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
public MainWindow() | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MainWindow"/> class. | ||
/// </summary> | ||
public MainWindow() | ||
{ | ||
this.InitializeComponent(); | ||
InitializeComponent(); | ||
#if RELEASE | ||
this.Loaded += this.MainWindow_Loaded; | ||
Loaded += MainWindow_Loaded; | ||
#endif | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddWpfBlazorWebView(); | ||
serviceCollection.AddBlazorWebViewDeveloperTools(); | ||
#pragma warning disable NI1004 | ||
this.Resources.Add("services", serviceCollection.BuildServiceProvider()); | ||
#pragma warning restore NI1004 | ||
} | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddWpfBlazorWebView(); | ||
serviceCollection.AddBlazorWebViewDeveloperTools(); | ||
Resources.Add("services", serviceCollection.BuildServiceProvider()); | ||
} | ||
|
||
#if RELEASE | ||
#pragma warning disable VSTHRD100 // Avoid async void methods | ||
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) | ||
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) | ||
#pragma warning restore VSTHRD100 // Avoid async void methods | ||
{ | ||
// We recommend for Release versions to turn off browser accelerator keys | ||
// for applications that are meant to operate more like a native desktop app. | ||
await this.blazorWebView.WebView.EnsureCoreWebView2Async().ConfigureAwait(true); | ||
var settings = this.blazorWebView.WebView.CoreWebView2.Settings; | ||
settings.AreBrowserAcceleratorKeysEnabled = false; | ||
} | ||
#endif | ||
{ | ||
// We recommend for Release versions to turn off browser accelerator keys | ||
// for applications that are meant to operate more like a native desktop app. | ||
await blazorWebView.WebView.EnsureCoreWebView2Async().ConfigureAwait(true); | ||
var settings = blazorWebView.WebView.CoreWebView2.Settings; | ||
settings.AreBrowserAcceleratorKeysEnabled = false; | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.