Get rid of some more disabled commands
This commit is contained in:
parent
1940e0e2d2
commit
06578e5d91
|
@ -36,8 +36,7 @@ struct IdenticalOperandsRule: ConfigurationProviderRule, SwiftSyntaxRule, OptInR
|
|||
Example("f( i : 2) \(operation) f (i: 3 )")
|
||||
]
|
||||
} + [
|
||||
// swiftlint:disable:next line_length
|
||||
Example("func evaluate(_ mode: CommandMode) -> Result<AutoCorrectOptions, CommandantError<CommandantError<()>>>"),
|
||||
Example("func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<CommandantError<()>>>"),
|
||||
Example("let array = Array<Array<Int>>()"),
|
||||
Example("guard Set(identifiers).count != identifiers.count else { return }"),
|
||||
Example(#"expect("foo") == "foo""#),
|
||||
|
|
|
@ -67,9 +67,8 @@ class ConfigurationTests: XCTestCase {
|
|||
XCTAssertTrue(config.allowZeroLintableFiles)
|
||||
}
|
||||
|
||||
func testEnableAllRulesConfiguration() {
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(
|
||||
func testEnableAllRulesConfiguration() throws {
|
||||
let configuration = try Configuration(
|
||||
dict: [:],
|
||||
ruleList: primaryRuleList,
|
||||
enableAllRules: true,
|
||||
|
@ -79,26 +78,24 @@ class ConfigurationTests: XCTestCase {
|
|||
XCTAssertEqual(configuration.rules.count, primaryRuleList.list.count)
|
||||
}
|
||||
|
||||
func testOnlyRules() {
|
||||
func testOnlyRules() throws {
|
||||
let only = ["nesting", "todo"]
|
||||
|
||||
// swiftlint:disable:next force_try
|
||||
let config = try! Configuration(dict: ["only_rules": only])
|
||||
let config = try Configuration(dict: ["only_rules": only])
|
||||
let configuredIdentifiers = config.rules.map {
|
||||
type(of: $0).description.identifier
|
||||
}.sorted()
|
||||
XCTAssertEqual(only, configuredIdentifiers)
|
||||
}
|
||||
|
||||
func testOnlyRulesWithCustomRules() {
|
||||
func testOnlyRulesWithCustomRules() throws {
|
||||
// All custom rules from a config file should be active if the `custom_rules` is included in the `only_rules`
|
||||
// As the behavior is different for custom rules from parent configs, this test is helpful
|
||||
let only = ["custom_rules"]
|
||||
let customRuleIdentifier = "my_custom_rule"
|
||||
let customRules = [customRuleIdentifier: ["name": "A name for this custom rule", "regex": "this is illegal"]]
|
||||
|
||||
// swiftlint:disable:next force_try
|
||||
let config = try! Configuration(dict: ["only_rules": only, "custom_rules": customRules])
|
||||
let config = try Configuration(dict: ["only_rules": only, "custom_rules": customRules])
|
||||
guard let resultingCustomRules = config.rules.first(where: { $0 is CustomRules }) as? CustomRules
|
||||
else {
|
||||
XCTFail("Custom rules are expected to be present")
|
||||
|
@ -111,15 +108,13 @@ class ConfigurationTests: XCTestCase {
|
|||
)
|
||||
}
|
||||
|
||||
func testWarningThreshold_value() {
|
||||
// swiftlint:disable:next force_try
|
||||
let config = try! Configuration(dict: ["warning_threshold": 5])
|
||||
func testWarningThreshold_value() throws {
|
||||
let config = try Configuration(dict: ["warning_threshold": 5])
|
||||
XCTAssertEqual(config.warningThreshold, 5)
|
||||
}
|
||||
|
||||
func testWarningThreshold_nil() {
|
||||
// swiftlint:disable:next force_try
|
||||
let config = try! Configuration(dict: [:])
|
||||
func testWarningThreshold_nil() throws {
|
||||
let config = try Configuration(dict: [:])
|
||||
XCTAssertNil(config.warningThreshold)
|
||||
}
|
||||
|
||||
|
@ -142,9 +137,8 @@ class ConfigurationTests: XCTestCase {
|
|||
XCTAssertNil(configuration)
|
||||
}
|
||||
|
||||
func testDisabledRules() {
|
||||
// swiftlint:disable:next force_try
|
||||
let disabledConfig = try! Configuration(dict: ["disabled_rules": ["nesting", "todo"]])
|
||||
func testDisabledRules() throws {
|
||||
let disabledConfig = try Configuration(dict: ["disabled_rules": ["nesting", "todo"]])
|
||||
XCTAssertEqual(disabledConfig.rulesWrapper.disabledRuleIdentifiers,
|
||||
["nesting", "todo"],
|
||||
"initializing Configuration with valid rules in Dictionary should succeed")
|
||||
|
@ -156,12 +150,11 @@ class ConfigurationTests: XCTestCase {
|
|||
XCTAssertEqual(expectedIdentifiers, configuredIdentifiers)
|
||||
}
|
||||
|
||||
func testDisabledRulesWithUnknownRule() {
|
||||
func testDisabledRulesWithUnknownRule() throws {
|
||||
let validRule = "nesting"
|
||||
let bogusRule = "no_sprites_with_elf_shoes"
|
||||
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(dict: ["disabled_rules": [validRule, bogusRule]])
|
||||
let configuration = try Configuration(dict: ["disabled_rules": [validRule, bogusRule]])
|
||||
|
||||
XCTAssertEqual(configuration.rulesWrapper.disabledRuleIdentifiers,
|
||||
[validRule],
|
||||
|
@ -351,21 +344,18 @@ class ConfigurationTests: XCTestCase {
|
|||
|
||||
// MARK: - Testing custom indentation
|
||||
|
||||
func testIndentationTabs() {
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(dict: ["indentation": "tabs"])
|
||||
func testIndentationTabs() throws {
|
||||
let configuration = try Configuration(dict: ["indentation": "tabs"])
|
||||
XCTAssertEqual(configuration.indentation, .tabs)
|
||||
}
|
||||
|
||||
func testIndentationSpaces() {
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(dict: ["indentation": 2])
|
||||
func testIndentationSpaces() throws {
|
||||
let configuration = try Configuration(dict: ["indentation": 2])
|
||||
XCTAssertEqual(configuration.indentation, .spaces(count: 2))
|
||||
}
|
||||
|
||||
func testIndentationFallback() {
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(dict: ["indentation": "invalid"])
|
||||
func testIndentationFallback() throws {
|
||||
let configuration = try Configuration(dict: ["indentation": "invalid"])
|
||||
XCTAssertEqual(configuration.indentation, .spaces(count: 4))
|
||||
}
|
||||
|
||||
|
@ -386,9 +376,8 @@ class ConfigurationTests: XCTestCase {
|
|||
XCTAssertTrue(rules == [RuleWithLevelsMock()])
|
||||
}
|
||||
|
||||
func testAllowZeroLintableFiles() {
|
||||
// swiftlint:disable:next force_try
|
||||
let configuration = try! Configuration(dict: ["allow_zero_lintable_files": true])
|
||||
func testAllowZeroLintableFiles() throws {
|
||||
let configuration = try Configuration(dict: ["allow_zero_lintable_files": true])
|
||||
XCTAssertTrue(configuration.allowZeroLintableFiles)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ class LinterCacheTests: XCTestCase {
|
|||
}
|
||||
|
||||
private func validateNewConfigDoesntHitCache(dict: [String: Any], initialConfig: Configuration,
|
||||
file: StaticString = #file, line: UInt = #line) {
|
||||
let newConfig = try! Configuration(dict: dict) // swiftlint:disable:this force_try
|
||||
file: StaticString = #file, line: UInt = #line) throws {
|
||||
let newConfig = try Configuration(dict: dict)
|
||||
let (file1, file2) = ("file1.swift", "file2.swift")
|
||||
|
||||
XCTAssertNil(cache.violations(forFile: file1, configuration: newConfig), file: (file), line: line)
|
||||
|
@ -187,8 +187,8 @@ class LinterCacheTests: XCTestCase {
|
|||
|
||||
// MARK: All-File Cache Invalidation
|
||||
|
||||
func testCustomRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
let initialConfig = try! Configuration( // swiftlint:disable:this force_try
|
||||
func testCustomRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(
|
||||
dict: [
|
||||
"only_rules": ["custom_rules", "rule1"],
|
||||
"custom_rules": ["rule1": ["regex": "([n,N]inja)"]]
|
||||
|
@ -198,7 +198,7 @@ class LinterCacheTests: XCTestCase {
|
|||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(
|
||||
try validateNewConfigDoesntHitCache(
|
||||
dict: [
|
||||
"only_rules": ["custom_rules", "rule1"],
|
||||
"custom_rules": ["rule1": ["regex": "([n,N]injas)"]]
|
||||
|
@ -207,7 +207,7 @@ class LinterCacheTests: XCTestCase {
|
|||
)
|
||||
|
||||
// Addition
|
||||
validateNewConfigDoesntHitCache(
|
||||
try validateNewConfigDoesntHitCache(
|
||||
dict: [
|
||||
"only_rules": ["custom_rules", "rule1"],
|
||||
"custom_rules": ["rule1": ["regex": "([n,N]injas)"], "rule2": ["regex": "([k,K]ittens)"]]
|
||||
|
@ -216,74 +216,70 @@ class LinterCacheTests: XCTestCase {
|
|||
)
|
||||
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: ["only_rules": ["custom_rules"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["only_rules": ["custom_rules"]], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testDisabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
// swiftlint:disable:next force_try
|
||||
let initialConfig = try! Configuration(dict: ["disabled_rules": ["nesting"]])
|
||||
func testDisabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(dict: ["disabled_rules": ["nesting"]])
|
||||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(dict: ["disabled_rules": ["todo"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["disabled_rules": ["todo"]], initialConfig: initialConfig)
|
||||
// Addition
|
||||
validateNewConfigDoesntHitCache(dict: ["disabled_rules": ["nesting", "todo"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["disabled_rules": ["nesting", "todo"]], initialConfig: initialConfig)
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: ["disabled_rules": []], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["disabled_rules": []], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testOptInRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
// swiftlint:disable:next force_try
|
||||
let initialConfig = try! Configuration(dict: ["opt_in_rules": ["attributes"]])
|
||||
func testOptInRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(dict: ["opt_in_rules": ["attributes"]])
|
||||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(dict: ["opt_in_rules": ["empty_count"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["opt_in_rules": ["empty_count"]], initialConfig: initialConfig)
|
||||
// Rules addition
|
||||
validateNewConfigDoesntHitCache(dict: ["opt_in_rules": ["attributes", "empty_count"]],
|
||||
initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["opt_in_rules": ["attributes", "empty_count"]],
|
||||
initialConfig: initialConfig)
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: ["opt_in_rules": []], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["opt_in_rules": []], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testEnabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
// swiftlint:disable:next force_try
|
||||
let initialConfig = try! Configuration(dict: ["enabled_rules": ["attributes"]])
|
||||
func testEnabledRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(dict: ["enabled_rules": ["attributes"]])
|
||||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(dict: ["enabled_rules": ["empty_count"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["enabled_rules": ["empty_count"]], initialConfig: initialConfig)
|
||||
// Addition
|
||||
validateNewConfigDoesntHitCache(dict: ["enabled_rules": ["attributes", "empty_count"]],
|
||||
initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["enabled_rules": ["attributes", "empty_count"]],
|
||||
initialConfig: initialConfig)
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: ["enabled_rules": []], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["enabled_rules": []], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testOnlyRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
// swiftlint:disable:next force_try
|
||||
let initialConfig = try! Configuration(dict: ["only_rules": ["nesting"]])
|
||||
func testOnlyRulesChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(dict: ["only_rules": ["nesting"]])
|
||||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(dict: ["only_rules": ["todo"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["only_rules": ["todo"]], initialConfig: initialConfig)
|
||||
// Addition
|
||||
validateNewConfigDoesntHitCache(dict: ["only_rules": ["nesting", "todo"]], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["only_rules": ["nesting", "todo"]], initialConfig: initialConfig)
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: ["only_rules": []], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["only_rules": []], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testRuleConfigurationChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() {
|
||||
let initialConfig = try! Configuration(dict: ["line_length": 120]) // swiftlint:disable:this force_try
|
||||
func testRuleConfigurationChangedOrAddedOrRemovedCausesAllFilesToBeReLinted() throws {
|
||||
let initialConfig = try Configuration(dict: ["line_length": 120])
|
||||
cacheAndValidateNoViolationsTwoFiles(configuration: initialConfig)
|
||||
|
||||
// Change
|
||||
validateNewConfigDoesntHitCache(dict: ["line_length": 100], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["line_length": 100], initialConfig: initialConfig)
|
||||
// Addition
|
||||
validateNewConfigDoesntHitCache(dict: ["line_length": 100, "number_separator": ["minimum_length": 5]],
|
||||
initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: ["line_length": 100, "number_separator": ["minimum_length": 5]],
|
||||
initialConfig: initialConfig)
|
||||
// Removal
|
||||
validateNewConfigDoesntHitCache(dict: [:], initialConfig: initialConfig)
|
||||
try validateNewConfigDoesntHitCache(dict: [:], initialConfig: initialConfig)
|
||||
}
|
||||
|
||||
func testSwiftVersionChangedRemovedCausesAllFilesToBeReLinted() {
|
||||
|
|
Loading…
Reference in New Issue