Moved nesting rule into example

This commit is contained in:
Chris Eidhof
2015-05-20 16:56:30 +02:00
committed by JP Simard
parent 20fd31672a
commit 31e4a3ec50
2 changed files with 18 additions and 28 deletions
@@ -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() {