Skip to content

Commit 0d982fb

Browse files
authored
Merge pull request #39 from itmo-is-dev/feat/private-properties
feat: MemberAccessibility
2 parents 56d282c + 04db866 commit 0d982fb

33 files changed

Lines changed: 627 additions & 93 deletions

File tree

SourceKit.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Propert
8989
EndProject
9090
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Reflect.Samples", "samples\SourceKit.Reflect.Samples\SourceKit.Reflect.Samples.csproj", "{B3EEEF25-A90E-404F-9874-93A2E6990468}"
9191
EndProject
92+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.MemberAccessibility.Samples", "samples\analyzers\SourceKit.Analyzers.MemberAccessibility.Samples\SourceKit.Analyzers.MemberAccessibility.Samples.csproj", "{6D49F53F-4765-4108-9AA7-1470D5FB8FD7}"
93+
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.MemberAccessibility.Tests", "tests\SourceKit.Analyzers.MemberAccessibility.Tests\SourceKit.Analyzers.MemberAccessibility.Tests.csproj", "{EACEDBCD-081E-4F95-A81E-B62CD18D3028}"
95+
EndProject
9296
Global
9397
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9498
Debug|Any CPU = Debug|Any CPU
@@ -131,6 +135,8 @@ Global
131135
{35F679FA-4F45-4870-B7C6-7B31A6CD014F} = {365210F4-5F33-49FD-9E14-552154E26285}
132136
{4B54BDA0-D16F-428F-97D2-03654311CE22} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE}
133137
{B3EEEF25-A90E-404F-9874-93A2E6990468} = {68973D47-37E1-492E-8F62-E94B002349BB}
138+
{6D49F53F-4765-4108-9AA7-1470D5FB8FD7} = {365210F4-5F33-49FD-9E14-552154E26285}
139+
{EACEDBCD-081E-4F95-A81E-B62CD18D3028} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE}
134140
EndGlobalSection
135141
GlobalSection(ProjectConfigurationPlatforms) = postSolution
136142
{637C01C1-3A3C-4FC6-9874-6CFBA4319A79}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -249,5 +255,13 @@ Global
249255
{B3EEEF25-A90E-404F-9874-93A2E6990468}.Debug|Any CPU.Build.0 = Debug|Any CPU
250256
{B3EEEF25-A90E-404F-9874-93A2E6990468}.Release|Any CPU.ActiveCfg = Release|Any CPU
251257
{B3EEEF25-A90E-404F-9874-93A2E6990468}.Release|Any CPU.Build.0 = Release|Any CPU
258+
{6D49F53F-4765-4108-9AA7-1470D5FB8FD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
259+
{6D49F53F-4765-4108-9AA7-1470D5FB8FD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
260+
{6D49F53F-4765-4108-9AA7-1470D5FB8FD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
261+
{6D49F53F-4765-4108-9AA7-1470D5FB8FD7}.Release|Any CPU.Build.0 = Release|Any CPU
262+
{EACEDBCD-081E-4F95-A81E-B62CD18D3028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
263+
{EACEDBCD-081E-4F95-A81E-B62CD18D3028}.Debug|Any CPU.Build.0 = Debug|Any CPU
264+
{EACEDBCD-081E-4F95-A81E-B62CD18D3028}.Release|Any CPU.ActiveCfg = Release|Any CPU
265+
{EACEDBCD-081E-4F95-A81E-B62CD18D3028}.Release|Any CPU.Build.0 = Release|Any CPU
252266
EndGlobalSection
253267
EndGlobal
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.cs]
2+
3+
dotnet_diagnostic.SK1100.severity = warning
4+
dotnet_diagnostic.SK1101.severity = warning
5+
dotnet_diagnostic.SK1102.severity = warning
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class MultipleFieldsCaseFixed
4+
{
5+
private object _first;
6+
private object _second;
7+
private object _third;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class MultipleFieldsCase
4+
{
5+
private object _first, _second, _third;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class PrivatePropertyCaseFixed
4+
{
5+
public object PrivateProperty { get; }
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class PrivatePropertyCase
4+
{
5+
private object PrivateProperty { get; }
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class PublicFieldTestCaseFixed
4+
{
5+
private object _publicField;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceKit.Analyzers.MemberAccessibility.Samples;
2+
3+
public class PublicFieldTestCase
4+
{
5+
public object _publicField;
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>disable</ImplicitUsings>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="SourceKit.Analyzers.MemberAccessibility"/>
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<Compile Update="MultipleFieldsCase.Fixed.cs">
13+
<DependentUpon>MultipleFieldsCase.cs</DependentUpon>
14+
</Compile>
15+
<Compile Update="PrivatePropertyCase.Fixed.cs">
16+
<DependentUpon>PrivatePropertyCase.cs</DependentUpon>
17+
</Compile>
18+
<Compile Update="PublicFieldTestCase.Fixed.cs">
19+
<DependentUpon>PublicFieldTestCase.cs</DependentUpon>
20+
</Compile>
21+
</ItemGroup>
22+
23+
</Project>

src/analyzers/SourceKit.Analyzers.Collections/Analyzers/DictionaryKeyTypeMustImplementEquatableAnalyzer.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private void AnalyzeGeneric(SyntaxNodeAnalysisContext context)
3636
{
3737
var node = (GenericNameSyntax)context.Node;
3838

39-
if (context.SemanticModel.GetDeclaredSymbol(node) is not INamedTypeSymbol symbol)
39+
if (context.SemanticModel.GetSymbolInfo(node).Symbol is not INamedTypeSymbol symbol)
4040
return;
4141

4242
if (TryGetDictionaryKeySymbol(symbol, typeof(Dictionary<,>), context, out INamedTypeSymbol? keySymbol) is false
@@ -54,17 +54,14 @@ private void AnalyzeGeneric(SyntaxNodeAnalysisContext context)
5454

5555
INamedTypeSymbol equatableSymbol = context.Compilation.GetTypeSymbol(typeof(IEquatable<>));
5656

57-
INamedTypeSymbol madeEquatableSymbol = equatableSymbol
58-
.Construct(keySymbol.WithNullableAnnotation(NullableAnnotation.None));
59-
6057
IEnumerable<INamedTypeSymbol> foundEquatableSymbols = keySymbol
6158
.FindAssignableTypesConstructedFrom(equatableSymbol);
6259

6360
bool hasCorrectEquatableImplementation = foundEquatableSymbols
6461
.Select(x => x.TypeArguments.First())
65-
.Any(x => madeEquatableSymbol.Equals(x, SymbolEqualityComparer.Default));
62+
.Any(x => keySymbol.Equals(x, SymbolEqualityComparer.Default) || keySymbol.IsAssignableTo(x));
6663

67-
if (hasCorrectEquatableImplementation is false)
64+
if (hasCorrectEquatableImplementation)
6865
return;
6966

7067
var diag = Diagnostic.Create(Descriptor, node.GetLocation());

0 commit comments

Comments
 (0)