From 198f0770dd1504a3c0da3eabfd43350535a43dde Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Wed, 10 Jun 2015 13:10:16 -0300 Subject: [PATCH] Closes #341. Add indent_size option to Rubocop beautifier --- examples/nested-jsbeautifyrc/.jsbeautifyrc | 2 ++ src/beautifiers/rubocop.coffee | 19 ++++++++++++++++++- src/beautifiers/ruby-beautify.coffee | 2 +- src/languages/ruby.coffee | 14 +++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/examples/nested-jsbeautifyrc/.jsbeautifyrc b/examples/nested-jsbeautifyrc/.jsbeautifyrc index 73c4142..feb1813 100644 --- a/examples/nested-jsbeautifyrc/.jsbeautifyrc +++ b/examples/nested-jsbeautifyrc/.jsbeautifyrc @@ -40,3 +40,5 @@ indent_class: true indent_with_tabs: 0 indent_size: 1 + ruby: + indent_size: 4 \ No newline at end of file diff --git a/src/beautifiers/rubocop.coffee b/src/beautifiers/rubocop.coffee index ec42a9f..ba20a7e 100644 --- a/src/beautifiers/rubocop.coffee +++ b/src/beautifiers/rubocop.coffee @@ -9,15 +9,32 @@ module.exports = class Rubocop extends Beautifier name: "Rubocop" options: { - Ruby: true + Ruby: + indent_size: true } beautify: (text, language, options) -> + + # Generate config file + yaml = require("yaml-front-matter") + + config = { + "Style/IndentationWidth": + "Width": options.indent_size + } + configStr = yaml.safeDump(config) + console.log("rubocop", config, configStr) + @run("rubocop", [ "--auto-correct" + "--config", @tempFile("rubocop-config", configStr) tempFile = @tempFile("temp", text) ], {ignoreReturnCode: true}) .then(=> # console.log('rubocop', arguments, tempFile) @readFile(tempFile) + .then((text) -> + console.log('rubocop', text) + return text + ) ) diff --git a/src/beautifiers/ruby-beautify.coffee b/src/beautifiers/ruby-beautify.coffee index b38b0f0..d42e472 100644 --- a/src/beautifiers/ruby-beautify.coffee +++ b/src/beautifiers/ruby-beautify.coffee @@ -9,7 +9,7 @@ module.exports = class RubyBeautify extends Beautifier name: "Ruby Beautify" options: { - Ruby: true + Ruby: false } beautify: (text, language, options) -> diff --git a/src/languages/ruby.coffee b/src/languages/ruby.coffee index 13f3f1c..9075b3d 100644 --- a/src/languages/ruby.coffee +++ b/src/languages/ruby.coffee @@ -1,3 +1,10 @@ +# Get Atom defaults +tabLength = atom?.config.get('editor.tabLength') ? 4 +softTabs = atom?.config.get('editor.softTabs') ? true +defaultIndentSize = (if softTabs then tabLength else 1) +defaultIndentChar = (if softTabs then " " else "\t") +defaultIndentWithTabs = not softTabs + module.exports = { name: "Ruby" @@ -18,6 +25,11 @@ module.exports = { "rb" ] - options: [] + options: + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" } \ No newline at end of file