Skip to content

Commit

Permalink
update dependencies & make minor improvements to some rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Nov 15, 2015
1 parent 6f643c4 commit 2300904
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github "antitypical/Result" "0.6.0-beta.5"
github "drmohundro/SWXMLHash" "2.0.3"
github "drmohundro/SWXMLHash" "2.0.4"
github "jpsim/SwiftXPC" "1.1.0"
github "behrang/YamlSwift" "1.2.2"
github "jspahrsummers/xcconfigs" "0.8.1"
Expand Down
14 changes: 6 additions & 8 deletions Source/SwiftLintFramework/Rules/FileLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public struct FileLengthRule: ParameterizedRule {

public func validateFile(file: File) -> [StyleViolation] {
let lineCount = file.lines.count
for parameter in parameters.reverse() {
if lineCount > parameter.value {
return [StyleViolation(ruleDescription: self.dynamicType.description,
severity: parameter.severity,
location: Location(file: file.path, line: lineCount),
reason: "File should contain \(parameters.first!.value) lines or less: " +
"currently contains \(lineCount)")]
}
for parameter in parameters.reverse() where lineCount > parameter.value {
return [StyleViolation(ruleDescription: self.dynamicType.description,
severity: parameter.severity,
location: Location(file: file.path, line: lineCount),
reason: "File should contain \(parameters.first!.value) lines or less: " +
"currently contains \(lineCount)")]
}
return []
}
Expand Down
8 changes: 3 additions & 5 deletions Source/SwiftLintFramework/Rules/NestingRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public struct NestingRule: ASTRule {
)

public func validateFile(file: File, kind: SwiftDeclarationKind,
dictionary: XPCDictionary) -> [StyleViolation] {
dictionary: XPCDictionary) -> [StyleViolation] {
return validateFile(file, kind: kind, dictionary: dictionary, level: 0)
}

func validateFile(file: File,
kind: SwiftDeclarationKind,
dictionary: XPCDictionary,
level: Int) -> [StyleViolation] {
func validateFile(file: File, kind: SwiftDeclarationKind, dictionary: XPCDictionary,
level: Int) -> [StyleViolation] {
var violations = [StyleViolation]()
let typeKinds: [SwiftDeclarationKind] = [.Class, .Struct, .Typealias, .Enum]
if let offset = (dictionary["key.offset"] as? Int64).flatMap({ Int($0) }) {
Expand Down
12 changes: 3 additions & 9 deletions Source/SwiftLintFramework/Rules/ReturnArrowWhitespaceRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@ public struct ReturnArrowWhitespaceRule: Rule {
let space = "[ \\f\\r\\t]"
let spaceRegex = "(\(space){0}|\(space){2,})"

// ex: func abc()-> Int {
let pattern1 = file.matchPattern("\\)\(spaceRegex)\\->\\s*\\S+",
withSyntaxKinds: [.Typeidentifier])

// ex: func abc() ->Int {
let pattern2 = file.matchPattern("\\)\\s\\->\(spaceRegex)\\S+",
withSyntaxKinds: [.Typeidentifier])

return (pattern1 + pattern2).map { match in
// ex: `func abc()-> Int {` & `func abc() ->Int {`
let pattern = "\\)(\(spaceRegex)\\->\\s*|\\s\\->\(spaceRegex))\\S+"
return file.matchPattern(pattern, withSyntaxKinds: [.Typeidentifier]).map { match in
return StyleViolation(ruleDescription: self.dynamicType.description,
location: Location(file: file, offset: match.location),
reason: "File should have 1 space before return arrow and return type")
Expand Down
14 changes: 6 additions & 8 deletions Source/SwiftLintFramework/Rules/VariableNameMaxLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ extension String {
return []
}
let name = nameStrippingLeadingUnderscoreIfPrivate(dictionary)
for parameter in parameters.reverse() {
if name.characters.count > parameter.value {
return [StyleViolation(ruleDescription: ruleDescription,
severity: parameter.severity,
location: location,
reason: "Variable name should be \(parameter.value) characters " +
"or less: currently \(name.characters.count) characters")]
}
for parameter in parameters.reverse() where name.characters.count > parameter.value {
return [StyleViolation(ruleDescription: ruleDescription,
severity: parameter.severity,
location: location,
reason: "Variable name should be \(parameter.value) characters " +
"or less: currently \(name.characters.count) characters")]
}
return []
}
Expand Down
14 changes: 6 additions & 8 deletions Source/SwiftLintFramework/Rules/VariableNameMinLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ extension String {
return []
}
let name = nameStrippingLeadingUnderscoreIfPrivate(dictionary)
for parameter in parameters.reverse() {
if name.characters.count < parameter.value {
return [StyleViolation(ruleDescription: ruleDescription,
severity: parameter.severity,
location: location,
reason: "Variable name should be \(parameter.value) characters " +
"or more: currently \(name.characters.count) characters")]
}
for parameter in parameters.reverse() where name.characters.count < parameter.value {
return [StyleViolation(ruleDescription: ruleDescription,
severity: parameter.severity,
location: location,
reason: "Variable name should be \(parameter.value) characters " +
"or more: currently \(name.characters.count) characters")]
}
return []
}
Expand Down

0 comments on commit 2300904

Please sign in to comment.