Skip to content

Commit facbf82

Browse files
committed
Merge roslyn-analyzers into the roslyn repo.
2 parents 3e2d972 + 9292ef7 commit facbf82

File tree

937 files changed

+281201
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

937 files changed

+281201
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<appSettings>
4+
<add key="xunit.shadowCopy" value="false"/>
5+
</appSettings>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<!--
6+
PackageId is used by Restore. If we set it to Microsoft.CodeAnalysis.AnalyzerUtilities,
7+
Restore would conclude that there is a cyclic dependency between us and the Microsoft.CodeAnalysis.AnalyzerUtilities package.
8+
-->
9+
<PackageId>*$(MSBuildProjectFile)*</PackageId>
10+
<ExcludeInternalFlowAnalyses>true</ExcludeInternalFlowAnalyses>
11+
<ExcludeCodeMetricsUtilities>true</ExcludeCodeMetricsUtilities>
12+
<ReleaseTrackingOptOut>true</ReleaseTrackingOptOut>
13+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
14+
15+
<!-- RS0026: Avoid public API overloads with differences in optional parameters -->
16+
<NoWarn>$(NoWarn);RS0026</NoWarn>
17+
<MicrosoftCodeAnalysisVersion>$(MicrosoftCodeAnalysisVersionForCodeAnalysisAnalyzers)</MicrosoftCodeAnalysisVersion>
18+
</PropertyGroup>
19+
<Import Project="..\Utilities\Compiler\Analyzer.Utilities.projitems" Label="Shared" />
20+
<Import Project="..\Utilities\FlowAnalysis\FlowAnalysis.Utilities.projitems" Label="Shared" />
21+
<ItemGroup>
22+
<AdditionalFiles Include="PublicAPI.Shipped.txt" />
23+
<AdditionalFiles Include="PublicAPI.Unshipped.txt" />
24+
</ItemGroup>
25+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


src/RoslynAnalyzers/Microsoft.CodeAnalysis.AnalyzerUtilities/PublicAPI.Unshipped.txt

