forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request realm#314 from realm/sh-dictionary-parameters
Dictionary Parameterization of rules
- Loading branch information
Showing
39 changed files
with
692 additions
and
167 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
20 changes: 20 additions & 0 deletions
20
Source/SwiftLintFramework/Extensions/Array+SwiftLint.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,20 @@ | ||
// | ||
// Array+SwiftLint.swift | ||
// SwiftLint | ||
// | ||
// Created by Scott Hoyt on 1/11/16. | ||
// Copyright © 2016 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
static func arrayOf(obj: AnyObject?) -> [Element]? { | ||
if let array = obj as? [Element] { | ||
return array | ||
} else if let obj = obj as? Element { | ||
return [obj] | ||
} | ||
return nil | ||
} | ||
} |
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,65 @@ | ||
// | ||
// Yaml+SwiftLint.swift | ||
// SwiftLint | ||
// | ||
// Created by Scott Hoyt on 12/28/15. | ||
// Copyright © 2015 Realm. All rights reserved. | ||
// | ||
|
||
import Yaml | ||
|
||
extension Yaml { | ||
var flatDictionary: [Swift.String : AnyObject]? { | ||
if let dict = dictionary { | ||
var newDict: [Swift.String : AnyObject] = [:] | ||
for (key, value) in dict { | ||
newDict[key.stringValue] = value.flatValue | ||
} | ||
return newDict | ||
} else if self.count == 0 || self == .Null { | ||
return [:] | ||
} | ||
|
||
return nil | ||
} | ||
|
||
var flatArray: [AnyObject]? { return array?.map { $0.flatValue } } | ||
|
||
var flatValue: AnyObject { | ||
switch self { | ||
case .Bool(let myBool): | ||
return myBool | ||
case .Int(let myInt): | ||
return myInt | ||
case .Double(let myDouble): | ||
return myDouble | ||
case .String(let myString): | ||
return myString | ||
case .Array: | ||
return flatArray! // This is valid because .Array will always flatten | ||
case .Dictionary: | ||
return flatDictionary! // This is valid because .Dictionary will always flatten | ||
case .Null: | ||
return NSNull() | ||
} | ||
} | ||
|
||
var stringValue: Swift.String { | ||
switch self { | ||
case .Bool(let myBool): | ||
return myBool.description | ||
case .Int(let myInt): | ||
return myInt.description | ||
case .Double(let myDouble): | ||
return myDouble.description | ||
case .String(let myString): | ||
return myString | ||
case .Array(let myArray): | ||
return myArray.description | ||
case .Dictionary(let myDictionary): | ||
return myDictionary.description | ||
case .Null: | ||
return "Null" | ||
} | ||
} | ||
} |
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,48 @@ | ||
// | ||
// MasterRuleList.swift | ||
// SwiftLint | ||
// | ||
// Created by Scott Hoyt on 12/28/15. | ||
// Copyright © 2015 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct RuleList { | ||
public let list: [String: Rule.Type] | ||
public init(rules: Rule.Type...) { | ||
var tmpList = [String: Rule.Type]() | ||
for rule in rules { | ||
tmpList[rule.description.identifier] = rule | ||
} | ||
list = tmpList | ||
} | ||
} | ||
|
||
public let masterRuleList = RuleList( rules: ClosingBraceRule.self, | ||
ColonRule.self, | ||
CommaRule.self, | ||
ConditionalBindingCascadeRule.self, | ||
ControlStatementRule.self, | ||
FileLengthRule.self, | ||
ForceCastRule.self, | ||
ForceTryRule.self, | ||
FunctionBodyLengthRule.self, | ||
LeadingWhitespaceRule.self, | ||
LegacyConstructorRule.self, | ||
LineLengthRule.self, | ||
NestingRule.self, | ||
OpeningBraceRule.self, | ||
OperatorFunctionWhitespaceRule.self, | ||
ReturnArrowWhitespaceRule.self, | ||
StatementPositionRule.self, | ||
TodoRule.self, | ||
TrailingNewlineRule.self, | ||
TrailingSemicolonRule.self, | ||
TrailingWhitespaceRule.self, | ||
TypeBodyLengthRule.self, | ||
TypeNameRule.self, | ||
ValidDocsRule.self, | ||
VariableNameMaxLengthRule.self, | ||
VariableNameMinLengthRule.self, | ||
VariableNameRule.self) |
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
Oops, something went wrong.