diff --git a/examples/simple-jsbeautifyrc/coffeescript/expected/operators.coffee b/examples/simple-jsbeautifyrc/coffeescript/expected/operators.coffee index 8cb7b8d..874e4e6 100644 --- a/examples/simple-jsbeautifyrc/coffeescript/expected/operators.coffee +++ b/examples/simple-jsbeautifyrc/coffeescript/expected/operators.coffee @@ -1,2 +1,2 @@ value %%= 4000 -value != true \ No newline at end of file +value isnt true diff --git a/examples/simple-jsbeautifyrc/coffeescript/expected/test.coffee b/examples/simple-jsbeautifyrc/coffeescript/expected/test.coffee index 0ba8e2c..9bd9a73 100644 --- a/examples/simple-jsbeautifyrc/coffeescript/expected/test.coffee +++ b/examples/simple-jsbeautifyrc/coffeescript/expected/test.coffee @@ -1,10 +1,8 @@ hello derek how is it going? for c, i in "Hello World!" k = 1 + 1 - 2 >= 3 <= 4 > 5 < 6 - for c, i in "Hello World" - k = (a, b) -> if b? return a - + k = (a, b) -> if b? then return a f = b()[0] for c, i in "Hello World" f(b()) diff --git a/examples/simple-jsbeautifyrc/coffeescript/original/test.coffee b/examples/simple-jsbeautifyrc/coffeescript/original/test.coffee index 680f1b2..e135635 100644 --- a/examples/simple-jsbeautifyrc/coffeescript/original/test.coffee +++ b/examples/simple-jsbeautifyrc/coffeescript/original/test.coffee @@ -3,7 +3,7 @@ for c, i in "Hello World!" k = 1+1- 2>=3<= 4>5 <6 for c, i in "Hello World" - k = (a,b)-> if b? return a + k = (a,b)-> if b? then return a f = b()[0] for c, i in "Hello World" diff --git a/package.json b/package.json index 062144d..f1ff27d 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "atom-message-panel": "^1.1.1", "atom-space-pen-views": "^2.0.3", "bluebird": "^2.9.25", + "coffee-fmt": "^0.7.0", "coffee-formatter": "^0.1.2", "csscomb": "^3.0.4", "diff": "^1.3.2", diff --git a/src/beautifiers/coffee-fmt.coffee b/src/beautifiers/coffee-fmt.coffee new file mode 100644 index 0000000..3fbc0e4 --- /dev/null +++ b/src/beautifiers/coffee-fmt.coffee @@ -0,0 +1,26 @@ +"use strict" +Beautifier = require('./beautifier') + +module.exports = class PrettyDiff extends Beautifier + name: "coffee-fmt" + + options: { + # Apply language-specific options + CoffeeScript: + tab: ["indent_size", "indent_char", "indent_with_tabs", (indentSize, indentChar, indentWithTabs) -> + return "\t" if indentWithTabs + Array(indentSize+1).join(indentChar) + ] + } + + beautify: (text, language, options) -> + return new @Promise((resolve, reject) -> + # Add newLine option + options.newLine = "\n" + # Require + fmt = require('coffee-fmt') + # Format! + results = fmt.format(text, options) + # Return beautified CoffeeScript code + resolve(results) + ) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index f67bff9..a5313f2 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -34,6 +34,7 @@ module.exports = class Beautifiers 'uncrustify' 'autopep8' 'coffee-formatter' + 'coffee-fmt' 'htmlbeautifier' 'csscomb' 'gofmt' diff --git a/src/beautifiers/prettydiff.coffee b/src/beautifiers/prettydiff.coffee index eb0978f..266502f 100644 --- a/src/beautifiers/prettydiff.coffee +++ b/src/beautifiers/prettydiff.coffee @@ -1,7 +1,5 @@ "use strict" -prettydiff = require("prettydiff") Beautifier = require('./beautifier') -_ = require('lodash') module.exports = class PrettyDiff extends Beautifier name: "Pretty Diff" @@ -36,6 +34,8 @@ module.exports = class PrettyDiff extends Beautifier beautify: (text, language, options) -> return new @Promise((resolve, reject) -> + prettydiff = require("prettydiff") + _ = require('lodash') # Select Prettydiff language lang = "auto" diff --git a/src/languages/coffeescript.coffee b/src/languages/coffeescript.coffee index 7abdf9d..f166430 100644 --- a/src/languages/coffeescript.coffee +++ b/src/languages/coffeescript.coffee @@ -18,4 +18,6 @@ module.exports = { "coffee" ] + defaultBeautifier: "coffee-fmt" + } \ No newline at end of file