Lines changed: 859 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Release 2.9.8
2+
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
--------|----------|----------|-------
7+
RS1014 | MicrosoftCodeAnalysisCorrectness | Warning | CSharpImmutableObjectMethodAnalyzer
8+
9+
## Release 3.3.4
10+
11+
### Removed Rules
12+
13+
Rule ID | Category | Severity | Notes
14+
--------|----------|----------|-------
15+
RS1014 | MicrosoftCodeAnalysisCorrectness | Warning | CSharpImmutableObjectMethodAnalyzer
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; Please do not edit this file manually, it should only be updated through code fix application.
2+
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
--------|----------|----------|-------
7+
RS1039 | MicrosoftCodeAnalysisCorrectness | Warning | SemanticModelGetDeclaredSymbolAlwaysReturnsNullAnalyzer
8+
RS1040 | MicrosoftCodeAnalysisCorrectness | Warning | CSharpSemanticModelGetDeclaredSymbolAlwaysReturnsNullAnalyzer
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
2+
3+
using Analyzer.Utilities.Extensions;
4+
using Microsoft.CodeAnalysis.Analyzers;
5+
using Microsoft.CodeAnalysis.CSharp.Syntax;
6+
using Microsoft.CodeAnalysis.Diagnostics;
7+
8+
namespace Microsoft.CodeAnalysis.CSharp.Analyzers
9+
{
10+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
11+
public class CSharpUpgradeMSBuildWorkspaceAnalyzer : UpgradeMSBuildWorkspaceAnalyzer
12+
{
13+
protected override void RegisterIdentifierAnalysis(CompilationStartAnalysisContext context)
14+
{
15+
context.RegisterSyntaxNodeAction(AnalyzeIdentifier, SyntaxKind.IdentifierName);
16+
}
17+
18+
private void AnalyzeIdentifier(SyntaxNodeAnalysisContext context)
19+
{
20+
if (context.Node is IdentifierNameSyntax identifierName &&
21+
identifierName.Identifier.ToString() == MSBuildWorkspace)
22+
{
23+
var symbolInfo = context.SemanticModel.GetSymbolInfo(identifierName, context.CancellationToken);
24+
if (symbolInfo.Symbol == null)
25+
{
26+
context.ReportDiagnostic(identifierName.CreateDiagnostic(UpgradeMSBuildWorkspaceDiagnosticRule));
27+
}
28+
}
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
2+
3+
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
4+
using Microsoft.CodeAnalysis.CSharp.Syntax;
5+
using Microsoft.CodeAnalysis.Diagnostics;
6+
7+
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
8+
{
9+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10+
public class CSharpDiagnosticAnalyzerApiUsageAnalyzer : DiagnosticAnalyzerApiUsageAnalyzer<TypeSyntax>
11+
{
12+
protected override bool IsNamedTypeDeclarationBlock(SyntaxNode syntax)
13+
{
14+
return syntax.Kind() switch
15+
{
16+
SyntaxKind.ClassDeclaration
17+
or SyntaxKind.StructDeclaration
18+
or SyntaxKind.EnumDeclaration
19+
#if CODEANALYSIS_V3_OR_BETTER
20+
or SyntaxKind.RecordDeclaration:
21+
#endif
22+
or SyntaxKind.InterfaceDeclaration => true,
23+
_ => false,
24+
};
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
2+
3+
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
4+
using Microsoft.CodeAnalysis.CSharp.Syntax;
5+
using Microsoft.CodeAnalysis.Diagnostics;
6+
7+
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
8+
{
9+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
10+
public class CSharpDiagnosticAnalyzerFieldsAnalyzer : DiagnosticAnalyzerFieldsAnalyzer<ClassDeclarationSyntax, StructDeclarationSyntax, FieldDeclarationSyntax, TypeSyntax, VariableDeclarationSyntax, TypeArgumentListSyntax, GenericNameSyntax>
11+
{
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
2+
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Analyzer.Utilities.Extensions;
6+
using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
8+
using Microsoft.CodeAnalysis.Diagnostics;
9+
10+
namespace Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers
11+
{
12+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
13+
public class CSharpRegisterActionAnalyzer : RegisterActionAnalyzer<InvocationExpressionSyntax, ArgumentSyntax, SyntaxKind>
14+
{
15+
internal const string CSharpSyntaxKindName = @"Microsoft.CodeAnalysis.CSharp.SyntaxKind";
16+
internal const string BasicSyntaxKindName = @"Microsoft.CodeAnalysis.VisualBasic.SyntaxKind";
17+
18+
protected override RegisterActionCodeBlockAnalyzer GetCodeBlockAnalyzer(
19+
Compilation compilation,
20+
INamedTypeSymbol analysisContext,
21+
INamedTypeSymbol compilationStartAnalysisContext,
22+
INamedTypeSymbol codeBlockStartAnalysisContext,
23+
INamedTypeSymbol operationBlockStartAnalysisContext,
24+
INamedTypeSymbol symbolKind)
25+
{
26+
INamedTypeSymbol? csharpSyntaxKind = compilation.GetOrCreateTypeByMetadataName(CSharpSyntaxKindName);
27+
INamedTypeSymbol? basicSyntaxKind = compilation.GetOrCreateTypeByMetadataName(BasicSyntaxKindName);
28+
return new CSharpRegisterActionCodeBlockAnalyzer(csharpSyntaxKind, basicSyntaxKind, analysisContext, compilationStartAnalysisContext,
29+
codeBlockStartAnalysisContext, operationBlockStartAnalysisContext, symbolKind);
30+
}
31+
32+
private sealed class CSharpRegisterActionCodeBlockAnalyzer : RegisterActionCodeBlockAnalyzer
33+
{
34+
private readonly ITypeSymbol? _csharpSyntaxKind, _basicSyntaxKind;
35+
36+
public CSharpRegisterActionCodeBlockAnalyzer(
37+
INamedTypeSymbol? csharpSyntaxKind,
38+
INamedTypeSymbol? basicSyntaxKind,
39+
INamedTypeSymbol analysisContext,
40+
INamedTypeSymbol compilationStartAnalysisContext,
41+
INamedTypeSymbol codeBlockStartAnalysisContext,
42+
INamedTypeSymbol operationBlockStartAnalysisContext,
43+
INamedTypeSymbol symbolKind)
44+
: base(analysisContext, compilationStartAnalysisContext, codeBlockStartAnalysisContext, operationBlockStartAnalysisContext, symbolKind)
45+
{
46+
_csharpSyntaxKind = csharpSyntaxKind;
47+
_basicSyntaxKind = basicSyntaxKind;
48+
}
49+
50+
protected override SyntaxKind InvocationExpressionKind => SyntaxKind.InvocationExpression;
51+
protected override SyntaxKind ArgumentSyntaxKind => SyntaxKind.Argument;
52+
protected override SyntaxKind ParameterSyntaxKind => SyntaxKind.Parameter;
53+
54+
protected override IEnumerable<SyntaxNode>? GetArgumentExpressions(InvocationExpressionSyntax invocation)
55+
{
56+
if (invocation.ArgumentList != null)
57+
{
58+
return invocation.ArgumentList.Arguments.Select(a => a.Expression);
59+
}
60+
61+
return null;
62+
}
63+
64+
protected override SyntaxNode GetArgumentExpression(ArgumentSyntax argument)
65+
{
66+
return argument.Expression;
67+
}
68+
69+
protected override SyntaxNode GetInvocationExpression(InvocationExpressionSyntax invocation)
70+
{
71+
return invocation.Expression;
72+
}
73+
74+
protected override SyntaxNode? GetInvocationReceiver(InvocationExpressionSyntax invocation)
75+
{
76+
return (invocation.Expression as MemberAccessExpressionSyntax)?.Expression;
77+
}
78+
79+
protected override bool IsSyntaxKind(ITypeSymbol type)
80+
=> SymbolEqualityComparer.Default.Equals(type, _csharpSyntaxKind)
81+
|| SymbolEqualityComparer.Default.Equals(type, _basicSyntaxKind);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)