Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiftlint autocorrect #163

Merged
merged 4 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swift:
config_file: .swiftlint.yml
8 changes: 8 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
disabled_rules:
opt_in_rules:
- missing_docs
included:
excluded:
- Packages
- Sources/Vapor/Core/Generated.swift
- Sources/Generator
24 changes: 12 additions & 12 deletions Sources/Vapor/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
To override certain configurations for a given environment,
create a file with the same name in a subdirectory of the environment.
For example, a file named `Config/production/app.json` would override
any properties in `Config/app.json`.
any properties in `Config/app.json`.

Finally, Vapor supports sensitive environment specific information, such
as API keys, to be stored in a special configuration file at `Config/.env.json`.
Expand All @@ -22,15 +22,15 @@ public class Config {
//The internal store of configuration options
//backed by `Json`
private var repository: [String: Json]

public enum Error: ErrorProtocol {
case NoFileFound
case NoValueFound
}

/**
Creates an instance of `Config` with an
optional starting repository of information.
optional starting repository of information.
The application is required to detect environment.
*/
public init(repository: [String: Json] = [:], application: Application? = nil) {
Expand All @@ -46,15 +46,15 @@ public class Config {
let result: Node? = try? get(keyPath)
return result != nil
}

///Returns the generic Json representation for an item at a given path or throws
public func get(keyPath: String) throws -> Node {
var keys = keyPath.keys

guard let json: Json = repository[keys.removeFirst()] else {
throw Error.NoFileFound
}

var node: Node? = json

for key in keys {
Expand All @@ -64,24 +64,24 @@ public class Config {
guard let result = node else {
throw Error.NoValueFound
}

return result
}

//Returns the value for a given type from the Config or throws
public func get<T: NodeInitializable>(keyPath: String) throws -> T {
let result: Node = try get(keyPath)
return try T.makeWith(result)
}


///Returns the result of `get(key: String)` but with a `String` fallback for `nil` cases
public func get<T: NodeInitializable>(keyPath: String, _ fallback: T) -> T {
let string: T? = try? get(keyPath)
return string ?? fallback
}


///Temporarily sets a value for a given key path
public func set(value: Json, forKeyPath keyPath: String) {
var keys = keyPath.keys
Expand Down Expand Up @@ -110,8 +110,8 @@ public class Config {
return false
}
}



///Attempts to populate the internal configuration store
public func populate(path: String, application: Application) throws {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Vapor/Core/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Application {
Provides access to config settings.
*/
public lazy var config: Config = Config(application: self)

/**
Provides access to the underlying
`HashDriver`.
Expand Down Expand Up @@ -190,7 +190,7 @@ public class Application {
self.port = port ?? self.port

bootRoutes()

if environment == .Production {
Log.info("Production mode detected, disabling information logs.")
Log.enabledLevels = [.Error, .Fatal]
Expand Down Expand Up @@ -261,7 +261,7 @@ extension Application: ServerDriverDelegate {
if environment == .Production {
error = "Something went wrong"
}

return Response(error: error)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Vapor/Core/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Simply append a dependencies provider to the Application's
`providers` array.
The Provider should take care of setting up any

The Provider should take care of setting up any
necessary configurations on itself and the Application.
*/
public protocol Provider {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Vapor/Fixes/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FileManager {
}

static func readBytesFromFile(path: String) throws -> [UInt8] {
let fd = open(path, O_RDONLY);
let fd = open(path, O_RDONLY)

if fd < 0 {
throw Error.CouldNotOpenFile
Expand All @@ -27,19 +27,19 @@ class FileManager {
}
return true
}

if !ret {
throw Error.Unreadable
}

let length = Int(info.st_size)

let rawData = malloc(length)
var remaining = Int(info.st_size)
var total = 0
while remaining > 0 {
let advanced = rawData.advanced(by: total)

let amt = read(fd, advanced, remaining)
if amt < 0 {
break
Expand Down Expand Up @@ -95,7 +95,7 @@ class FileManager {
}

defer { free(result) }

let cstring = String(validatingUTF8: result)

if let expanded = cstring {
Expand Down Expand Up @@ -131,7 +131,7 @@ class FileManager {
#endif

for i in 0..<count {

let cstring = String(validatingUTF8: gt.gl_pathv[i])
if let path = cstring {
contents.append(path)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Vapor/Fixes/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ extension String {
return self + ending
}
}

init?(data: [UInt8]) {
var signedData = data.map { byte in
return Int8(byte)
}
signedData.append(0)

guard let string = String(validatingUTF8: signedData) else {
return nil
}

self = string
}

Expand All @@ -33,7 +33,7 @@ extension String {
}
return true
}

func hasSuffix(str: String) -> Bool {
let strGen = str.characters.reversed().makeIterator()
let selfGen = self.characters.reversed().makeIterator()
Expand All @@ -45,4 +45,4 @@ extension String {
}

#endif
}
}