mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
# Conflicts: # Tests/BuiltInRulesTests/FileHeaderRuleTests.swift # Tests/BuiltInRulesTests/FileNameNoSpaceRuleTests.swift # Tests/BuiltInRulesTests/IndentationWidthRuleTests.swift # Tests/CoreTests/RegexConfigurationTests.swift # Tests/CoreTests/SwiftLintFileTests.swift # Tests/FileSystemAccessTests/BaselineTests.swift # Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift # Tests/FileSystemAccessTests/ConfigurationTests.swift # Tests/FileSystemAccessTests/GlobTests.swift # Tests/FileSystemAccessTests/MultipleConfigurationsTests.swift # Tests/FileSystemAccessTests/ReporterTests.swift # Tests/FileSystemAccessTests/SourceKitCrashTests.swift # Tests/FrameworkTests/CustomRulesTests.swift # Tests/FrameworkTests/LinterCacheTests.swift # Tests/FrameworkTests/RuleConfigurationTests.swift # Tests/FrameworkTests/SwiftVersionTests.swift # Tests/GeneratedTests/GeneratedTests_02.swift # Tests/GeneratedTests/GeneratedTests_03.swift # Tests/GeneratedTests/GeneratedTests_04.swift # Tests/GeneratedTests/GeneratedTests_05.swift # Tests/GeneratedTests/GeneratedTests_06.swift # Tests/GeneratedTests/GeneratedTests_07.swift # Tests/GeneratedTests/GeneratedTests_08.swift # Tests/GeneratedTests/GeneratedTests_09.swift # Tests/GeneratedTests/GeneratedTests_10.swift # Tests/IntegrationTests/ConfigPathResolutionTests.swift # Tests/IntegrationTests/IntegrationTests.swift # Tests/TestHelpers/TestHelpers.swift
68 lines
2.2 KiB
Swift
68 lines
2.2 KiB
Swift
import SwiftLintFramework
|
|
import Testing
|
|
|
|
@Suite
|
|
struct EmptyFileTests {
|
|
var collectedLinter: CollectedLinter! // swiftlint:disable:this implicitly_unwrapped_optional
|
|
var ruleStorage: RuleStorage! // swiftlint:disable:this implicitly_unwrapped_optional
|
|
|
|
init() throws {
|
|
let ruleList = RuleList(rules: RuleMock<DontLintEmptyFiles>.self, RuleMock<LintEmptyFiles>.self)
|
|
let configuration = try Configuration(dict: [:], ruleList: ruleList)
|
|
let file = SwiftLintFile(contents: "")
|
|
let linter = Linter(file: file, configuration: configuration)
|
|
ruleStorage = RuleStorage()
|
|
collectedLinter = linter.collect(into: ruleStorage)
|
|
}
|
|
|
|
@Test
|
|
func shouldLintEmptyFileRespectedDuringLint() {
|
|
let styleViolations = collectedLinter.styleViolations(using: ruleStorage)
|
|
#expect(styleViolations.count == 1)
|
|
#expect(styleViolations.first?.ruleIdentifier == "rule_mock<LintEmptyFiles>")
|
|
}
|
|
|
|
@Test
|
|
func shouldLintEmptyFileRespectedDuringCorrect() {
|
|
let corrections = collectedLinter.correct(using: ruleStorage)
|
|
#expect(corrections == ["rule_mock<LintEmptyFiles>": 1])
|
|
}
|
|
}
|
|
|
|
private protocol ShouldLintEmptyFilesProtocol {
|
|
static var shouldLintEmptyFiles: Bool { get }
|
|
}
|
|
|
|
private struct LintEmptyFiles: ShouldLintEmptyFilesProtocol {
|
|
static var shouldLintEmptyFiles: Bool { true }
|
|
}
|
|
|
|
private struct DontLintEmptyFiles: ShouldLintEmptyFilesProtocol {
|
|
static var shouldLintEmptyFiles: Bool { false }
|
|
}
|
|
|
|
private struct RuleMock<ShouldLintEmptyFiles: ShouldLintEmptyFilesProtocol>: CorrectableRule, SourceKitFreeRule {
|
|
var configuration = SeverityConfiguration<Self>(.warning)
|
|
|
|
static var description: RuleDescription {
|
|
RuleDescription(
|
|
identifier: "rule_mock<\(ShouldLintEmptyFiles.self)>",
|
|
name: "",
|
|
description: "",
|
|
kind: .style,
|
|
deprecatedAliases: ["mock"])
|
|
}
|
|
|
|
var shouldLintEmptyFiles: Bool {
|
|
ShouldLintEmptyFiles.shouldLintEmptyFiles
|
|
}
|
|
|
|
func validate(file: SwiftLintFile) -> [StyleViolation] {
|
|
[StyleViolation(ruleDescription: Self.description, location: Location(file: file.path))]
|
|
}
|
|
|
|
func correct(file _: SwiftLintFile) -> Int {
|
|
1
|
|
}
|
|
}
|