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

use multiple exit codes to distinguish between errors & strict warnings #584

Merged
merged 3 commits into from Mar 10, 2016

Conversation

jpsim
Copy link
Collaborator

@jpsim jpsim commented Mar 10, 2016

Addresses #166.

Does this approach make sense to you all? /cc @jakecraige @kylef @scottrhoyt @norio-nomura

@jpsim
Copy link
Collaborator Author

jpsim commented Mar 10, 2016

Code Meaning
0 No errors, maybe warnings in non-strict mode
1 Usage or system error
2 Style violations of severity "Error"
3 No style violations of severity "Error", but violations of severity "warning" with --strict

@scottrhoyt
Copy link
Contributor

That's funny! I just implemented the same thing--though slightly differently. I created a new error type to be used as Commandant's ClientError

enum SwiftLintError: ErrorType {
    case ExitCode(Int)
}

LintCommand was similar to your implementation:

            if numberOfSeriousViolations > 0 {
                return .Failure(.CommandError(.ExitCode(2)))
            } else if options.strict && !violations.isEmpty {
                return .Failure(.CommandError(.ExitCode(3)))
            } 

Then in main.swift I modified the Commandant error handler to be:

registry.main(defaultVerb: LintCommand().verb) { error in
    queuedPrintError(String(error))
    switch error {
    case .CommandError(.ExitCode(let code)):
        exit(Int32(code))
    default:
        break
    }
}

The effect was the same as what you did, though I suppose it's a solution that might offer room for expansion to more types of errors/handling, but there's no good use case for that currently, so I'm happy to go with your much simpler approach. 👍

otherwise we get a function length exceeded violation
@jpsim
Copy link
Collaborator Author

jpsim commented Mar 10, 2016

Oh, sorry for stepping on your toes then @scottrhoyt! Your approach is definitely nicer, while mine is simpler. In this case, I'd prefer keeping things simple until that "doesn't scale" 😛

@scottrhoyt
Copy link
Contributor

Premature optimization is the root of all evil. 😄

I'm all for simple. I'll keep it stashed away incase we go that direction.

@jpsim
Copy link
Collaborator Author

jpsim commented Mar 10, 2016

I'm all for simple. I'll keep it stashed away incase we go that direction.

👍

jpsim added a commit that referenced this pull request Mar 10, 2016
use multiple exit codes to distinguish between errors & strict warnings
@jpsim jpsim merged commit ee77861 into master Mar 10, 2016
@jpsim jpsim deleted the jp-multiple-exit-codes branch March 10, 2016 04:59
@jakecraige
Copy link
Contributor

Awesome! Thanks for doing this.

@norio-nomura
Copy link
Collaborator

Nice!

jpsim added a commit that referenced this pull request Mar 14, 2016
Fix printing duplicated violations bug that introduced by #584
@jinnatan
Copy link

Awesome

norio-nomura added a commit to norio-nomura/linter-swiftlint that referenced this pull request Jan 30, 2017
SwiftLint returns 2 as exit code when detecting style violations of severity "Error”.
realm/SwiftLint#584

That produces error on running linter-swiftlint as following:
> Error: Process exited with non-zero code: 2

This commit avoid that error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants