Skip to content

Commit 67e9891

Browse files
committed
Get rid of @testable import
1 parent 25409e2 commit 67e9891

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

.swiftlint.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ custom_rules:
110110
fatal_error:
111111
name: Fatal Error
112112
excluded: "Tests/*"
113-
message: Prefer using `queuedFatalError` over `fatalError` to avoid leaking compiler host machine paths.
113+
message: Prefer `queuedFatalError` over `fatalError` to avoid leaking compiler host machine paths
114114
regex: \bfatalError\b
115115
match_kinds:
116116
- identifier
@@ -121,3 +121,9 @@ custom_rules:
121121
message: Rule Test Function mustn't end with `rule`
122122
regex: func\s*test\w+(r|R)ule\(\)
123123
severity: error
124+
testable_import:
125+
included: Tests/TestHelpers/.+\.swift
126+
name: Testable Import
127+
message: Do not use @testable imports
128+
regex: ^\s*@testable\s+import\s+\w+
129+
severity: error

Source/SwiftLintCoreMacros/DisabledWithoutSourceKit.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ enum DisabledWithoutSourceKit: ExtensionMacro {
1414
context.diagnose(SwiftLintCoreMacroError.notStruct.diagnose(at: declaration))
1515
return []
1616
}
17+
let acl = declaration.modifiers.first {
18+
["public", "internal", "package", "fileprivate", "private"].contains($0.name.text)
19+
}?.name.text ?? "internal"
1720
let message = #"""
1821
"Skipping enabled rule '\(Self.identifier)' because it requires SourceKit and SourceKit access is prohibited."
1922
"""#
2023
return [
2124
try ExtensionDeclSyntax("""
22-
extension \(type) {
25+
\(raw: acl) extension \(type) {
2326
private static let postMessage: Void = {
2427
Issue.genericWarning(\(raw: message)).print()
2528
}()

Source/SwiftLintFramework/Rules/CustomRules.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import Foundation
22

33
// MARK: - CustomRulesConfiguration
44

5-
struct CustomRulesConfiguration: RuleConfiguration, CacheDescriptionProvider {
6-
typealias Parent = CustomRules
5+
package struct CustomRulesConfiguration: RuleConfiguration, CacheDescriptionProvider {
6+
package typealias Parent = CustomRules
77

8-
var parameterDescription: RuleConfigurationDescription? { RuleConfigurationOption.noOptions }
9-
var cacheDescription: String {
8+
package var parameterDescription: RuleConfigurationDescription? { RuleConfigurationOption.noOptions }
9+
package var cacheDescription: String {
1010
let configsDescription = customRuleConfigurations
1111
.sorted { $0.identifier < $1.identifier }
1212
.map(\.cacheDescription)
@@ -20,7 +20,7 @@ struct CustomRulesConfiguration: RuleConfiguration, CacheDescriptionProvider {
2020
var customRuleConfigurations = [RegexConfiguration<Parent>]()
2121
var defaultExecutionMode: RegexConfiguration<Parent>.ExecutionMode?
2222

23-
mutating func apply(configuration: Any) throws(Issue) {
23+
package mutating func apply(configuration: Any) throws(Issue) {
2424
guard let configurationDict = configuration as? [String: Any] else {
2525
throw .invalidConfiguration(ruleID: Parent.identifier)
2626
}
@@ -52,16 +52,20 @@ struct CustomRulesConfiguration: RuleConfiguration, CacheDescriptionProvider {
5252
// MARK: - CustomRules
5353

5454
@DisabledWithoutSourceKit
55-
struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
56-
var cacheDescription: String {
55+
package struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
56+
package init() {
57+
// Nothing to initialize.
58+
}
59+
60+
package var cacheDescription: String {
5761
configuration.cacheDescription
5862
}
5963

6064
var customRuleIdentifiers: [String] {
6165
configuration.customRuleConfigurations.map(\.identifier)
6266
}
6367

64-
static let description = RuleDescription(
68+
package static let description = RuleDescription(
6569
identifier: "custom_rules",
6670
name: "Custom Rules",
6771
description: """
@@ -71,10 +75,10 @@ struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
7175
""",
7276
kind: .style)
7377

74-
var configuration = CustomRulesConfiguration()
78+
package var configuration = CustomRulesConfiguration()
7579

7680
/// Returns true if all configured custom rules use SwiftSyntax mode, making this rule effectively SourceKit-free.
77-
var isEffectivelySourceKitFree: Bool {
81+
package var isEffectivelySourceKitFree: Bool {
7882
configuration.customRuleConfigurations.allSatisfy { config in
7983
let effectiveMode = config.executionMode == .default
8084
? (configuration.defaultExecutionMode ?? .sourcekit)
@@ -83,7 +87,7 @@ struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
8387
}
8488
}
8589

86-
func validate(file: SwiftLintFile) -> [StyleViolation] {
90+
package func validate(file: SwiftLintFile) -> [StyleViolation] {
8791
var configurations = configuration.customRuleConfigurations
8892

8993
guard configurations.isNotEmpty else {
@@ -114,7 +118,7 @@ struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
114118
}
115119
}
116120

117-
func canBeDisabled(violation: StyleViolation, by ruleID: RuleIdentifier) -> Bool {
121+
package func canBeDisabled(violation: StyleViolation, by ruleID: RuleIdentifier) -> Bool {
118122
switch ruleID {
119123
case let .single(identifier: id):
120124
id == Self.identifier
@@ -125,7 +129,7 @@ struct CustomRules: Rule, CacheDescriptionProvider, ConditionallySourceKitFree {
125129
}
126130
}
127131

128-
func isEnabled(in region: Region, for ruleID: String) -> Bool {
132+
package func isEnabled(in region: Region, for ruleID: String) -> Bool {
129133
if !Self.description.allIdentifiers.contains(ruleID),
130134
!customRuleIdentifiers.contains(ruleID),
131135
Self.identifier != ruleID {

Tests/TestHelpers/TestHelpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import SourceKittenFramework
33
import XCTest
44

5-
@testable import SwiftLintFramework
5+
import SwiftLintFramework
66

77
// swiftlint:disable file_length
88

@@ -582,7 +582,7 @@ private extension RuleDescription {
582582
}
583583
}
584584

585-
public extension [any Rule] {
585+
package extension [any Rule] {
586586
var customRules: CustomRules? {
587587
first(where: { $0 is CustomRules }) as? CustomRules
588588
}

0 commit comments

Comments
 (0)