-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GH-11] - attempting generate suppression file
- Loading branch information
Showing
19 changed files
with
321 additions
and
33 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
src/NSubstitute.Analyzers.CSharp.Vsix/NSubstitute.Analyzers.CSharp.Vsix.csproj
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,79 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. --> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<FileUpgradeFlags> | ||
</FileUpgradeFlags> | ||
<OldToolsVersion>14.0</OldToolsVersion> | ||
<UpgradeBackupLocation /> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> | ||
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<ProjectGuid>{4DF03310-98B3-450E-90FE-2EF423A6CC59}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>NSubstitute.Analyzers2.CSharp.Vsix</RootNamespace> | ||
<AssemblyName>NSubstitute.Analyzers2.CSharp</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<GeneratePkgDefFile>false</GeneratePkgDefFile> | ||
<IncludeAssemblyInVSIXContainer>false</IncludeAssemblyInVSIXContainer> | ||
<IncludeDebugSymbolsInVSIXContainer>false</IncludeDebugSymbolsInVSIXContainer> | ||
<IncludeDebugSymbolsInLocalVSIXDeployment>false</IncludeDebugSymbolsInLocalVSIXDeployment> | ||
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory> | ||
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory> | ||
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartAction>Program</StartAction> | ||
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram> | ||
<StartArguments>/rootsuffix Roslyn</StartArguments> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="source.extension.vsixmanifest"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\NSubstitute.Analyzers.CSharp\NSubstitute.Analyzers.CSharp.csproj"> | ||
<Project>{27CBFCE9-8E54-4EA1-8417-70BEB8F97E5B}</Project> | ||
<Name>NSubstitute.Analyzers.CSharp</Name> | ||
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3b</IncludeOutputGroupsInVSIX> | ||
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly> | ||
</ProjectReference> | ||
<ProjectReference Include="..\NSubstitute.Analyzers.Shared\NSubstitute.Analyzers.Shared.csproj"> | ||
<Project>{2b7bf4d2-4964-4674-9268-70ae5a3c98db}</Project> | ||
<Name>NSubstitute.Analyzers.Shared</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json"> | ||
<Version>11.0.2</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
22 changes: 22 additions & 0 deletions
22
src/NSubstitute.Analyzers.CSharp.Vsix/source.extension - Copy.vsixmanifest
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011"> | ||
<Metadata> | ||
<Identity Id="NSubstitute.Analyzers.CSharp.d429c94d-b39b-4294-99cd-205607d7d485" Version="1.0" Language="en-US" Publisher="Tomek"/> | ||
<DisplayName>NSubstitute.Analyzers.CSharp</DisplayName> | ||
<Description xml:space="preserve">This is a sample diagnostic extension for the .NET Compiler Platform ("Roslyn").</Description> | ||
</Metadata> | ||
<Installation> | ||
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,)" /> | ||
</Installation> | ||
<Dependencies> | ||
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" /> | ||
</Dependencies> | ||
<Assets> | ||
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NSubstitute.Analyzers2.CSharp" Path="|NSubstitute.Analyzers2.CSharp|"/> | ||
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NSubstitute.Analyzers2.CSharp" Path="|NSubstitute.Analyzers2.CSharp|"/> | ||
</Assets> | ||
<Prerequisites> | ||
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,16.0)" DisplayName="Visual Studio core editor" /> | ||
<Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[15.0,16.0)" DisplayName="Roslyn Language Services" /> | ||
</Prerequisites> | ||
</PackageManifest> |
23 changes: 23 additions & 0 deletions
23
src/NSubstitute.Analyzers.CSharp.Vsix/source.extension.vsixmanifest
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011"> | ||
<Metadata> | ||
<Identity Id="NSubstitute.Analyzers.CSharp.d429c94d-b39b-4294-99cd-205607d7d485" Version="1.0" Language="en-US" Publisher="Tomek"/> | ||
<DisplayName>NSubstitute.Analyzers.CSharp</DisplayName> | ||
<Description xml:space="preserve">This is a sample diagnostic extension for the .NET Compiler Platform ("Roslyn").</Description> | ||
</Metadata> | ||
<Installation> | ||
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,)" /> | ||
</Installation> | ||
<Dependencies> | ||
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" /> | ||
</Dependencies> | ||
<Assets> | ||
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NSubstitute.Analyzers.CSharp" Path="|NSubstitute.Analyzers.CSharp|"/> | ||
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NSubstitute.Analyzers.CSharp" Path="|NSubstitute.Analyzers.CSharp|"/> | ||
<Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="NSubstitute.Analyzers.Shared" Path="|NSubstitute.Analyzers.Shared|"/> | ||
</Assets> | ||
<Prerequisites> | ||
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,16.0)" DisplayName="Visual Studio core editor" /> | ||
<Prerequisite Id="Microsoft.VisualStudio.Component.Roslyn.LanguageServices" Version="[15.0,16.0)" DisplayName="Roslyn Language Services" /> | ||
</Prerequisites> | ||
</PackageManifest> |
76 changes: 76 additions & 0 deletions
76
src/NSubstitute.Analyzers.CSharp/CodeFixProviders/SupressDiagnosticCodeFixProvider.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Newtonsoft.Json; | ||
using NSubstitute.Analyzers.Shared; | ||
using NSubstitute.Analyzers.Shared.Extensions; | ||
using NSubstitute.Analyzers.Shared.Settings; | ||
using NSubstitute.Analyzers.Shared.Threading; | ||
|
||
namespace NSubstitute.Analyzers.CSharp.CodeFixProviders | ||
{ | ||
[ExportCodeFixProvider(LanguageNames.CSharp)] | ||
public class SupressDiagnosticCodeFixProvider : CodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticIdentifiers.NonVirtualSetupSpecification); | ||
|
||
public override Task RegisterCodeFixesAsync(CodeFixContext context) | ||
{ | ||
var project = context.Document.Project; | ||
var workspace = project.Solution.Workspace; | ||
|
||
// check if we are allowed to add it | ||
if (!workspace.CanApplyChange(ApplyChangesKind.AddAdditionalDocument)) | ||
{ | ||
return SpecializedTasks.CompletedTask; | ||
} | ||
|
||
foreach (var diagnostic in context.Diagnostics) | ||
{ | ||
context.RegisterCodeFix( | ||
CodeAction.Create( | ||
"Suppress in nsubstitute.json", // TODO proper message | ||
cancellationToken => GetTransformedSolutionAsync(context, diagnostic), | ||
nameof(SupressDiagnosticCodeFixProvider)), | ||
diagnostic); | ||
} | ||
|
||
return SpecializedTasks.CompletedTask; | ||
} | ||
|
||
private async Task<Solution> GetTransformedSolutionAsync(CodeFixContext context, Diagnostic diagnostic) | ||
{ | ||
var options = context.Document.Project.AnalyzerOptions.GetSettings(default(CancellationToken)); | ||
var project = context.Document.Project; | ||
var solution = project.Solution; | ||
var root = await context.Document.GetSyntaxRootAsync().ConfigureAwait(false); | ||
var model = await context.Document.GetSemanticModelAsync(); | ||
|
||
var forPartsOfNode = (InvocationExpressionSyntax)root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true); | ||
var symbol = model.GetSymbolInfo(forPartsOfNode); | ||
|
||
var newDocumentId = DocumentId.CreateNewId(project.Id); | ||
|
||
options.Suppressions.Add(new Suppression | ||
{ | ||
Target = DocumentationCommentId.CreateDeclarationId(symbol.Symbol), | ||
Rules = new List<string> | ||
{ | ||
DiagnosticIdentifiers.NonVirtualSetupSpecification | ||
} | ||
}); | ||
|
||
var newSolution = solution.AddAdditionalDocument(newDocumentId, AnalyzersSettings.AnalyzerFileName, JsonConvert.SerializeObject(options)); | ||
|
||
return newSolution; | ||
} | ||
} | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
src/NSubstitute.Analyzers.Shared/Extensions/AdditionalTextExtensions.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.IO; | ||
using Microsoft.CodeAnalysis; | ||
using NSubstitute.Analyzers.Shared.Settings; | ||
|
||
namespace NSubstitute.Analyzers.Shared.Extensions | ||
{ | ||
public static class AdditionalTextExtensions | ||
{ | ||
public static bool IsSettingsFile(this AdditionalText additionalText) | ||
{ | ||
return Path.GetFileName(additionalText.Path).Equals(AnalyzersSettings.AnalyzerFileName, StringComparison.CurrentCultureIgnoreCase); | ||
} | ||
} | ||
} |
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.