Skip to content

Commit 8cda6c6

Browse files
CopilotSimplyDanny
andauthored
Fix no_extension_access_modifier rule triggering on nonisolated modifier (#6174)
Co-authored-by: Danny Mösch <[email protected]>
1 parent a809480 commit 8cda6c6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@
9595

9696
### Bug Fixes
9797

98+
* Fix `no_extension_access_modifier` rule incorrectly triggering for `nonisolated extension`.
99+
The rule now only flags actual access control modifiers (`private`, `public`, `open`,
100+
`internal`, `fileprivate`) and ignores isolation modifiers like `nonisolated`.
101+
[copilot](https://github.com/copilot)
102+
[#6168](https://github.com/realm/SwiftLint/issues/6168)
103+
98104
* Improved error reporting when SwiftLint exits, because of an invalid configuration file
99105
or other error.
100106
[Martin Redington](https://github.com/mildm8nnered)

Source/SwiftLintBuiltInRules/Rules/Idiomatic/NoExtensionAccessModifierRule.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct NoExtensionAccessModifierRule: Rule {
1212
nonTriggeringExamples: [
1313
Example("extension String {}"),
1414
Example("\n\n extension String {}"),
15+
Example("nonisolated extension String {}"),
1516
],
1617
triggeringExamples: [
1718
Example("↓private extension String {}"),
@@ -29,8 +30,8 @@ private extension NoExtensionAccessModifierRule {
2930

3031
override func visitPost(_ node: ExtensionDeclSyntax) {
3132
let modifiers = node.modifiers
32-
if modifiers.isNotEmpty {
33-
violations.append(modifiers.positionAfterSkippingLeadingTrivia)
33+
if let accessLevelModifier = modifiers.accessLevelModifier {
34+
violations.append(accessLevelModifier.positionAfterSkippingLeadingTrivia)
3435
}
3536
}
3637
}

0 commit comments

Comments
 (0)