Moved main code into then() for actual promise resolution

This commit is contained in:
Brian Bugh 2017-10-07 21:26:34 -05:00
parent 2d595f2a20
commit 5f36431b1d
1 changed files with 31 additions and 31 deletions

View File

@ -33,35 +33,35 @@ module.exports = class Rubocop extends Beautifier
rubocopPath = paths.find((p) -> p and path.isAbsolute(p)) or "rubocop" rubocopPath = paths.find((p) -> p and path.isAbsolute(p)) or "rubocop"
@verbose('rubocopPath', rubocopPath) @verbose('rubocopPath', rubocopPath)
@debug('rubocopPath', rubocopPath, paths) @debug('rubocopPath', rubocopPath, paths)
)
# Find or generate a config file if non exists
# Find or generate a config file if non exists configFile = @findFile(path.dirname(fullPath), ".rubocop.yml")
configFile = @findFile(path.dirname(fullPath), ".rubocop.yml") if !configFile?
if !configFile? yaml = require("yaml-front-matter")
yaml = require("yaml-front-matter") config = {
config = { "Style/IndentationWidth":
"Style/IndentationWidth": "Width": options.indent_size
"Width": options.indent_size }
} tempConfig = @tempFile("rubocop-config", yaml.safeDump(config))
tempConfig = @tempFile("rubocop-config", yaml.safeDump(config))
rubocopArguments = [
rubocopArguments = [ "--auto-correct"
"--auto-correct" "--force-exclusion"
"--force-exclusion" "--stdin", relativePath || temp.path({suffix: '.rb'})
"--stdin", relativePath || temp.path({suffix: '.rb'}) ]
] rubocopArguments.push("--config", tempConfig) if tempConfig?
rubocopArguments.push("--config", tempConfig) if tempConfig? @debug("rubocop arguments", rubocopArguments)
@debug("rubocop arguments", rubocopArguments)
@run(rubocopPath, rubocopArguments, {
@run(rubocopPath, rubocopArguments, { ignoreReturnCode: true,
ignoreReturnCode: true, cwd: projectPath,
cwd: projectPath, onStdin: (stdin) -> stdin.end text
onStdin: (stdin) -> stdin.end text }).then((stdout) =>
}).then((stdout) => @debug("rubocop output", stdout)
@debug("rubocop output", stdout) # Rubocop output an error if stdout is empty
# Rubocop output an error if stdout is empty return text if stdout.length == 0
return text if stdout.length == 0
result = stdout.split("====================\n")
result = stdout.split("====================\n") result[result.length - 1]
result[result.length - 1] )
) )