From e138cd4dcd517e89758423c121550a8d227cb3c7 Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Thu, 19 Nov 2015 17:45:07 +1000 Subject: [PATCH] add option to specify path for rubocop and usage in relative beautifier --- src/beautifiers/rubocop.coffee | 40 ++++++++++++++++++++++++++-------- src/languages/ruby.coffee | 5 +++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/beautifiers/rubocop.coffee b/src/beautifiers/rubocop.coffee index d76568c..396eda6 100644 --- a/src/beautifiers/rubocop.coffee +++ b/src/beautifiers/rubocop.coffee @@ -15,7 +15,6 @@ module.exports = class Rubocop extends Beautifier beautify: (text, language, options) -> - path = require 'path' fs = require 'fs' configFile = path.join(atom.project.getPaths()[0], ".rubocop.yml") @@ -33,11 +32,34 @@ module.exports = class Rubocop extends Beautifier configFile = @tempFile("rubocop-config", yaml.safeDump(config)) @debug("rubocop", config, configFile) - @run("rubocop", [ - "--auto-correct" - "--config", configFile - tempFile = @tempFile("temp", text) - ], {ignoreReturnCode: true}) - .then(=> - @readFile(tempFile) - ) + @Promise.all([ + @which(options.rubocop_path) if options.rubocop_path + @which('rubocop') + ]).then((paths) => + @debug('php-cs-fixer 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) + # Check if PHP-CS-Fixer path was found + if rubocopPath? + @run("rubocop", [ + rubocopPath + "--auto-correct" + "--config", configFile + tempFile = @tempFile("temp", text) + ], {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) + ) + else + @run("rubocop", [ + "--auto-correct" + "--config", configFile + tempFile = @tempFile("temp", text) + ], {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) + ) diff --git a/src/languages/ruby.coffee b/src/languages/ruby.coffee index 9eb866c..5530d40 100644 --- a/src/languages/ruby.coffee +++ b/src/languages/ruby.coffee @@ -32,6 +32,11 @@ module.exports = { default: defaultIndentSize minimum: 0 description: "Indentation size/length" + rubocop_path: + title: "Rubocop Path" + type: 'string' + default: "" + description: "Path to the `rubocop` CLI executable" indent_char: type: 'string' default: defaultIndentChar