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

Return an error status code if serious violations found #31

Merged
merged 2 commits into from
May 24, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion Source/SwiftLintFramework/ViolationSeverity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
23 changes: 18 additions & 5 deletions Source/swiftlint/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}
}

Expand Down