Get rid of some disabled commands (#4807)
This commit is contained in:
parent
7d7bee5eee
commit
1bf2f25e40
|
@ -47,11 +47,10 @@ extension Configuration {
|
|||
Self.nestedConfigIsSelfByIdentifierLock.unlock()
|
||||
}
|
||||
|
||||
// swiftlint:disable:next discouraged_optional_boolean
|
||||
internal static func getIsNestedConfigurationSelf(forIdentifier identifier: String) -> Bool? {
|
||||
internal static func getIsNestedConfigurationSelf(forIdentifier identifier: String) -> Bool {
|
||||
Self.nestedConfigIsSelfByIdentifierLock.lock()
|
||||
defer { Self.nestedConfigIsSelfByIdentifierLock.unlock() }
|
||||
return Self.nestedConfigIsSelfByIdentifier[identifier]
|
||||
return Self.nestedConfigIsSelfByIdentifier[identifier] ?? false
|
||||
}
|
||||
|
||||
// MARK: SwiftLint Cache (On-Disk)
|
||||
|
|
|
@ -56,9 +56,8 @@ public extension Configuration {
|
|||
)
|
||||
}
|
||||
|
||||
// swiftlint:disable:next discouraged_optional_boolean
|
||||
internal func includesFile(atPath path: String) -> Bool? {
|
||||
guard isBuilt else { return nil }
|
||||
internal func includesFile(atPath path: String) -> Bool {
|
||||
guard isBuilt else { return false }
|
||||
|
||||
return vertices.contains { vertix in
|
||||
if case let .existing(filePath) = vertix.filePath {
|
||||
|
|
|
@ -106,7 +106,7 @@ extension Configuration {
|
|||
config = self
|
||||
} else if
|
||||
FileManager.default.fileExists(atPath: configurationSearchPath),
|
||||
fileGraph.includesFile(atPath: configurationSearchPath) != true
|
||||
!fileGraph.includesFile(atPath: configurationSearchPath)
|
||||
{
|
||||
// Use self merged with the nested config that was found
|
||||
// iff that nested config has not already been used to build the main config
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable:next balanced_xctest_lifecycle
|
||||
class ExpiringTodoRuleTests: XCTestCase {
|
||||
private lazy var config: Configuration = makeConfiguration()
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
config = makeConfiguration()
|
||||
}
|
||||
private var config: Configuration = makeConfiguration()
|
||||
|
||||
func testExpiringTodo() {
|
||||
verifyRule(ExpiringTodoRule.description, commentDoesntViolate: false)
|
||||
|
@ -37,7 +30,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testNonExpiredTodo() {
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: nil))] Implement")
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: .badFormatting))] Implement")
|
||||
XCTAssertEqual(violations(example).count, 0)
|
||||
}
|
||||
|
||||
|
@ -45,7 +38,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateDelimiters: .init(opening: "<", closing: ">")
|
||||
)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: <\(dateString(for: .expired))> Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -58,7 +51,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
dateFormat: "MM-dd-yyyy",
|
||||
dateSeparator: "-"
|
||||
)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: .expired))] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -70,7 +63,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateFormat: "yyyy/MM/dd"
|
||||
)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [\(dateString(for: .expired))] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -139,7 +132,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
let ruleConfig: ExpiringTodoConfiguration = .init(
|
||||
dateFormat: "dd/yyyy/MM"
|
||||
)
|
||||
config = makeConfiguration(with: ruleConfig)
|
||||
config = Self.makeConfiguration(with: ruleConfig)
|
||||
|
||||
let example = Example("fatalError() // TODO: [31/01/2020] Implement")
|
||||
let violations = self.violations(example)
|
||||
|
@ -151,28 +144,26 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
return SwiftLintFrameworkTests.violations(example, config: config)
|
||||
}
|
||||
|
||||
private func dateString(for status: ExpiringTodoRule.ExpiryViolationLevel?) -> String {
|
||||
private func dateString(for status: ExpiringTodoRule.ExpiryViolationLevel) -> String {
|
||||
let formatter: DateFormatter = .init()
|
||||
formatter.dateFormat = config.ruleConfiguration.dateFormat
|
||||
|
||||
return formatter.string(from: date(for: status))
|
||||
}
|
||||
|
||||
private func date(for status: ExpiringTodoRule.ExpiryViolationLevel?) -> Date {
|
||||
private func date(for status: ExpiringTodoRule.ExpiryViolationLevel) -> Date {
|
||||
let ruleConfiguration = config.ruleConfiguration
|
||||
|
||||
let daysToAdvance: Int
|
||||
|
||||
// swiftlint:disable optional_enum_case_matching
|
||||
switch status {
|
||||
case .approachingExpiry?:
|
||||
case .approachingExpiry:
|
||||
daysToAdvance = ruleConfiguration.approachingExpiryThreshold
|
||||
case .expired?:
|
||||
case .expired:
|
||||
daysToAdvance = 0
|
||||
case .badFormatting?, nil:
|
||||
case .badFormatting:
|
||||
daysToAdvance = ruleConfiguration.approachingExpiryThreshold + 1
|
||||
}
|
||||
// swiftlint:enable optional_enum_case_matching
|
||||
|
||||
return Calendar.current
|
||||
.date(
|
||||
|
@ -182,7 +173,7 @@ class ExpiringTodoRuleTests: XCTestCase {
|
|||
)!
|
||||
}
|
||||
|
||||
private func makeConfiguration(with ruleConfiguration: ExpiringTodoConfiguration? = nil) -> Configuration {
|
||||
private static func makeConfiguration(with ruleConfiguration: ExpiringTodoConfiguration? = nil) -> Configuration {
|
||||
var serializedConfig: [String: Any]?
|
||||
|
||||
if let config = ruleConfiguration {
|
||||
|
|
|
@ -12,10 +12,8 @@ class ExtendedNSStringTests: XCTestCase {
|
|||
"// do something\n" + // 16 characters
|
||||
"}\n" +
|
||||
"}"
|
||||
// swiftlint:disable:next legacy_objc_type
|
||||
let string = NSString(string: contents)
|
||||
// A character placed on 80 offset indicates a white-space before 'do' at 5th line.
|
||||
if let lineAndCharacter = StringView(string).lineAndCharacter(forCharacterOffset: 80) {
|
||||
if let lineAndCharacter = StringView(contents).lineAndCharacter(forCharacterOffset: 80) {
|
||||
XCTAssertEqual(lineAndCharacter.line, 5)
|
||||
XCTAssertEqual(lineAndCharacter.character, 3)
|
||||
} else {
|
||||
|
|
|
@ -214,11 +214,9 @@ class IndentationWidthRuleTests: XCTestCase {
|
|||
private func countViolations(
|
||||
in example: Example,
|
||||
indentationWidth: Int? = nil,
|
||||
// swiftlint:disable discouraged_optional_boolean
|
||||
includeComments: Bool? = nil,
|
||||
includeCompilerDirectives: Bool? = nil,
|
||||
includeMultilineStrings: Bool? = nil,
|
||||
// swiftlint:enable discouraged_optional_boolean
|
||||
includeComments: Bool = true,
|
||||
includeCompilerDirectives: Bool = true,
|
||||
includeMultilineStrings: Bool = true,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line
|
||||
) -> Int {
|
||||
|
@ -226,15 +224,9 @@ class IndentationWidthRuleTests: XCTestCase {
|
|||
if let indentationWidth {
|
||||
configDict["indentation_width"] = indentationWidth
|
||||
}
|
||||
if let includeComments {
|
||||
configDict["include_comments"] = includeComments
|
||||
}
|
||||
if let includeCompilerDirectives {
|
||||
configDict["include_compiler_directives"] = includeCompilerDirectives
|
||||
}
|
||||
if let includeMultilineStrings {
|
||||
configDict["include_multiline_strings"] = includeMultilineStrings
|
||||
}
|
||||
|
||||
guard let config = makeConfig(configDict, IndentationWidthRule.description.identifier) else {
|
||||
XCTFail("Unable to create rule configuration.", file: (file), line: line)
|
||||
|
@ -248,11 +240,9 @@ class IndentationWidthRuleTests: XCTestCase {
|
|||
in string: String,
|
||||
equals expectedCount: Int,
|
||||
indentationWidth: Int? = nil,
|
||||
// swiftlint:disable discouraged_optional_boolean
|
||||
includeComments: Bool? = nil,
|
||||
includeCompilerDirectives: Bool? = nil,
|
||||
includeMultilineStrings: Bool? = nil,
|
||||
// swiftlint:enable discouraged_optional_boolean
|
||||
includeComments: Bool = true,
|
||||
includeCompilerDirectives: Bool = true,
|
||||
includeMultilineStrings: Bool = true,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line
|
||||
) {
|
||||
|
@ -275,11 +265,9 @@ class IndentationWidthRuleTests: XCTestCase {
|
|||
private func assertNoViolation(
|
||||
in string: String,
|
||||
indentationWidth: Int? = nil,
|
||||
// swiftlint:disable discouraged_optional_boolean
|
||||
includeComments: Bool? = nil,
|
||||
includeCompilerDirectives: Bool? = nil,
|
||||
includeMultilineStrings: Bool? = nil,
|
||||
// swiftlint:enable discouraged_optional_boolean
|
||||
includeComments: Bool = true,
|
||||
includeCompilerDirectives: Bool = true,
|
||||
includeMultilineStrings: Bool = true,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line
|
||||
) {
|
||||
|
@ -298,11 +286,9 @@ class IndentationWidthRuleTests: XCTestCase {
|
|||
private func assert1Violation(
|
||||
in string: String,
|
||||
indentationWidth: Int? = nil,
|
||||
// swiftlint:disable discouraged_optional_boolean
|
||||
includeComments: Bool? = nil,
|
||||
includeCompilerDirectives: Bool? = nil,
|
||||
includeMultilineStrings: Bool? = nil,
|
||||
// swiftlint:enable discouraged_optional_boolean
|
||||
includeComments: Bool = true,
|
||||
includeCompilerDirectives: Bool = true,
|
||||
includeMultilineStrings: Bool = true,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line
|
||||
) {
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable:next balanced_xctest_lifecycle
|
||||
class RequiredEnumCaseRuleConfigurationTests: XCTestCase {
|
||||
private typealias RuleConfiguration = RequiredEnumCaseRuleConfiguration
|
||||
private typealias RequiredCase = RuleConfiguration.RequiredCase
|
||||
|
||||
private let protocol1 = "RequiredProtocol"
|
||||
private let protocol2 = "NetworkResults"
|
||||
private let protocol3 = "RequiredProtocolWithSeverity"
|
||||
private let rule1 = RuleConfiguration.RequiredCase(name: "success", severity: .warning)
|
||||
private let rule2 = RuleConfiguration.RequiredCase(name: "error", severity: .warning)
|
||||
private let rule3 = RuleConfiguration.RequiredCase(name: "success", severity: .error)
|
||||
private static let protocol1 = "RequiredProtocol"
|
||||
private static let protocol2 = "NetworkResults"
|
||||
private static let protocol3 = "RequiredProtocolWithSeverity"
|
||||
private static let rule1 = RuleConfiguration.RequiredCase(name: "success", severity: .warning)
|
||||
private static let rule2 = RuleConfiguration.RequiredCase(name: "error", severity: .warning)
|
||||
private static let rule3 = RuleConfiguration.RequiredCase(name: "success", severity: .error)
|
||||
|
||||
private var config: RuleConfiguration!
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
config = RuleConfiguration()
|
||||
private var config: RuleConfiguration = {
|
||||
var config = RuleConfiguration()
|
||||
config.protocols[protocol1] = [rule1, rule2]
|
||||
config.protocols[protocol2] = [rule2]
|
||||
}
|
||||
return config
|
||||
}()
|
||||
|
||||
func testRequiredCaseHashValue() {
|
||||
let requiredCase = RequiredCase(name: "success")
|
||||
|
@ -68,22 +65,22 @@ class RequiredEnumCaseRuleConfigurationTests: XCTestCase {
|
|||
}
|
||||
|
||||
private func validateRulesExistForProtocol1() {
|
||||
XCTAssertTrue(self.config.protocols[protocol1]?.contains(self.rule1) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[protocol1]?.contains(self.rule2) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[Self.protocol1]?.contains(Self.rule1) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[Self.protocol1]?.contains(Self.rule2) ?? false)
|
||||
}
|
||||
|
||||
func testRegisterProtocolCasesRegistersCasesWithSpecifiedSeverity() {
|
||||
config.register(protocol: protocol3, cases: ["success": "error", "error": "warning"])
|
||||
config.register(protocol: Self.protocol3, cases: ["success": "error", "error": "warning"])
|
||||
validateRulesExistForProtocol3()
|
||||
}
|
||||
|
||||
private func validateRulesExistForProtocol3() {
|
||||
XCTAssertTrue(self.config.protocols[protocol3]?.contains(self.rule3) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[protocol3]?.contains(self.rule2) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[Self.protocol3]?.contains(Self.rule3) ?? false)
|
||||
XCTAssertTrue(self.config.protocols[Self.protocol3]?.contains(Self.rule2) ?? false)
|
||||
}
|
||||
|
||||
func testRegisterProtocols() {
|
||||
config.register(protocols: [protocol1: ["success": "warning", "error": "warning"]])
|
||||
config.register(protocols: [Self.protocol1: ["success": "warning", "error": "warning"]])
|
||||
validateRulesExistForProtocol1()
|
||||
}
|
||||
|
||||
|
@ -100,36 +97,36 @@ class RequiredEnumCaseRuleConfigurationTests: XCTestCase {
|
|||
}
|
||||
|
||||
func testApplyRegistersProtocols() {
|
||||
try? config.apply(configuration: [protocol1: ["success": "warning", "error": "warning"]])
|
||||
try? config.apply(configuration: [Self.protocol1: ["success": "warning", "error": "warning"]])
|
||||
validateRulesExistForProtocol1()
|
||||
}
|
||||
|
||||
func testEqualsReturnsTrue() {
|
||||
var lhs = RuleConfiguration()
|
||||
try? lhs.apply(configuration: [protocol1: ["success", "error"]])
|
||||
try? lhs.apply(configuration: [Self.protocol1: ["success", "error"]])
|
||||
|
||||
var rhs = RuleConfiguration()
|
||||
try? rhs.apply(configuration: [protocol1: ["success", "error"]])
|
||||
try? rhs.apply(configuration: [Self.protocol1: ["success", "error"]])
|
||||
|
||||
XCTAssertEqual(lhs, rhs)
|
||||
}
|
||||
|
||||
func testEqualsReturnsFalseBecauseProtocolsArentEqual() {
|
||||
var lhs = RuleConfiguration()
|
||||
try? lhs.apply(configuration: [protocol1: ["success": "error"]])
|
||||
try? lhs.apply(configuration: [Self.protocol1: ["success": "error"]])
|
||||
|
||||
var rhs = RuleConfiguration()
|
||||
try? rhs.apply(configuration: [protocol2: ["success": "error", "error": "warning"]])
|
||||
try? rhs.apply(configuration: [Self.protocol2: ["success": "error", "error": "warning"]])
|
||||
|
||||
XCTAssertNotEqual(lhs, rhs)
|
||||
}
|
||||
|
||||
func testEqualsReturnsFalseBecauseSeverityIsntEqual() {
|
||||
var lhs = RuleConfiguration()
|
||||
try? lhs.apply(configuration: [protocol1: ["success": "error", "error": "error"]])
|
||||
try? lhs.apply(configuration: [Self.protocol1: ["success": "error", "error": "error"]])
|
||||
|
||||
var rhs = RuleConfiguration()
|
||||
try? rhs.apply(configuration: [protocol1: ["success": "warning", "error": "error"]])
|
||||
try? rhs.apply(configuration: [Self.protocol1: ["success": "warning", "error": "error"]])
|
||||
|
||||
XCTAssertNotEqual(lhs, rhs)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@testable import SwiftLintFramework
|
||||
import XCTest
|
||||
|
||||
// swiftlint:disable:next balanced_xctest_lifecycle
|
||||
class SwiftLintFileTests: XCTestCase {
|
||||
private let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
|
||||
|
@ -10,6 +9,11 @@ class SwiftLintFileTests: XCTestCase {
|
|||
try "let i = 2".data(using: .utf8)!.write(to: tempFile)
|
||||
}
|
||||
|
||||
override func tearDown() async throws {
|
||||
try FileManager.default.removeItem(at: tempFile)
|
||||
try await super.tearDown()
|
||||
}
|
||||
|
||||
func testFileFromStringUpdate() {
|
||||
let file = SwiftLintFile(contents: "let i = 1")
|
||||
|
||||
|
|
Loading…
Reference in New Issue