Add support for beautifiers ignoring CLI return code

Rubocop always returns an error code (1) instead of a good code (0) so
the beautifier has now been configured to ignore the return code / exit
status for only Rubocop beautifier. Other beautifiers will properly
return error when an bad return code is received.
This commit is contained in:
Glavin Wiechert 2015-05-03 12:22:24 -03:00
parent 65ef42fadb
commit 141bca7aba
2 changed files with 8 additions and 8 deletions

View File

@ -128,7 +128,7 @@ module.exports = class Beautifier
### ###
Run command-line interface command Run command-line interface command
### ###
run: (executable, args) -> run: (executable, args, {ignoreReturnCode} = {}) ->
# Resolve executable # Resolve executable
Promise.resolve(executable) Promise.resolve(executable)
.then((exe) => .then((exe) =>
@ -156,13 +156,13 @@ module.exports = class Beautifier
cmd.stdout.on('data', (data) -> stdout += data ) cmd.stdout.on('data', (data) -> stdout += data )
cmd.stderr.on('data', (data) -> stderr += data ) cmd.stderr.on('data', (data) -> stderr += data )
# when the spawn child process exits, check if there were any errors and close the writeable stream # when the spawn child process exits, check if there were any errors and close the writeable stream
cmd.on('exit', (code) -> cmd.on('exit', (returnCode) ->
# console.log('spawn done', code, stderr, stdout) console.log('spawn done', returnCode, stderr, stdout)
# If return code is not 0 then error occured # If return code is not 0 then error occured
# if code isnt 0 if not ignoreReturnCode and returnCode isnt 0
# reject(stderr) reject(stderr)
# else else
resolve(stdout) resolve(stdout)
) )
cmd.on('error', (err) -> cmd.on('error', (err) ->
# console.log('error', err) # console.log('error', err)

View File

@ -16,7 +16,7 @@ module.exports = class Rubocop extends Beautifier
@run("rubocop", [ @run("rubocop", [
"--auto-correct" "--auto-correct"
tempFile = @tempFile("temp", text) tempFile = @tempFile("temp", text)
]) ], {ignoreReturnCode: true})
.then(=> .then(=>
# console.log('rubocop', arguments, tempFile) # console.log('rubocop', arguments, tempFile)
@readFile(tempFile) @readFile(tempFile)