Skip to content

Commit

Permalink
RCS1018 - Handle 'file' modifier (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 1, 2024
1 parent 8c83e15 commit 6a85d83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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));
}
}

0 comments on commit 6a85d83

Please sign in to comment.