KEMBAR78
Handle CA1416 violations found in MAUI repo by buyaa-n · Pull Request #6237 · dotnet/maui · GitHub
Skip to content

Conversation

@buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Apr 19, 2022

Fix Platform Compatibility Analyzer CA1416 violations found in MAUI repo

There is several issues found while evaluating the violations:

  1. Platform annotation issues in Microsoft.iOS assembly. Xamarin annotation related warnings, these are suppressed with a link to the issue so that it can be removed/evaluated again after the issue resolved:
    #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
  2. Plenty of warnings caused by unsupported APIs, MAUI team informed that those are mostly deprecated but still works, there is many more found in other projects which needs review from the team. These are mostly suppressed with TODO:
    • #pragma warning disable CA1416 // TODO: 'UIApplication.KeyWindow' is unsupported on: 'ios' 13.0 and later.
    • Or asserted: System.Diagnostics.Debug.Assert(!OperatingSystem.IsIOSVersionAtLeast(14));
  3. Warnings caused by supported version of the API were mostly guarded as needed and the PR adds a few more guard, or propagates the warning to the caller with corresponding annotation in a very few cases it is suppressed which needs the team review in the future
  4. There is a few known false positives that will not be fixed which are suppressed with: #pragma warning disable CA1416 // Known false positive with Lambda expression
  5. Several analyzer bugs found and most of them fixed, the repo is dogfooding the analyzer build to consume the fixes. 2 scenarios haven't been fixed from False positives in flow analysis found in Platform compatibility analyzer roslyn-analyzers#5938, if def conditional with a negation operator is not working for related platforms (iOS and MacCatalyst), this violation found several times and all are suppressed
  6. A few warnings found for CA1307;CA1309: Use ordinal StringComparison and fixed as needed

The PR now ready for review

Fixes #823

@buyaa-n buyaa-n requested a review from a team as a code owner April 19, 2022 15:39
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Looking really good and this is a long running PR with loads of changes. And a extra 👍 for the follow up issue.

I added a few comments that I think are API binding errors, s o maybe we should just ignore for now.

And then Shane's comment on the Debug.Assert. If there are things that will throw at runtime, then maybe we should actually not execute?

Comment on lines +181 to +184
#pragma warning disable CA1416 // TODO: 'UINavigationBar.PrefersLargeTitles' is only supported on: 'ios' 11.0 and later
bool CanUseRefreshControlProperty() =>
this.GetNavigationController()?.NavigationBar?.PrefersLargeTitles ?? true;
#pragma warning restore CA1416
Copy link
Member

Choose a reason for hiding this comment

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

Should this not just use a => IsAtLeast(11) && this.xxx.Prefers == true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, I was not sure because that could cause behavioral change, it is returning true if its null, which is strange

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Apr 27, 2022

I added a few comments that I think are API binding errors, s o maybe we should just ignore for now.

Thanks, suppressed with a link to the existing issues for iOS and Android

And then Shane's comment on the Debug.Assert. If there are things that will throw at runtime, then maybe we should actually not execute?

I have suppressed the Debug.Asserts @PureWeen pointed out. Now a few left, it will only throw in Debug mode, so could throw on dev's local builds/tests or on CI build/test, I thought that could be helpful to catch unsupported platforms during development, but should not cause issue for customers by assuming that they would only consume Release build. But if you guys prefer to suppress instead let me know, I can update.

@mattleibow mattleibow merged commit c963d0a into dotnet:main Apr 28, 2022
akoeplinger added a commit to akoeplinger/maui that referenced this pull request Apr 28, 2022
akoeplinger added a commit to akoeplinger/maui that referenced this pull request Apr 28, 2022
mattleibow pushed a commit that referenced this pull request Apr 29, 2022
#6636)

* Restore and fix tvOS checks and annotations

Some of them got lost in #6237

* Remove PlatformVersion and use OperatingSystem APIs directly
@buyaa-n buyaa-n deleted the pca_analyzer2 branch April 29, 2022 17:45
maxkatz6 pushed a commit to AvaloniaUI/Avalonia.Essentials that referenced this pull request May 15, 2023
…n (#6636)

* Restore and fix tvOS checks and annotations

Some of them got lost in dotnet/maui#6237

* Remove PlatformVersion and use OperatingSystem APIs directly
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@samhouts samhouts added the fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Platform Compatibility Code Analysis Violations

4 participants