diff --git a/CHANGELOG.md b/CHANGELOG.md index 546a1ccce0..3d173c736b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ FunctionBodyLength, Nesting, TypeBodyLength, TypeName, VariableName. [JP Simard](https://github.com/jpsim) +* swiftlint returns a non-zero error code when a warning of high-severity + or above is found in the source files being linted. + [Pat Wallace](https://github.com/pawrsccouk) + [#30](https://github.com/realm/SwiftLint/issues/30) + ##### Bug Fixes None. diff --git a/Source/SwiftLintFramework/ViolationSeverity.swift b/Source/SwiftLintFramework/ViolationSeverity.swift index d9d642f8f4..823e21f450 100644 --- a/Source/SwiftLintFramework/ViolationSeverity.swift +++ b/Source/SwiftLintFramework/ViolationSeverity.swift @@ -28,8 +28,12 @@ public enum ViolationSeverity: Int, Printable, Comparable { } } + public var isError: Bool { + return self > Medium + } + public var xcodeSeverityDescription: String { - return self <= Medium ? "warning" : "error" + return isError ? "error" : "warning" } } diff --git a/Source/swiftlint/Lint.swift b/Source/swiftlint/Lint.swift index ea32a455e1..301d45de37 100644 --- a/Source/swiftlint/Lint.swift +++ b/Source/swiftlint/Lint.swift @@ -22,20 +22,33 @@ struct LintCommand: CommandType { func run(mode: CommandMode) -> Result<(), CommandantError<()>> { println("Finding Swift files in current directory...") let files = recursivelyFindSwiftFilesInDirectory(fileManager.currentDirectoryPath) - var numberOfViolations = 0 + var numberOfViolations = 0, numberOfSeriousViolations = 0 for (index, file) in enumerate(files) { println("Linting '\(file.lastPathComponent)' (\(index + 1)/\(files.count))") for violation in Linter(file: File(path: file)!).styleViolations { println(violation) numberOfViolations++ + if violation.severity.isError { + numberOfSeriousViolations++ + } } } + let violationSuffix = (numberOfViolations != 1 ? "s" : "") + let filesSuffix = (files.count != 1 ? "s." : ".") println( - "Done linting! Found \(numberOfViolations) violation" + - (numberOfViolations != 1 ? "s" : "") + - " in \(files.count) file" + (files.count != 1 ? "s." : ".") + "Done linting!" + + " Found \(numberOfViolations) violation\(violationSuffix)," + + " \(numberOfSeriousViolations) serious" + + " in \(files.count) file\(filesSuffix)" ) - return success() + if numberOfSeriousViolations <= 0 { + return success() + } else { + // This represents failure of the content (i.e. violations in the files linted) + // and not failure of the scanning process itself. The current command architecture + // doesn't discriminate between these types. + return failure(CommandantError<()>.CommandError(Box())) + } } }