-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a459ccf
commit 0c9827b
Showing
5 changed files
with
81 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/ExplicitInitConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
struct ExplicitInitConfiguration: SeverityBasedRuleConfiguration, Equatable { | ||
typealias Parent = ExplicitInitRule | ||
|
||
@ConfigurationElement(key: "severity") | ||
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning) | ||
@ConfigurationElement(key: "include_bare_init") | ||
private(set) var includeBareInit = false | ||
|
||
mutating func apply(configuration: Any) throws { | ||
guard let configuration = configuration as? [String: Any] else { | ||
throw Issue.unknownConfiguration(ruleID: Parent.identifier) | ||
} | ||
|
||
if let severityString = configuration[$severityConfiguration] as? String { | ||
try severityConfiguration.apply(configuration: severityString) | ||
} | ||
|
||
if let includeBareInit = configuration[$includeBareInit] as? Bool { | ||
self.includeBareInit = includeBareInit | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@testable import SwiftLintBuiltInRules | ||
|
||
class ExplicitInitRuleTests: SwiftLintTestCase { | ||
func testIncludeBareInit() { | ||
let nonTriggeringExamples = [ | ||
Example("let foo = Foo()"), | ||
Example("let foo = init()") | ||
] + ExplicitInitRule.description.nonTriggeringExamples | ||
|
||
let triggeringExamples = [ | ||
Example("let foo: Foo = ↓.init()"), | ||
Example("let foo: [Foo] = [↓.init(), ↓.init()]"), | ||
Example("foo(↓.init())") | ||
] | ||
|
||
let description = ExplicitInitRule.description | ||
.with(nonTriggeringExamples: nonTriggeringExamples) | ||
.with(triggeringExamples: triggeringExamples) | ||
.with(corrections: [:]) | ||
|
||
verifyRule(description, ruleConfiguration: ["include_bare_init": true]) | ||
} | ||
} |