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

RCS1018 - Handle 'file' modifier #1510

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1182](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1182) ([PR](https://github.com/dotnet/roslynator/pull/1502))
- Fix analyzer [RCS1198](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1198) ([PR](https://github.com/dotnet/roslynator/pull/1501))
- Fix analyzer [RCS1214](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1214) ([PR](https://github.com/dotnet/roslynator/pull/1500))
- Fix analyzer [RCS1018](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1018) ([PR](https://github.com/dotnet/roslynator/pull/1510))

## [4.12.4] - 2024-06-01

Expand Down
10 changes: 10 additions & 0 deletions src/CSharp/CSharp/SyntaxAccessibility`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public static Accessibility GetDefaultExplicitAccessibility(BaseTypeDeclarationS
if (declaration is null)
throw new ArgumentNullException(nameof(declaration));

#if ROSLYN_4_4
if (declaration.Modifiers.Contains(SyntaxKind.FileKeyword))
return Accessibility.NotApplicable;
#endif

#if ROSLYN_4_0
return (declaration.IsParentKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKind.RecordDeclaration, SyntaxKind.RecordStructDeclaration))
#else
Expand Down Expand Up @@ -354,6 +359,11 @@ public override Accessibility GetDefaultExplicitAccessibility(DelegateDeclaratio
if (declaration is null)
throw new ArgumentNullException(nameof(declaration));

#if ROSLYN_4_4
if (declaration.Modifiers.Contains(SyntaxKind.FileKeyword))
return Accessibility.NotApplicable;
#endif

if (declaration.IsParentKind(
SyntaxKind.ClassDeclaration,
SyntaxKind.StructDeclaration,
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1018AddAccessibilityModifiersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ object I.this[int index]
}
}
}
", options: Options.AddConfigOption(ConfigOptionKeys.AccessibilityModifiers, ConfigOptionValues.AccessibilityModifiers_Explicit));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddOrRemoveAccessibilityModifiers)]
public async Task TestNoDiagnostic_FileAccessModifier()
{
await VerifyNoDiagnosticAsync(@"
using System;
file class C;
file struct S;
file interface I;
file record R;
file record struct RS;
file delegate void D();
file enum E;
", options: Options.AddConfigOption(ConfigOptionKeys.AccessibilityModifiers, ConfigOptionValues.AccessibilityModifiers_Explicit));
}
}