mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Moved nesting rule into example
This commit is contained in:
@@ -9,10 +9,12 @@
|
||||
import SourceKittenFramework
|
||||
import SwiftXPC
|
||||
|
||||
struct NestingRule: ASTRule {
|
||||
public struct NestingRule: ASTRule {
|
||||
public init() { }
|
||||
|
||||
let identifier = "nesting"
|
||||
|
||||
func validateFile(file: File) -> [StyleViolation] {
|
||||
public func validateFile(file: File) -> [StyleViolation] {
|
||||
return self.validateFile(file, dictionary: Structure(file: file).dictionary)
|
||||
}
|
||||
|
||||
@@ -75,11 +77,20 @@ struct NestingRule: ASTRule {
|
||||
return violations
|
||||
}
|
||||
|
||||
let example: RuleExample = RuleExample(
|
||||
public let example: RuleExample = RuleExample(
|
||||
ruleName: "Nesting Rule",
|
||||
ruleDescription: "Types should be nested at most 1 level deep, and statements should be nested at most 5 levels deep.",
|
||||
correctExamples: [],
|
||||
failingExamples: [],
|
||||
showExamples: false)
|
||||
correctExamples: ["class", "struct", "enum"].flatMap { kind in
|
||||
["\(kind) Class0 { \(kind) Class1 {} }\n",
|
||||
"func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " +
|
||||
"func func5() {\n}\n}\n}\n}\n}\n}\n"]
|
||||
},
|
||||
failingExamples: ["class", "struct", "enum"].map { kind in
|
||||
"\(kind) Class0 { \(kind) Class1 { \(kind) Class2 {} } }\n"
|
||||
} + [
|
||||
"func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " +
|
||||
"func func5() {\nfunc func6() {\n}\n}\n}\n}\n}\n}\n}\n"
|
||||
],
|
||||
showExamples: true)
|
||||
|
||||
}
|
||||
|
||||
@@ -153,28 +153,7 @@ class LinterTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testNesting() {
|
||||
for kind in ["class", "struct", "enum"] {
|
||||
XCTAssertEqual(violations("\(kind) Class0 { \(kind) Class1 {} }\n"), [])
|
||||
XCTAssertEqual(violations("\(kind) Class0 { \(kind) Class1 { \(kind) Class2 {} } }\n"),
|
||||
[
|
||||
StyleViolation(type: .Nesting,
|
||||
location: Location(file: nil, line: 1),
|
||||
reason: "Types should be nested at most 1 level deep")
|
||||
])
|
||||
}
|
||||
XCTAssertEqual(violations(
|
||||
"func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " +
|
||||
"func func5() {\n}\n}\n}\n}\n}\n}\n"
|
||||
), [])
|
||||
XCTAssertEqual(violations(
|
||||
"func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " +
|
||||
"func func5() {\nfunc func6() {\n}\n}\n}\n}\n}\n}\n}\n"
|
||||
),
|
||||
[
|
||||
StyleViolation(type: .Nesting,
|
||||
location: Location(file: nil, line: 6),
|
||||
reason: "Statements should be nested at most 5 levels deep")
|
||||
])
|
||||
verifyRule(NestingRule().example, type: StyleViolationType.Nesting, checkCommentsDoesNotViolate: false)
|
||||
}
|
||||
|
||||
func testControlStatements() {
|
||||
|
||||
Reference in New Issue
Block a user