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

Restructure frameworks #5482

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,3 @@ custom_categories:
- name: Rules
children:
- Rule Directory
- name: Reporters
children:
- CSVReporter
- CheckstyleReporter
- CodeClimateReporter
- EmojiReporter
- GitHubActionsLoggingReporter
- HTMLReporter
- JSONReporter
- JUnitReporter
- MarkdownReporter
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ swift_library(
srcs = glob(
["Source/SwiftLintFramework/**/*.swift"],
),
copts = copts + strict_concurrency_copts,
copts = copts, # TODO: strict_concurrency_copts
module_name = "SwiftLintFramework",
visibility = ["//visibility:public"],
deps = [
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ VERSION_STRING=$(shell ./tools/get-version)

all: build

sourcery: Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift Source/SwiftLintCore/Models/ReportersList.swift Tests/GeneratedTests/GeneratedTests.swift
sourcery: Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift Source/SwiftLintFramework/Models/ReportersList.swift Tests/GeneratedTests/GeneratedTests.swift

Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift: Source/SwiftLintBuiltInRules/Rules/**/*.swift .sourcery/BuiltInRules.stencil
./tools/sourcery --sources Source/SwiftLintBuiltInRules/Rules --templates .sourcery/BuiltInRules.stencil --output .sourcery
mv .sourcery/BuiltInRules.generated.swift Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift

Source/SwiftLintCore/Models/ReportersList.swift: Source/SwiftLintCore/Reporters/*.swift .sourcery/ReportersList.stencil
./tools/sourcery --sources Source/SwiftLintCore/Reporters --templates .sourcery/ReportersList.stencil --output .sourcery
mv .sourcery/ReportersList.generated.swift Source/SwiftLintCore/Models/ReportersList.swift
Source/SwiftLintFramework/Models/ReportersList.swift: Source/SwiftLintFramework/Reporters/*.swift .sourcery/ReportersList.stencil
./tools/sourcery --sources Source/SwiftLintFramework/Reporters --templates .sourcery/ReportersList.stencil --output .sourcery
mv .sourcery/ReportersList.generated.swift Source/SwiftLintFramework/Models/ReportersList.swift

Tests/GeneratedTests/GeneratedTests.swift: Source/SwiftLint*/Rules/**/*.swift .sourcery/GeneratedTests.stencil
./tools/sourcery --sources Source/SwiftLintBuiltInRules/Rules --templates .sourcery/GeneratedTests.stencil --output .sourcery
Expand Down Expand Up @@ -173,7 +173,7 @@ endif
$(eval NEW_VERSION_AND_NAME := $(filter-out $@,$(MAKECMDGOALS)))
$(eval NEW_VERSION := $(shell echo $(NEW_VERSION_AND_NAME) | sed 's/:.*//' ))
@sed -i '' 's/## Main/## $(NEW_VERSION_AND_NAME)/g' CHANGELOG.md
@sed 's/__VERSION__/$(NEW_VERSION)/g' tools/Version.swift.template > Source/SwiftLintCore/Models/Version.swift
@sed 's/__VERSION__/$(NEW_VERSION)/g' tools/Version.swift.template > Source/SwiftLintFramework/Models/Version.swift
@sed -e '3s/.*/ version = "$(NEW_VERSION)",/' -i '' MODULE.bazel
make clean
make package
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import SwiftLintCore

struct FunctionBodyLengthRule: SwiftSyntaxRule {
var configuration = SeverityLevelsConfiguration<Self>(warning: 50, error: 100)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import SwiftLintCore

private func wrapExample(
prefix: String = "",
_ type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct RegularExpression: Hashable, Comparable, ExpressibleByStringLitera
try! self.init(pattern: value)
}

var pattern: String { regex.pattern }
package var pattern: String { regex.pattern }

var numberOfCaptureGroups: Int { regex.numberOfCaptureGroups }

Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftLintCore/Extensions/SwiftLintFile+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private let syntaxKindsByLinesCache = Cache { $0.syntaxKindsByLine() }
private let syntaxTokensByLinesCache = Cache { $0.syntaxTokensByLine() }
private let linesWithTokensCache = Cache { $0.computeLinesWithTokens() }

internal typealias AssertHandler = () -> Void
package typealias AssertHandler = () -> Void
// Re-enable once all parser diagnostics in tests have been addressed.
// https://github.com/realm/SwiftLint/issues/3348
package var parserDiagnosticsDisabledForTests = false
Expand Down Expand Up @@ -114,7 +114,7 @@ extension SwiftLintFile {
}
}

internal var assertHandler: AssertHandler? {
package var assertHandler: AssertHandler? {
get {
return assertHandlerCache.get(self)
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SwiftLintCore/Models/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Command: Equatable {

/// - returns: The inverse action that can cancel out the current action, restoring the SwifttLint engine's
/// state prior to the current action.
internal func inverse() -> Action {
package func inverse() -> Action {
switch self {
case .enable: return .disable
case .disable: return .enable
Expand Down Expand Up @@ -143,7 +143,7 @@ public struct Command: Equatable {
/// If the command doesn't have a modifier, it is returned as-is.
///
/// - returns: The expanded commands.
internal func expand() -> [Command] {
package func expand() -> [Command] {
guard let modifier else {
return [self]
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Models/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct Example: Sendable {
/// why a rule is applied and where not. Complex examples with rarely used language constructs or
/// pathological use cases which are indeed important to test but not helpful for understanding can be
/// hidden from the documentation with this option.
let excludeFromDocumentation: Bool
package let excludeFromDocumentation: Bool

/// Specifies whether the test example should be the only example run during the current test case execution.
package var isFocused: Bool
Expand Down
6 changes: 3 additions & 3 deletions Source/SwiftLintCore/Models/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public enum Issue: LocalizedError, Equatable {
/// - parameter error: Any `Error`.
///
/// - returns: A `SwiftLintError.genericWarning` containig the message of the `error` argument.
static func wrap(error: some Error) -> Self {
package static func wrap(error: some Error) -> Self {
error as? Issue ?? Self.genericWarning(error.localizedDescription)
}

/// Make this issue an error.
var asError: Self {
package var asError: Self {
Self.genericError(message)
}

/// The issues description which is ready to be printed to the console.
var errorDescription: String {
package var errorDescription: String {
switch self {
case .genericError:
return "error: \(message)"
Expand Down
6 changes: 3 additions & 3 deletions Source/SwiftLintCore/Models/RuleList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct RuleList {

// MARK: - Internal

internal func allRulesWrapped(configurationDict: [String: Any] = [:]) throws -> [ConfigurationRuleWrapper] {
package func allRulesWrapped(configurationDict: [String: Any] = [:]) throws -> [ConfigurationRuleWrapper] {
var rules = [String: ConfigurationRuleWrapper]()

// Add rules where configuration exists
Expand Down Expand Up @@ -72,11 +72,11 @@ public struct RuleList {
return Array(rules.values)
}

internal func identifier(for alias: String) -> String? {
package func identifier(for alias: String) -> String? {
return aliases[alias]
}

internal func allValidIdentifiers() -> [String] {
package func allValidIdentifiers() -> [String] {
return list.flatMap { _, rule -> [String] in
rule.description.allIdentifiers
}
Expand Down
9 changes: 8 additions & 1 deletion Source/SwiftLintCore/Models/StyleViolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ public struct StyleViolation: CustomStringConvertible, Equatable, Codable {

/// A printable description for this violation.
public var description: String {
return XcodeReporter.generateForSingleViolation(self)
// {full_path_to_file}{:line}{:character}: {error,warning}: {content}
[
"\(location): ",
"\(severity.rawValue): ",
"\(ruleName) Violation: ",
reason,
" (\(ruleIdentifier))"
].joined()
}

/// Creates a `StyleViolation` by specifying its properties directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct RegexConfiguration<Parent: Rule>: SeverityBasedRuleConfiguration,
public var message = "Regex matched"
/// The regular expression to apply to trigger violations for this custom rule.
@ConfigurationElement(key: "regex")
var regex: RegularExpression!
package var regex: RegularExpression!
/// Regular expressions to include when matching the file path.
public var included: [NSRegularExpression] = []
/// Regular expressions to exclude when matching the file path.
Expand Down Expand Up @@ -102,7 +102,7 @@ public struct RegexConfiguration<Parent: Rule>: SeverityBasedRuleConfiguration,
hasher.combine(identifier)
}

func shouldValidate(filePath: String) -> Bool {
package func shouldValidate(filePath: String) -> Bool {
let pathRange = filePath.fullNSRange
let isIncluded = included.isEmpty || included.contains { regex in
regex.firstMatch(in: filePath, range: pathRange) != nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import SwiftSyntax

final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<SeverityLevelsConfiguration<Parent>> {
/// Visitor that collection violations of code block lengths.
public final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<SeverityLevelsConfiguration<Parent>> {
private let kind: Kind

enum Kind {
/// The code block types to check.
public enum Kind {
/// Closure code blocks.
case closure
/// Function body blocks.
case function
/// Type (class, enum, ...) member blocks.
case type

fileprivate var name: String {
Expand All @@ -20,12 +25,18 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

init(kind: Kind, file: SwiftLintFile, configuration: SeverityLevelsConfiguration<Parent>) {
/// Initializer.
///
/// - Parameters:
/// - kind: The code block type to check. See ``Kind``.
/// - file: The file to collect violation for.
/// - configuration: The configuration that defines the acceptable limits.
public init(kind: Kind, file: SwiftLintFile, configuration: SeverityLevelsConfiguration<Parent>) {
self.kind = kind
super.init(configuration: configuration, file: file)
}

override func visitPost(_ node: EnumDeclSyntax) {
override public func visitPost(_ node: EnumDeclSyntax) {
if kind == .type {
registerViolations(
leftBrace: node.memberBlock.leftBrace,
Expand All @@ -35,7 +46,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: ClassDeclSyntax) {
override public func visitPost(_ node: ClassDeclSyntax) {
if kind == .type {
registerViolations(
leftBrace: node.memberBlock.leftBrace,
Expand All @@ -45,7 +56,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: StructDeclSyntax) {
override public func visitPost(_ node: StructDeclSyntax) {
if kind == .type {
registerViolations(
leftBrace: node.memberBlock.leftBrace,
Expand All @@ -55,7 +66,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: ActorDeclSyntax) {
override public func visitPost(_ node: ActorDeclSyntax) {
if kind == .type {
registerViolations(
leftBrace: node.memberBlock.leftBrace,
Expand All @@ -65,7 +76,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: ClosureExprSyntax) {
override public func visitPost(_ node: ClosureExprSyntax) {
if kind == .closure {
registerViolations(
leftBrace: node.leftBrace,
Expand All @@ -75,7 +86,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: FunctionDeclSyntax) {
override public func visitPost(_ node: FunctionDeclSyntax) {
if kind == .function, let body = node.body {
registerViolations(
leftBrace: body.leftBrace,
Expand All @@ -85,7 +96,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor<Severit
}
}

override func visitPost(_ node: InitializerDeclSyntax) {
override public func visitPost(_ node: InitializerDeclSyntax) {
if kind == .function, let body = node.body {
registerViolations(
leftBrace: body.leftBrace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ struct XcodeReporter: Reporter {
///
/// - returns: The report for a single violation.
internal static func generateForSingleViolation(_ violation: StyleViolation) -> String {
// {full_path_to_file}{:line}{:character}: {error,warning}: {content}
return [
"\(violation.location): ",
"\(violation.severity.rawValue): ",
"\(violation.ruleName) Violation: ",
violation.reason,
" (\(violation.ruleIdentifier))"
].joined()
violation.description
}
}
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/CollectingRuleTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import SwiftLintTestHelpers
import XCTest

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// swiftlint:disable file_length
import Foundation
import SourceKittenFramework
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

private extension Command {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

final class ConfigurationAliasesTests: SwiftLintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftLintCore
import SwiftLintFramework

// swiftlint:disable:next blanket_disable_command
// swiftlint:disable nesting identifier_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

// swiftlint:disable file_length
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import SourceKittenFramework
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

// swiftlint:disable file_length
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/CustomRulesTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SourceKittenFramework
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

class CustomRulesTests: SwiftLintTestCase {
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftLintFrameworkTests/ExpiringTodoRuleTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import SwiftLintBuiltInRules
import SwiftLintFramework
import XCTest

class ExpiringTodoRuleTests: SwiftLintTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/GlobTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

final class GlobTests: SwiftLintTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/LinterCacheTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

private struct CacheTestHelper {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/ReporterTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SourceKittenFramework
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

class ReporterTests: SwiftLintTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/SourceKitCrashTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

class SourceKitCrashTests: SwiftLintTestCase {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/YamlParserTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testable import SwiftLintCore
@testable import SwiftLintFramework
import XCTest

class YamlParserTests: SwiftLintTestCase {
Expand Down