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

Prefer package ACL over @_spi #5466

Merged
merged 1 commit into from
Mar 3, 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
Prefer package ACL over @_spi
  • Loading branch information
SimplyDanny committed Mar 3, 2024
commit 83bc7b993f80026e979dc8aa2628054e26664102
1 change: 0 additions & 1 deletion .sourcery/GeneratedTests.stencil
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import SwiftLintBuiltInRules
@_spi(TestHelper)
@testable import SwiftLintCore
import SwiftLintTestHelpers

Expand Down
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ universal_swift_compiler_plugin(

swift_library(
name = "SwiftLintCore",
package_name = "SwiftLint",
srcs = glob(["Source/SwiftLintCore/**/*.swift"]),
copts = copts, # TODO: strict_concurrency_copts
module_name = "SwiftLintCore",
Expand All @@ -92,6 +93,7 @@ swift_library(

swift_library(
name = "SwiftLintBuiltInRules",
package_name = "SwiftLint",
srcs = glob(["Source/SwiftLintBuiltInRules/**/*.swift"]),
copts = copts + select({
":strict_concurrency_builtin_rules": strict_concurrency_copts,
Expand All @@ -106,6 +108,7 @@ swift_library(

swift_library(
name = "SwiftLintExtraRules",
package_name = "SwiftLint",
srcs = [
"Source/SwiftLintExtraRules/Exports.swift",
"@swiftlint_extra_rules//:extra_rules",
Expand All @@ -120,6 +123,7 @@ swift_library(

swift_library(
name = "SwiftLintFramework",
package_name = "SwiftLint",
srcs = glob(
["Source/SwiftLintFramework/**/*.swift"],
),
Expand All @@ -135,6 +139,7 @@ swift_library(

swift_library(
name = "swiftlint.library",
package_name = "SwiftLint",
srcs = glob(["Source/swiftlint/**/*.swift"]),
copts = copts, # TODO: strict_concurrency_copts
module_name = "swiftlint",
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source 'https://rubygems.org'

gem 'cocoapods'
gem 'danger'
gem 'jazzy'
gem 'jazzy', '~> 0.14.4'
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ GEM
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jazzy (0.14.3)
jazzy (0.14.4)
cocoapods (~> 1.5)
mustache (~> 1.1)
open4 (~> 1.3)
redcarpet (~> 3.4)
rexml (~> 3.2)
rouge (>= 2.0.6, < 4.0)
rouge (>= 2.0.6, < 5.0)
sassc (~> 2.1)
sqlite3 (~> 1.3)
xcinvoke (~> 0.3.0)
Expand All @@ -123,16 +123,16 @@ GEM
rchardet (1.8.0)
redcarpet (3.6.0)
rexml (3.2.5)
rouge (3.30.0)
rouge (4.2.0)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
sassc (2.4.0)
ffi (~> 1.9)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
sqlite3 (1.6.2-arm64-darwin)
sqlite3 (1.6.2-x86_64-linux)
sqlite3 (1.7.2-arm64-darwin)
sqlite3 (1.7.2-x86_64-linux)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
typhoeus (1.4.0)
Expand All @@ -153,12 +153,13 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
cocoapods
danger
jazzy
jazzy (~> 0.14.4)

BUNDLED WITH
2.4.12
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

@_spi(TestHelper)
public extension Configuration {
package extension Configuration {
struct FileGraph: Hashable {
// MARK: - Properties
private static let defaultRemoteConfigTimeout: TimeInterval = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public extension Configuration {
case spaces(count: Int)

/// The default indentation style if none is explicitly provided.
@_spi(TestHelper)
public static let `default` = spaces(count: 4)
package static let `default` = spaces(count: 4)

/// Creates an indentation style based on an untyped configuration value.
///
Expand Down
3 changes: 1 addition & 2 deletions Source/SwiftLintCore/Extensions/Configuration+Merging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import SourceKittenFramework

extension Configuration {
// MARK: - Methods: Merging
@_spi(TestHelper)
public func merged(
package func merged(
withChild childConfiguration: Configuration,
rootDirectory: String
) -> Configuration {
Expand Down
6 changes: 2 additions & 4 deletions Source/SwiftLintCore/Extensions/SwiftLintFile+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ private let linesWithTokensCache = Cache { $0.computeLinesWithTokens() }
internal typealias AssertHandler = () -> Void
// Re-enable once all parser diagnostics in tests have been addressed.
// https://github.com/realm/SwiftLint/issues/3348
@_spi(TestHelper)
public var parserDiagnosticsDisabledForTests = false
package var parserDiagnosticsDisabledForTests = false

private let assertHandlers = [FileCacheKey: AssertHandler]()
private let assertHandlerCache = Cache { file in assertHandlers[file.cacheKey] }
Expand Down Expand Up @@ -209,8 +208,7 @@ extension SwiftLintFile {
linesWithTokensCache.invalidate(self)
}

@_spi(TestHelper)
public static func clearCaches() {
package static func clearCaches() {
responseCache.clear()
assertHandlerCache.clear()
structureDictionaryCache.clear()
Expand Down
3 changes: 1 addition & 2 deletions Source/SwiftLintCore/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public struct Configuration {
/// - parameter pinnedVersion: The SwiftLint version defined in this configuration.
/// - parameter allowZeroLintableFiles: Allow SwiftLint to exit successfully when passed ignored or unlintable files
/// - parameter strict: Treat warnings as errors
@_spi(TestHelper)
public init(
package init(
rulesMode: RulesMode = .default(disabled: [], optIn: []),
allRulesWrapped: [ConfigurationRuleWrapper]? = nil,
ruleList: RuleList = RuleRegistry.shared.list,
Expand Down
3 changes: 1 addition & 2 deletions Source/SwiftLintCore/Models/ConfigurationRuleWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@_spi(TestHelper)
public typealias ConfigurationRuleWrapper = (rule: any Rule, initializedWithNonEmptyConfiguration: Bool)
package typealias ConfigurationRuleWrapper = (rule: any Rule, initializedWithNonEmptyConfiguration: Bool)
12 changes: 4 additions & 8 deletions Source/SwiftLintCore/Models/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ public struct Example: Sendable {
/// - SeeAlso: addEmoji(_:)
public private(set) var testMultiByteOffsets: Bool
/// Whether tests shall verify that the example wrapped in a comment doesn't trigger
@_spi(TestHelper)
public private(set) var testWrappingInComment: Bool
package private(set) var testWrappingInComment: Bool
/// Whether tests shall verify that the example wrapped into a string doesn't trigger
@_spi(TestHelper)
public private(set) var testWrappingInString: Bool
package private(set) var testWrappingInString: Bool
/// Whether tests shall verify that the disabled rule (comment in the example) doesn't trigger
@_spi(TestHelper)
public private(set) var testDisableCommand: Bool
package private(set) var testDisableCommand: Bool
/// Whether the example should be tested on Linux
public private(set) var testOnLinux: Bool
/// The path to the file where the example was created
Expand All @@ -43,8 +40,7 @@ public struct Example: Sendable {
let excludeFromDocumentation: Bool

/// Specifies whether the test example should be the only example run during the current test case execution.
@_spi(TestHelper)
public var isFocused: Bool
package var isFocused: Bool
}

public extension Example {
Expand Down
3 changes: 1 addition & 2 deletions Source/SwiftLintCore/Models/SwiftLintFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public final class SwiftLintFile {
}

/// Mark this file as used for testing purposes.
@_spi(TestHelper)
public func markAsTestFile() {
package func markAsTestFile() {
isTestFile = true
}
}
Expand Down
8 changes: 3 additions & 5 deletions Source/SwiftLintCore/Protocols/CollectingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public extension CollectingRule where Self: AnalyzerRule {
}

/// A `CollectingRule` that is also a `CorrectableRule`.
@_spi(TestHelper)
public protocol CollectingCorrectableRule: CollectingRule, CorrectableRule {
package protocol CollectingCorrectableRule: CollectingRule, CorrectableRule {
/// Attempts to correct the violations to this rule in the specified file after collecting file info for all files
/// and returns all corrections that were applied.
///
Expand All @@ -114,8 +113,7 @@ public protocol CollectingCorrectableRule: CollectingRule, CorrectableRule {
func correct(file: SwiftLintFile, collectedInfo: [SwiftLintFile: FileInfo]) -> [Correction]
}

@_spi(TestHelper)
public extension CollectingCorrectableRule {
package extension CollectingCorrectableRule {
func correct(file: SwiftLintFile, collectedInfo: [SwiftLintFile: FileInfo],
compilerArguments: [String]) -> [Correction] {
return correct(file: file, collectedInfo: collectedInfo)
Expand All @@ -137,7 +135,7 @@ public extension CollectingCorrectableRule {
}
}

public extension CollectingCorrectableRule where Self: AnalyzerRule {
package extension CollectingCorrectableRule where Self: AnalyzerRule {
func correct(file: SwiftLintFile) -> [Correction] {
queuedFatalError("Must call `correct(file:collectedInfo:compilerArguments:)` for AnalyzerRule")
}
Expand Down
11 changes: 5 additions & 6 deletions Source/SwiftLintCore/Rules/SuperfluousDisableCommandRule.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@_spi(TestHelper)
public struct SuperfluousDisableCommandRule: SourceKitFreeRule {
public var configuration = SeverityConfiguration<Self>(.warning)
package struct SuperfluousDisableCommandRule: SourceKitFreeRule {
package var configuration = SeverityConfiguration<Self>(.warning)

public init() {}
package init() {}

public static let description = RuleDescription(
package static let description = RuleDescription(
identifier: "superfluous_disable_command",
name: "Superfluous Disable Command",
description: """
Expand All @@ -30,7 +29,7 @@ public struct SuperfluousDisableCommandRule: SourceKitFreeRule {
]
)

public func validate(file: SwiftLintFile) -> [StyleViolation] {
package func validate(file: SwiftLintFile) -> [StyleViolation] {
// This rule is implemented in Linter.swift
return []
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ swift_library(
testonly = True,
srcs = glob(["CLITests/**/*.swift"]),
module_name = "CLITests",
package_name = "SwiftLint",
deps = [
"//:swiftlint.library",
],
Expand Down Expand Up @@ -50,6 +51,7 @@ swift_library(
testonly = True,
srcs = glob(["SwiftLintTestHelpers/**/*.swift"]),
module_name = "SwiftLintTestHelpers",
package_name = "SwiftLint",
deps = [
"//:SwiftLintFramework",
],
Expand Down Expand Up @@ -85,6 +87,7 @@ swift_library(
testonly = True,
srcs = [":SwiftLintFrameworkTestsSources"],
module_name = "SwiftLintFrameworkTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
],
Expand All @@ -109,6 +112,7 @@ swift_library(
testonly = True,
srcs = ["GeneratedTests/GeneratedTests.swift"],
module_name = "GeneratedTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
],
Expand All @@ -128,6 +132,7 @@ swift_library(
testonly = True,
srcs = ["IntegrationTests/IntegrationTests.swift"],
module_name = "IntegrationTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
],
Expand Down Expand Up @@ -163,6 +168,7 @@ swift_library(
"//conditions:default": [],
}),
module_name = "ExtraRulesTests",
package_name = "SwiftLint",
deps = [
":SwiftLintTestHelpers",
],
Expand Down
1 change: 0 additions & 1 deletion Tests/CLITests/RulesFilterTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import swiftlint
@_spi(TestHelper)
import SwiftLintFramework
import XCTest

Expand Down
1 change: 0 additions & 1 deletion Tests/GeneratedTests/GeneratedTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated using Sourcery 2.1.2 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
@testable import SwiftLintBuiltInRules
@_spi(TestHelper)
@testable import SwiftLintCore
import SwiftLintTestHelpers

Expand Down
1 change: 0 additions & 1 deletion Tests/IntegrationTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
@_spi(TestHelper)
import SwiftLintFramework
import SwiftLintTestHelpers
import XCTest
Expand Down
2 changes: 0 additions & 2 deletions Tests/SwiftLintFrameworkTests/CollectingRuleTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@_spi(TestHelper)
@testable import SwiftLintCore
@_spi(TestHelper)
import SwiftLintTestHelpers
import XCTest

Expand Down
1 change: 0 additions & 1 deletion Tests/SwiftLintFrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// swiftlint:disable file_length
import Foundation
import SourceKittenFramework
@_spi(TestHelper)
@testable import SwiftLintCore
import XCTest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import SwiftLintBuiltInRules
@_spi(TestHelper)
@testable import SwiftLintCore
import XCTest

Expand Down
1 change: 0 additions & 1 deletion Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import SourceKittenFramework
@_spi(TestHelper)
@testable import SwiftLintCore
import XCTest

Expand Down
1 change: 0 additions & 1 deletion Tests/SwiftLintFrameworkTests/ParserDiagnosticsTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import SwiftLintBuiltInRules
@_spi(TestHelper)
@testable import SwiftLintCore
import XCTest

Expand Down
1 change: 0 additions & 1 deletion Tests/SwiftLintFrameworkTests/SourceKitCrashTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@_spi(TestHelper)
@testable import SwiftLintCore
import XCTest

Expand Down
3 changes: 0 additions & 3 deletions Tests/SwiftLintTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import SourceKittenFramework
@_spi(TestHelper)
import SwiftLintCore
import XCTest

Expand Down Expand Up @@ -87,7 +86,6 @@ public extension Collection where Element == String {
.violations(config: config, requiresFileOnDisk: requiresFileOnDisk)
}

@_spi(TestHelper)
func corrections(config: Configuration = Configuration.default, requiresFileOnDisk: Bool = false) -> [Correction] {
return map { SwiftLintFile.testFile(withContents: $0, persistToDisk: requiresFileOnDisk) }
.corrections(config: config, requiresFileOnDisk: requiresFileOnDisk)
Expand All @@ -109,7 +107,6 @@ public extension Collection where Element: SwiftLintFile {
return requiresFileOnDisk ? violations.withoutFiles() : violations
}

@_spi(TestHelper)
func corrections(config: Configuration = Configuration.default, requiresFileOnDisk: Bool = false) -> [Correction] {
let storage = RuleStorage()
let corrections = map({ file in
Expand Down