Skip to content

Commit

Permalink
Autocorrected files
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ernst committed Mar 8, 2017
1 parent 6a653cd commit 9a07a6f
Show file tree
Hide file tree
Showing 169 changed files with 444 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/SwiftLintFramework/Extensions/Array+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ import Dispatch
import Foundation

extension Array where Element: NSTextCheckingResult {

func ranges() -> [NSRange] {
return map { $0.range }
}

}

extension Array where Element: Equatable {

var unique: [Element] {
var uniqueValues = [Element]()
for item in self where !uniqueValues.contains(item) {
uniqueValues.append(item)
}
return uniqueValues
}

}

extension Array {

static func array(of obj: Any?) -> [Element]? {
if let array = obj as? [Element] {
return array
Expand Down Expand Up @@ -73,4 +78,5 @@ extension Array {
}
return result.sorted { $0.0 < $1.0 }.map { $0.1 }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

extension CharacterSet {

func isSuperset(ofCharactersIn string: String) -> Bool {
#if os(Linux)
// workaround for https://bugs.swift.org/browse/SR-3485
Expand All @@ -23,13 +24,16 @@ extension CharacterSet {
return isSuperset(of: otherSet)
#endif
}

}

extension Character {

fileprivate var unicodeScalar: UnicodeScalar {
let characterString = String(self)
let scalars = characterString.unicodeScalars

return scalars[scalars.startIndex]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ extension Dictionary where Key: ExpressibleByStringLiteral {
return name
}
}

}
5 changes: 5 additions & 0 deletions Source/SwiftLintFramework/Extensions/File+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal typealias AssertHandler = () -> Void
private var assertHandlers = [String: AssertHandler]()

private struct RebuildQueue {

private let lock = NSLock()
private var queue = [Structure]()
private var allDeclarationsByType = [String: [String]]()
Expand Down Expand Up @@ -75,11 +76,13 @@ private struct RebuildQueue {
rebuildIfNecessary()
return allDeclarationsByType
}

}

private var queueForRebuild = RebuildQueue()

private struct Cache<T> {

private var values = [String: T]()
private let factory: (File) -> T
private let lock = NSLock()
Expand Down Expand Up @@ -123,6 +126,7 @@ private struct Cache<T> {
block()
lock.unlock()
}

}

extension File {
Expand Down Expand Up @@ -219,4 +223,5 @@ extension File {
internal static var allDeclarationsByType: [String: [String]] {
return queueForRebuild.getAllDeclarationsByType()
}

}
1 change: 1 addition & 0 deletions Source/SwiftLintFramework/Extensions/File+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal func regex(_ pattern: String,
}

extension File {

internal func regions() -> [Region] {
var regions = [Region]()
var disabledRules = Set<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import Foundation

public protocol LintableFileManager {

func filesToLint(inPath: String, rootDirectory: String?) -> [String]

}

extension FileManager: LintableFileManager {

public func filesToLint(inPath path: String, rootDirectory: String? = nil) -> [String] {
let rootPath = rootDirectory ?? currentDirectoryPath
let absolutePath = path.bridge()
Expand All @@ -31,4 +34,5 @@ extension FileManager: LintableFileManager {
return nil
} ?? []
}

}
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Extensions/NSRange+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

extension NSRange {

func intersects(_ range: NSRange) -> Bool {
return NSIntersectionRange(self, range).length > 0
}
Expand All @@ -19,4 +20,5 @@ extension NSRange {
}
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public typealias NSTextCheckingResult = TextCheckingResult
private var regexCache = [RegexCacheKey: NSRegularExpression]()

private struct RegexCacheKey: Hashable {

let pattern: String
let options: NSRegularExpression.Options

Expand All @@ -26,9 +27,11 @@ private struct RegexCacheKey: Hashable {
static func == (lhs: RegexCacheKey, rhs: RegexCacheKey) -> Bool {
return lhs.options == rhs.options && lhs.pattern == rhs.pattern
}

}

extension NSRegularExpression {

internal static func cached(pattern: String, options: Options? = nil) throws -> NSRegularExpression {
let options = options ?? [.anchorsMatchLines, .dotMatchesLineSeparators]
let key = RegexCacheKey(pattern: pattern, options: options)
Expand All @@ -40,4 +43,5 @@ extension NSRegularExpression {
regexCache[key] = result
return result
}

}
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Extensions/String+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import SourceKittenFramework

extension String {

internal func hasTrailingWhitespace() -> Bool {
if isEmpty {
return false
Expand Down Expand Up @@ -92,4 +93,5 @@ extension String {
}
return false
}

}
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Extensions/String+XML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

extension String {

func escapedForXML() -> String {
// & needs to go first, otherwise other replacements will be replaced again
let htmlEscapes = [
Expand All @@ -22,4 +23,5 @@ extension String {
}
return newString
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ extension Structure {
parse(dictionary)
return results
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SourceKittenFramework

extension SwiftDeclarationKind {

internal static func variableKinds() -> [SwiftDeclarationKind] {
return [
.varClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

public enum SwiftExpressionKind: String {

case call = "source.lang.swift.expr.call"
case argument = "source.lang.swift.expr.argument"
case array = "source.lang.swift.expr.array"
Expand All @@ -32,4 +33,5 @@ public enum SwiftExpressionKind: String {
self = .other
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SourceKittenFramework

extension SyntaxKind {

init(shortName: Swift.String) throws {
let prefix = "source.lang.swift.syntaxtype."
guard let kind = SyntaxKind(rawValue: prefix + shortName.lowercased()) else {
Expand All @@ -35,4 +36,5 @@ extension SyntaxKind {
.keyword, .number, .objectLiteral, .parameter, .placeholder, .string,
.stringInterpolationAnchor, .typeidentifier]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ extension SyntaxMap {
}
return Array(tokensBeginningIntersect)
}

}
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Extensions/Yaml+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import Yaml

extension Yaml {

var flatDictionary: [Swift.String: Any]? {
if let dict = dictionary {
var newDict: [Swift.String: Any] = [:]
Expand Down Expand Up @@ -63,4 +64,5 @@ extension Yaml {
return "Null"
}
}

}
1 change: 1 addition & 0 deletions Source/SwiftLintFramework/Helpers/RegexHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ struct RegexHelpers {

// Two 'variable or number'
static let twoVariableOrNumber = "\(variableOrNumber),\(variableOrNumber)"

}
10 changes: 10 additions & 0 deletions Source/SwiftLintFramework/Models/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import Foundation

#if !os(Linux)

private extension Scanner {

func scanUpToString(_ string: String) -> String? {
var result: NSString? = nil
let success = scanUpTo(string, into: &result)
Expand All @@ -27,11 +29,15 @@ private extension Scanner {
}
return nil
}

}

#endif

public struct Command {

public enum Action: String {

case enable
case disable

Expand All @@ -41,12 +47,15 @@ public struct Command {
case .disable: return .enable
}
}

}

public enum Modifier: String {

case previous
case this
case next

}

internal let action: Action
Expand Down Expand Up @@ -121,4 +130,5 @@ public struct Command {
]
}
}

}
6 changes: 6 additions & 0 deletions Source/SwiftLintFramework/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SourceKittenFramework
private let fileManager = FileManager.default

private enum ConfigurationKey: String {

case cachePath = "cache_path"
case disabledRules = "disabled_rules"
case enabledRules = "enabled_rules" // deprecated in favor of optInRules
Expand All @@ -23,9 +24,11 @@ private enum ConfigurationKey: String {
case useNestedConfigs = "use_nested_configs" // deprecated
case warningThreshold = "warning_threshold"
case whitelistRules = "whitelist_rules"

}

public struct Configuration: Equatable {

public static let fileName = ".swiftlint.yml"
public let included: [String] // included
public let excluded: [String] // excluded
Expand Down Expand Up @@ -216,6 +219,7 @@ public struct Configuration: Equatable {
}
return self
}

}

private func validateRuleIdentifiers(configuredRules: [Rule], disabledRules: [String]) -> [String] {
Expand Down Expand Up @@ -310,6 +314,7 @@ private func warnAboutDeprecations(configurationDictionary dict: [String: Any],
// MARK: - Nested Configurations Extension

extension Configuration {

fileprivate func configuration(forPath path: String) -> Configuration {
let pathNSString = path.bridge()
let configurationSearchPath = pathNSString.appendingPathComponent(Configuration.fileName)
Expand All @@ -336,6 +341,7 @@ extension Configuration {
internal func merge(with configuration: Configuration) -> Configuration {
return configuration
}

}

// Mark - == Implementation
Expand Down
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Models/ConfigurationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
import Foundation

public enum ConfigurationError: Error {

case unknownConfiguration

}
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Models/Correction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
//

public struct Correction: Equatable {

public let ruleDescription: RuleDescription
public let location: Location

public var consoleDescription: String {
return "\(location) Corrected \(ruleDescription.name)"
}

}

// MARK: Equatable
Expand Down
Loading

0 comments on commit 9a07a6f

Please sign in to comment.