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

Platform Specific Analyzer #2083

Merged
merged 18 commits into from
May 21, 2018
Merged

Platform Specific Analyzer #2083

merged 18 commits into from
May 21, 2018

Conversation

hermitdave
Copy link
Contributor

@hermitdave hermitdave commented May 11, 2018

Issue: #1497

PR Type

What kind of change does this PR introduce?

<- Feature >

What is the current behavior?

No platform / version analyzers

What is the new behavior?

Added Platform Specific Differences Generator and Roslyn code Analyzer + Fixer

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

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

  1. Tried it on this code and the warning showed up as expected:

    LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStreamAsync(null);
    

    However, the fix was incomplete:
    image

  2. Related, this line does not generate a warning:

    LearningModelPreview learningModel;

    should it?


# Platform Specific Analyzer

The [writing version adaptive](https://docs.microsoft.com/windows/uwp/debug-test-perf/version-adaptive-code) code, the developers should ensure that code checks for presence of API before calling it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird wording, should be

When writing version adaptive code...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

| Device family | Universal, 10.0.15063.0 or higher |
| ---------------------------------------------------------------- | ----------------------------------- |
| Namespace | Microsoft.Toolkit.Uwp.PlatformSpecificAnalyzer |
| NuGet package | [Microsoft.Toolkit.Uwp.UI.Animations](https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.PlatformSpecificAnalyzer/) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Nuget package name is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixing that too


## Installation

The analyzer is available both as a nuget package and also as Visual Studio Extention
Copy link
Contributor

Choose a reason for hiding this comment

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

Could not find the Visual Studio Extension, how do we build it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a vsix solution and building it is as easy as including it in sln however that throws VSTS errors. Need to get that looked into.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Not familiar with VSIX - what's the benefit over having a nuget package? Should we publish both?

Copy link
Member

Choose a reason for hiding this comment

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

I'm sure we can get it building in VSTS, but in general, I don't think it's as good since it requires everyone to install it. Nice part of nuget analyzers is that they are brought in with the solution so clone-open just works.

Copy link
Member

Choose a reason for hiding this comment

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

The VSIX will also need to be added to the list of items sent to the signing service. (and ensure it has the proper filter configuration)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't that the reason the analyzer template supports both vsix and nuget ?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but that's a template, doesn't mean you have to support both methods. Most analyzers that I know of just use NuGet.

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 am okay with whatever you and others think 👍 I have no idea about the sort of usage they have plus VSIX would need submissions to VS gallery etc.. maybe its not worth the effort unless there's a strong demand.

We can go nuget to start with. I will fix the docs

{
public class Program
{
private static string path = @"D:\UwpApi";
Copy link
Contributor

Choose a reason for hiding this comment

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

Path is hardcoded, should be current directory instead

<PropertyGroup>
<PackageId>Microsoft.Toolkit.Uwp.PlatformSpecificAnalyzer</PackageId>
<PackageVersion>1.0.0.0</PackageVersion>
<Authors>hermi</Authors>
Copy link
Contributor

Choose a reason for hiding this comment

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

Change author, image, and other properties to match other projects

Add ability to analyse field declaration
Correct guard instantiation
Correct documentation
Correct path in diff generator
Correct project file properties
@@ -6,22 +6,6 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
Copy link
Contributor

@nmetulev nmetulev May 16, 2018

Choose a reason for hiding this comment

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

You should still have <Title> <Description> and <PackageTags> here (see other projects for example)

@hermitdave
Copy link
Contributor Author

Beauty of VSIX is install once and use across projects. Nuget is per project. In this instance is prefer VSIX over Nuget

Maintain differences dictionary to prevent frequent loading from resource.
@hermitdave
Copy link
Contributor Author

This is feature complete I believe.
I have tested it with Types, Methods, Properties, Events for Version specific
And tested it with Type for Platform specific.

@azchohfi azchohfi self-requested a review May 18, 2018 17:40
@hermitdave
Copy link
Contributor Author

@azchohfi any good?


<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework><Title>Windows Community Toolkit UI</Title>
<Description>This .NET standard library provides analyzer and code fixer to ensure that version / platform specific code is well guarded. It is part of the Windows Community Toolkit.</Description>
Copy link
Contributor

Choose a reason for hiding this comment

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

"code fixes"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope I think the current wording is okay. There is an analyser and code fixer in the project

<Title>Windows Community Toolkit UWP Platform Specific Analyzer</Title>

<!-- This is a temporary workaround for https://github.com/dotnet/sdk/issues/955 -->
<DebugType>Full</DebugType>
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't this been fixed in the latest VS? Oren even opened an issue to remove the workaround on other Toolkit projects #1951

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'm not sure. @nmetulev asked me to make it same as other projects so I just copied that bit as was

Copy link
Contributor

Choose a reason for hiding this comment

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

@onovotny, have you verified this is fixed now - should we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be merged today and a separate PR cleaning up all projects would be a good idea if applicable

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a problem. Let's merge it.

@azchohfi azchohfi merged commit 0d970c6 into master May 21, 2018
@azchohfi azchohfi deleted the HD-PSA branch May 21, 2018 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants