From e138cd4dcd517e89758423c121550a8d227cb3c7 Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Thu, 19 Nov 2015 17:45:07 +1000 Subject: [PATCH 1/6] 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 From ea83bd88f26c96cb3c7df1337002a7853c756b6f Mon Sep 17 00:00:00 2001 From: Patrick O'Melveny Date: Thu, 19 Nov 2015 00:00:29 -0800 Subject: [PATCH 2/6] Set ignoreResponseCode to true in yapf.coffee --- src/beautifiers/yapf.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/beautifiers/yapf.coffee b/src/beautifiers/yapf.coffee index 4fd8ecc..05c3877 100644 --- a/src/beautifiers/yapf.coffee +++ b/src/beautifiers/yapf.coffee @@ -17,6 +17,9 @@ module.exports = class Yapf extends Beautifier @run("yapf", [ ["--style=pep8"] @tempFile("input", text) - ], help: { - link: "https://github.com/google/yapf" + ], { + ignoreReturnCode: true, + help: { + link: "https://github.com/google/yapf" + } }) From 2ea86c30913d2bc884471dd3fb548d9cb19f4331 Mon Sep 17 00:00:00 2001 From: Patrick O'Melveny Date: Thu, 19 Nov 2015 10:46:39 -0800 Subject: [PATCH 3/6] Changed indents to 2 spaces for package consistancy --- src/beautifiers/yapf.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/beautifiers/yapf.coffee b/src/beautifiers/yapf.coffee index 05c3877..6242c00 100644 --- a/src/beautifiers/yapf.coffee +++ b/src/beautifiers/yapf.coffee @@ -18,8 +18,8 @@ module.exports = class Yapf extends Beautifier ["--style=pep8"] @tempFile("input", text) ], { - ignoreReturnCode: true, - help: { - link: "https://github.com/google/yapf" - } + ignoreReturnCode: true, + help: { + link: "https://github.com/google/yapf" + } }) From 32df741007c08b6f884aace639e45ebc4319b4dd Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Fri, 20 Nov 2015 09:24:53 +1000 Subject: [PATCH 4/6] 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) ) +) From 0915043fbdad20fc1e486981835c117ce7847cfd Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Mon, 23 Nov 2015 11:52:10 +1000 Subject: [PATCH 5/6] fixed coffescript parsing error switching to double quotes --- src/beautifiers/beautifier.coffee | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 2dfaa02..355e08e 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -20,27 +20,27 @@ module.exports = class Beautifier ### Supported Options - + Enable options for supported languages. - : - :: - :: - :: - :: - + ### options: {} ### Supported languages by this Beautifier - + Extracted from the keys of the `options` field. ### languages: null ### Beautify text - + Override this method in subclasses ### beautify: null @@ -87,7 +87,7 @@ module.exports = class Beautifier ### Get Shell Environment variables - + Special thank you to @ioquatix See https://github.com/ioquatix/script-runner/blob/v1.5.0/lib/script-runner.coffee#L45-L63 ### @@ -139,7 +139,7 @@ module.exports = class Beautifier ### Like the unix which utility. - + Finds the first instance of a specified executable in the PATH environment variable. Does not cache the results, so hash -r is not needed when the PATH changes. @@ -165,7 +165,7 @@ module.exports = class Beautifier ### Add help to error.description - + Note: error.description is not officially used in JavaScript, however it is used internally for Atom Beautify when displaying errors. ### @@ -256,8 +256,8 @@ module.exports = class Beautifier # If return code is not 0 then error occured if not ignoreReturnCode and returnCode isnt 0 err = new Error(stderr) - windowsProgramNotFoundMsg = 'is not recognized as an \ - internal or external command'#, operable program or batch file.' + windowsProgramNotFoundMsg = "is not recognized as an \ + internal or external command" # operable program or batch file @verbose(stderr, windowsProgramNotFoundMsg) if @isWindows and returnCode is 1 and \ stderr.indexOf(windowsProgramNotFoundMsg) isnt -1 @@ -346,5 +346,3 @@ module.exports = class Beautifier @verbose("Options for #{@name}:", @options) # Set supported languages @languages = _.keys(@options) - - From 02fc882ccce581f87e2ffdcc2736fccb0217814e Mon Sep 17 00:00:00 2001 From: Emanuele Tonello Date: Mon, 23 Nov 2015 11:52:31 +1000 Subject: [PATCH 6/6] added docs for new rubocop option --- docs/options.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docs/options.md b/docs/options.md index a20bc67..649b8a0 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1766,6 +1766,30 @@ Indentation size/length (Supported by Rubocop, Ruby Beautify) } ``` +#### [Ruby - Rubocop Path](#ruby---rubocop-path) + +**Namespace**: `ruby` + +**Key**: `rubocop_path` + +**Type**: `string` + +**Supported Beautifiers**: [`Rubocop`](#rubocop) + +**Description**: + +Path to the `rubocop` CLI executable (Supported by Rubocop) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "ruby": { + "rubocop_path": "" + } +} +``` + #### [Ruby - Indent char](#ruby---indent-char) **Namespace**: `ruby` @@ -6447,6 +6471,30 @@ Indentation size/length (Supported by Rubocop, Ruby Beautify) } ``` +#### [Ruby - Rubocop Path](#ruby---rubocop-path) + +**Namespace**: `ruby` + +**Key**: `rubocop_path` + +**Type**: `string` + +**Supported Beautifiers**: [`Rubocop`](#rubocop) + +**Description**: + +Path to the `rubocop` CLI executable (Supported by Rubocop) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "ruby": { + "rubocop_path": "" + } +} +``` + ### Ruby Beautify