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

Trwalke/ruleset updates #3189

Merged
merged 2 commits into from
Mar 15, 2022
Merged

Trwalke/ruleset updates #3189

merged 2 commits into from
Mar 15, 2022

Conversation

trwalke
Copy link
Member

@trwalke trwalke commented Feb 25, 2022

Fixes #
Ruleset update

Changes proposed in this request
Enabling critical Async Threading rules
Adding ruleset from asp.net repo

dotnet_diagnostic.VSTHRD010.severity = warning

# Use AsyncLazy<T>
dotnet_diagnostic.VSTHRD011.severity = none #error requires the use of Microsoft.VisualStudio.Threading to get access to the AsyncLazy<T> type
Copy link
Member Author

Choose a reason for hiding this comment

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

inorder to enable this we need to use Microsoft.VisualStudio.Threading but the package is not compatable with our .net 45 targets. same with some other older targets.

@bgavrilMS

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, bummer.

@trwalke
Copy link
Member Author

trwalke commented Feb 25, 2022

I fixed a bunch of errors already but these rules produce an extra 100+ warnings and it may be easier to disable the problematic rules but not sure. Thoughts @bgavrilMS? Should I keep going?

image

VSTHRD002 Avoid problematic synchronous waits Critical 2nd rule Warning
VSTHRD003 Avoid awaiting foreign Tasks Critical 3rd rule Warning

Reference Here

@@ -14,20 +14,20 @@ namespace Microsoft.Identity.Client.Platforms
{
internal static class WebAuthenticationCoreManagerInterop
{
public static IAsyncOperation<WebTokenRequestResult> RequestTokenForWindowAsync(IntPtr hWnd, WebTokenRequest request)
Copy link
Member

Choose a reason for hiding this comment

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

These operations are async, but not in the traditional "way", but in the Windows way. You can create your own async API which can be await-ed by simply implementing an interface. The "async" suffix should be here. Please disable the rule for this file.

@@ -190,7 +190,7 @@ private async void OnAcquireSilentlyClickedAsync(object sender, EventArgs e)
}
}

private async void OnAcquireClickedAsync(object sender, EventArgs e)
private async Task OnAcquireClickedAsync(object sender, EventArgs e)
Copy link
Member

Choose a reason for hiding this comment

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

Does the app continue to work? I was under the impression that async event handlers cannot use Task. This is the whole reason why we still have async void allowed in the language.

@@ -61,7 +61,6 @@ public static string GetiOSAccountKey(string homeAccountId, string environment)
return stringBuilder.ToString().ToLowerInvariant();
}


public static string GetiOSServiceKey(
Copy link
Contributor

Choose a reason for hiding this comment

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

no changes here, same with some many other files.

requestPtr,
webAccountPtr,
ref guid,
requestPtr,
Copy link
Contributor

Choose a reason for hiding this comment

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

was this edit based on a rule?

[HttpGet]
#pragma warning disable UseAsyncSuffix // Use Async suffix
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "<Pending>")]
Copy link
Contributor

Choose a reason for hiding this comment

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

few pending justifications?

@bgavrilMS
Copy link
Member

This is a huge PR that touches a lot of files, so it must be closed quickly, otherwise merging will be hell.

@@ -140,6 +140,7 @@
<Compile Include="$(PathToMsalSources)\**\*.cs" Exclude="$(PathToMsalSources)\obj\**\*.*" />
<Compile Remove="$(PathToMsalSources)\Platforms\**\*.*;$(PathToMsalSources)\Resources\*.cs" />
<Compile Remove="$(PathToMsalSources)\PlatformsCommon\PlatformNotSupported\ApiConfig\SystemWebViewOptions.cs" />
<Compile Remove="GlobalSuppressions3.cs" />
Copy link
Member Author

Choose a reason for hiding this comment

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

Probably dont need this?

@trwalke
Copy link
Member Author

trwalke commented Mar 10, 2022

Getting some strange errors around .net 4.8 after merging in master. Are you aware of any changes to .net 48?

@bgavrilMS
Copy link
Member

@trwalke - yeah, I'm trying to convert all our dev apps to net48, since net47 and net461 are no longer installed by default with VS.

@bgavrilMS bgavrilMS marked this pull request as ready for review March 11, 2022 17:19
@pmaytak pmaytak self-requested a review March 14, 2022 19:29
Copy link
Contributor

@pmaytak pmaytak left a comment

Choose a reason for hiding this comment

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

Main comment is that it could be cleaner to disable some rules in the test editorconfig, instead of adding pragma disable or suppression files. Also can maybe add editorconfigs to different folders, since they are hierarchical.

This should also be merged right after the WAM bug fix PR before any other ones.

dotnet_diagnostic.VSTHRD110.severity = none

#------------------------------------------------------------------------------------------------------------------------------------------------------------#
# Rules from aspnet
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a link here to the page with rules descriptions. I think it's this one, https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/, but may be something else.

dotnet_diagnostic.CA1507.severity = warning

# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = suggestion
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be a warning or error for public API. But should probably be left for a seprate PR.


# IDE0036: Order modifiers
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
dotnet_diagnostic.IDE0036.severity = warning
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe set this to none (or at least for now), I don't think we follow the order and might create a lot of warnings.

dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = warning

# CA1018: Mark attributes with AttributeUsageAttribute
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem to be duplicates of ones above.

@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of GlobalSuppressions and pragma disable in code, can these rules be disabled in tests editorconfig for all tests?

@bgavrilMS bgavrilMS merged commit 5e29d34 into master Mar 15, 2022
@bgavrilMS bgavrilMS deleted the trwalke/ruleset_updates branch March 15, 2022 18:38
Csaba8472 added a commit to Csaba8472/microsoft-authentication-library-for-dotnet that referenced this pull request Apr 24, 2022
…library-for-dotnet

* 'master' of github.com:AzureAD/microsoft-authentication-library-for-dotnet: (39 commits)
  OBO for SP with RT support (AzureAD#3266) (AzureAD#3280)
  Update some projects to net48 (AzureAD#3269)
  Bump Source Link version (tool change) (AzureAD#3275)
  Update changelog.txt (AzureAD#3282)
  Default to WebView1 instead of WebView2 when using AAD or ADFS authorities (AzureAD#3276)
  Revert "OBO for SP with RT support (AzureAD#3266)"
  OBO for SP with RT support (AzureAD#3266)
  Add perf tests for Acquire Token calls with serialization cache and Builders (AzureAD#3250)
  Minor fix to SuggestedCacheKey comment and update NuGet icon in Readme. (AzureAD#3268)
  MSAL changelog 4.43.0 (AzureAD#3263)
  Bogavril/3251 (AzureAD#3255)
  Fix for AzureAD#3248 - use the correct plugin to sing out (AzureAD#3253)
  Performance project improvements (AzureAD#3064)
  Reuse lists in token cache filtering logic. (AzureAD#3233)
  Update andorid install script to use andorid 30 (AzureAD#3243)
  Fix for UWP packaging (AzureAD#3239)
  Pass account to Auth result (AzureAD#3199)
  App ported to Lab4 (AzureAD#3229)
  Trwalke/ruleset updates (AzureAD#3189)
  Conditional Access for Android (AzureAD#3210)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants