diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c9c23ebd..b317f23517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,25 @@ ## Master +##### Breaking + +* None. + +##### Enhancements + +* None. + ##### Bug Fixes * Make linting faster than 0.5.0, but slower than 0.4.0 [Norio Nomura](https://github.com/norio-nomura) [#119](https://github.com/jpsim/SourceKitten/issues/119) +* Re-introduce `--use-script-input-files` option for `lint` & `autocorrect` + commands. Should also fix some issues when running SwiftLint from an Xcode + build phase. + [JP Simard](https://github.com/jpsim) + [#264](https://github.com/realm/SwiftLint/issues/264) + ## 0.5.0: Downy™ ##### Breaking @@ -72,7 +86,7 @@ [JP Simard](https://github.com/jpsim) * Support linting from Input Files provided by Run Script Phase of Xcode with - `--use-script-input-files`. + `--use-script-input-files`. [Norio Nomura](https://github.com/norio-nomura) [#193](https://github.com/realm/SwiftLint/pull/193) diff --git a/Source/swiftlint/Commands/AutoCorrectCommand.swift b/Source/swiftlint/Commands/AutoCorrectCommand.swift index 47f3f26e7d..0d86219799 100644 --- a/Source/swiftlint/Commands/AutoCorrectCommand.swift +++ b/Source/swiftlint/Commands/AutoCorrectCommand.swift @@ -20,7 +20,8 @@ struct AutoCorrectCommand: CommandType { func run(mode: CommandMode) -> Result<(), CommandantError<()>> { return AutoCorrectOptions.evaluate(mode).flatMap { options in let configuration = Configuration(commandLinePath: options.configurationFile) - return configuration.visitLintableFiles(options.path, action: "Correcting") { linter in + return configuration.visitLintableFiles(options.path, action: "Correcting", + useScriptInputFiles: options.useScriptInputFiles) { linter in let corrections = linter.correct() if !corrections.isEmpty { let correctionLogs = corrections.map({ $0.consoleDescription }) @@ -37,6 +38,7 @@ struct AutoCorrectCommand: CommandType { struct AutoCorrectOptions: OptionsType { let path: String let configurationFile: String + let useScriptInputFiles: Bool static func evaluate(mode: CommandMode) -> Result> { return curry(self.init) @@ -46,5 +48,8 @@ struct AutoCorrectOptions: OptionsType { <*> mode <| Option(key: "config", defaultValue: ".swiftlint.yml", usage: "the path to SwiftLint's configuration file") + <*> mode <| Option(key: "use-script-input-files", + defaultValue: false, + usage: "read SCRIPT_INPUT_FILE* environment variables as files") } } diff --git a/Source/swiftlint/Commands/LintCommand.swift b/Source/swiftlint/Commands/LintCommand.swift index 3a5e2cccc2..e92647bf03 100644 --- a/Source/swiftlint/Commands/LintCommand.swift +++ b/Source/swiftlint/Commands/LintCommand.swift @@ -23,7 +23,8 @@ struct LintCommand: CommandType { var reporter: Reporter.Type! let configuration = Configuration(commandLinePath: options.configurationFile) return configuration.visitLintableFiles(options.path, action: "Linting", - useSTDIN: options.useSTDIN) { linter in + useSTDIN: options.useSTDIN, + useScriptInputFiles: options.useScriptInputFiles) { linter in let currentViolations = linter.styleViolations violations += currentViolations if reporter == nil { reporter = linter.reporter } @@ -61,9 +62,11 @@ struct LintOptions: OptionsType { let useSTDIN: Bool let configurationFile: String let strict: Bool + let useScriptInputFiles: Bool static func evaluate(mode: CommandMode) -> Result> { - return curry(self.init) + let curriedInitializer = curry(self.init) + return curriedInitializer <*> mode <| Option(key: "path", defaultValue: "", usage: "the path to the file or directory to lint") @@ -76,5 +79,8 @@ struct LintOptions: OptionsType { <*> mode <| Option(key: "strict", defaultValue: false, usage: "fail on warnings") + <*> mode <| Option(key: "use-script-input-files", + defaultValue: false, + usage: "read SCRIPT_INPUT_FILE* environment variables as files") } } diff --git a/Source/swiftlint/Extensions/Configuration+CommandLine.swift b/Source/swiftlint/Extensions/Configuration+CommandLine.swift index 4799b6dd1d..f130d089d1 100644 --- a/Source/swiftlint/Extensions/Configuration+CommandLine.swift +++ b/Source/swiftlint/Extensions/Configuration+CommandLine.swift @@ -12,8 +12,6 @@ import Result import SourceKittenFramework import SwiftLintFramework -private let inputFileKey = "SCRIPT_INPUT_FILE_COUNT" - private func scriptInputFiles() -> Result<[String], CommandantError<()>> { func getEnvironmentVariable(variable: String) -> Result> { let environment = NSProcessInfo.processInfo().environment @@ -24,6 +22,7 @@ private func scriptInputFiles() -> Result<[String], CommandantError<()>> { } let count: Result> = { + let inputFileKey = "SCRIPT_INPUT_FILE_COUNT" guard let countString = NSProcessInfo.processInfo().environment[inputFileKey] else { return .Failure(.UsageError(description: "\(inputFileKey) variable not set")) } @@ -64,8 +63,10 @@ extension Configuration { } func visitLintableFiles(path: String, action: String, useSTDIN: Bool = false, - visitorBlock: (Linter) -> ()) -> Result<[File], CommandantError<()>> { - return getFiles(path, action: action, useSTDIN: useSTDIN) + useScriptInputFiles: Bool, visitorBlock: (Linter) -> ()) -> + Result<[File], CommandantError<()>> { + return getFiles(path, action: action, useSTDIN: useSTDIN, + useScriptInputFiles: useScriptInputFiles) .flatMap { files -> Result<[File], CommandantError<()>> in if files.isEmpty { let errorMessage = "No lintable files found at path '\(path)'" @@ -85,8 +86,8 @@ extension Configuration { } } - private func getFiles(path: String, action: String, useSTDIN: Bool) -> - Result<[File], CommandantError<()>> { + private func getFiles(path: String, action: String, useSTDIN: Bool, + useScriptInputFiles: Bool) -> Result<[File], CommandantError<()>> { if useSTDIN { let standardInput = NSFileHandle.fileHandleWithStandardInput() let stdinData = standardInput.readDataToEndOfFile() @@ -95,7 +96,7 @@ extension Configuration { return .Success([File(contents: stdinString)]) } return .Failure(.UsageError(description: "stdin isn't a UTF8-encoded string")) - } else if NSProcessInfo.processInfo().environment.keys.contains(inputFileKey) { + } else if useScriptInputFiles { return scriptInputFiles().map { $0.flatMap(File.maybeSwiftFile) } } queuedPrintError(