From 32df741007c08b6f884aace639e45ebc4319b4dd Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Fri, 20 Nov 2015 09:24:53 +1000 Subject: [PATCH] fixed path retrieval --- src/beautifiers/rubocop.coffee | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/beautifiers/rubocop.coffee b/src/beautifiers/rubocop.coffee index 396eda6..83a3253 100644 --- a/src/beautifiers/rubocop.coffee +++ b/src/beautifiers/rubocop.coffee @@ -11,42 +11,42 @@ module.exports = class Rubocop extends Beautifier options: { Ruby: indent_size: true + rubocop_path: true } beautify: (text, language, options) -> - - fs = require 'fs' - - configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml") - - if fs.existsSync(configFile) - @debug("rubocop", config, fs.readFileSync(configFile, 'utf8')) - else - yaml = require("yaml-front-matter") - # Generate config file - config = { - "Style/IndentationWidth": - "Width": options.indent_size - } - - configFile = @tempFile("rubocop-config", yaml.safeDump(config)) - @debug("rubocop", config, configFile) - @Promise.all([ @which(options.rubocop_path) if options.rubocop_path @which('rubocop') ]).then((paths) => - @debug('php-cs-fixer paths', paths) + @debug('rubocop paths', paths) _ = require 'lodash' path = require 'path' # Get first valid, absolute path rubocopPath = _.find(paths, (p) -> p and path.isAbsolute(p) ) @verbose('rubocopPath', rubocopPath) @debug('rubocopPath', rubocopPath, paths) + + configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml") + + fs = require 'fs' + + if fs.existsSync(configFile) + @debug("rubocop", config, fs.readFileSync(configFile, 'utf8')) + else + yaml = require("yaml-front-matter") + # Generate config file + config = { + "Style/IndentationWidth": + "Width": options.indent_size + } + + configFile = @tempFile("rubocop-config", yaml.safeDump(config)) + @debug("rubocop", config, configFile) + # Check if PHP-CS-Fixer path was found if rubocopPath? - @run("rubocop", [ - rubocopPath + @run(rubocopPath, [ "--auto-correct" "--config", configFile tempFile = @tempFile("temp", text) @@ -63,3 +63,4 @@ module.exports = class Rubocop extends Beautifier .then(=> @readFile(tempFile) ) +)