From 31695b33c916e224a4c9939a9bd347b46924ce9a Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 06:42:08 -0700 Subject: [PATCH 1/9] Add support for Elm --- .travis.yml | 3 +++ README.md | 2 ++ .../nested-jsbeautifyrc/elm/expected/test.elm | 9 ++++++++ .../nested-jsbeautifyrc/elm/original/test.elm | 3 +++ src/beautifiers/elm-format.coffee | 18 +++++++++++++++ src/beautifiers/index.coffee | 1 + src/languages/elm.coffee | 22 +++++++++++++++++++ src/languages/index.coffee | 1 + test.elm | 9 ++++++++ 9 files changed, 68 insertions(+) create mode 100644 examples/nested-jsbeautifyrc/elm/expected/test.elm create mode 100644 examples/nested-jsbeautifyrc/elm/original/test.elm create mode 100644 src/beautifiers/elm-format.coffee create mode 100644 src/languages/elm.coffee create mode 100644 test.elm diff --git a/.travis.yml b/.travis.yml index 578e41c30..dde1a070c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,3 +59,6 @@ before_install: - brew install haskell-stack - stack setup - stack install stylish-haskell + # Elm + - curl -L -o /tmp/elm-format.tgz + - tar xvzf -C /usr/local/bin /tmp/elm-format.tgz diff --git a/README.md b/README.md index 3ed654d8b..472ff6abd 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify` - [x] [TypeScript](https://github.com/Glavin001/atom-beautify/issues/49) - [x] [Haskell](https://github.com/Glavin001/atom-beautify/issues/628) - Requires [stylish-haskell](https://github.com/jaspervdj/stylish-haskell) +- [x] [Elm]() + - Requires [Elm-Format](https://github.com/avh4/elm-format) ## Usage diff --git a/examples/nested-jsbeautifyrc/elm/expected/test.elm b/examples/nested-jsbeautifyrc/elm/expected/test.elm new file mode 100644 index 000000000..b28a16c47 --- /dev/null +++ b/examples/nested-jsbeautifyrc/elm/expected/test.elm @@ -0,0 +1,9 @@ +module Main (..) where + + +addThings x y = + x + y + + +main = + addThings 4 5 diff --git a/examples/nested-jsbeautifyrc/elm/original/test.elm b/examples/nested-jsbeautifyrc/elm/original/test.elm new file mode 100644 index 000000000..40128fd94 --- /dev/null +++ b/examples/nested-jsbeautifyrc/elm/original/test.elm @@ -0,0 +1,3 @@ +addThings x y = x + y + +main = addThings 4 5 diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee new file mode 100644 index 000000000..fb8e60b11 --- /dev/null +++ b/src/beautifiers/elm-format.coffee @@ -0,0 +1,18 @@ +### +Requires https://github.com/avh4/elm-format +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class ElmFormat extends Beautifier + name: "elm-format" + + options: { + Elm: true + } + + beautify: (text, language, options) -> + @run("elm-format", [ + @tempFile("input", text) + ]) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 143fef3a5..6569f748b 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -38,6 +38,7 @@ module.exports = class Beautifiers extends EventEmitter 'coffee-formatter' 'coffee-fmt' 'clang-format' + 'elm-format' 'htmlbeautifier' 'csscomb' 'gherkin' diff --git a/src/languages/elm.coffee b/src/languages/elm.coffee new file mode 100644 index 000000000..0631898c7 --- /dev/null +++ b/src/languages/elm.coffee @@ -0,0 +1,22 @@ +module.exports = { + + name: "Elm" + namespace: "elm" + + ### + Supported Grammars + ### + grammars: [ + "Elm" + ] + + ### + Supported extensions + ### + extensions: [ + "elm" + ] + + options: [] + +} diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 5cbd7096a..895b5b243 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -21,6 +21,7 @@ module.exports = class Languages "csv" "d" "ejs" + "elm" "erb" "gherkin" "go" diff --git a/test.elm b/test.elm new file mode 100644 index 000000000..c92e50527 --- /dev/null +++ b/test.elm @@ -0,0 +1,9 @@ +module Main (..) where + + +addThings x y = + Signal.map (x + y) + + +main = + addThings 4 5 From 64e2fe3ec3fd7c1d0089fd53549b98b5c94c8ea9 Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 06:45:39 -0700 Subject: [PATCH 2/9] Update PR link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 472ff6abd..edbcabb4e 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify` - [x] [TypeScript](https://github.com/Glavin001/atom-beautify/issues/49) - [x] [Haskell](https://github.com/Glavin001/atom-beautify/issues/628) - Requires [stylish-haskell](https://github.com/jaspervdj/stylish-haskell) -- [x] [Elm]() +- [x] [Elm](https://github.com/Glavin001/atom-beautify/pull/700) - Requires [Elm-Format](https://github.com/avh4/elm-format) ## Usage From 9572c8d1d80df4065026a8bc627841c035d8d80f Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 06:52:52 -0700 Subject: [PATCH 3/9] Update changelog and package.json --- CHANGELOG.md | 1 + package.json | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbe3e5a0b..77f4918d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # dev +- Add [elm-format](https://github.com/avh4/elm-format) beautifier for the Elm language. - Add [clang-format](http://clang.llvm.org/docs/ClangFormat.html) beautifier for C/C++/Obj-C languages. - Add [yapf](http://github.com/google/yapf) beautifier for Python. diff --git a/package.json b/package.json index db82a524f..e4393e947 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,10 @@ { "name": "Daniel Bayley", "url": "https://github.com/danielbayley" + }, + { + "name": "Murphy Randle", + "url": "https://github.com/splodingsocks" } ], "engines": { From 92fde28461298b355e31bbc33f7bec0ef16290ef Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 09:00:38 -0700 Subject: [PATCH 4/9] Modify appveyor.yml and add the elm tag to package.json --- appveyor.yml | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 503bad880..58081532a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -115,7 +115,7 @@ build_script: - cd %APPVEYOR_BUILD_FOLDER% # Install languages to Atom - - apm install language-marko language-html-swig language-svg + - apm install language-marko language-html-swig language-svg language-elm # Show current PATH - echo %PATH% # Run tests on package diff --git a/package.json b/package.json index e4393e947..fe090442e 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,8 @@ "marko", "go", "golang", - "svg" + "svg", + "elm" ], "devDependencies": { "coffee-script": "^1.9.3", From 2dcaba4f47d26abb0a0b193b33098fad51796065 Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 09:01:09 -0700 Subject: [PATCH 5/9] Change the beautifier to conform to the expectations of elm-format --- src/beautifiers/elm-format.coffee | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index fb8e60b11..327c5bd8f 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -1,9 +1,12 @@ ### Requires https://github.com/avh4/elm-format ### - "use strict" Beautifier = require('./beautifier') +Promise = require("bluebird") +fs = require("fs") +readFile = Promise.promisify(fs.readFile) +rename = Promise.promisify(fs.rename) module.exports = class ElmFormat extends Beautifier name: "elm-format" @@ -13,6 +16,14 @@ module.exports = class ElmFormat extends Beautifier } beautify: (text, language, options) -> - @run("elm-format", [ - @tempFile("input", text) - ]) + tempfile = @tempFile("input", text) + .then (name) => + newName = name + ".elm" + rename name, newName + .then () => + @run("elm-format", [ + '--yes', + newName + ]) + .then () => + readFile newName, {encoding: 'utf-8'} From 1d59cc0970f25d187de31fc24df1c9dfe8655fc9 Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 17:49:07 -0700 Subject: [PATCH 6/9] Whoops, forgot the URL for the executable on Travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dde1a070c..eb8823530 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,5 +60,5 @@ before_install: - stack setup - stack install stylish-haskell # Elm - - curl -L -o /tmp/elm-format.tgz + - curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.1-alpha2/elm-format-0.1-alpha2-mac-x64.tgz - tar xvzf -C /usr/local/bin /tmp/elm-format.tgz From 7ccdff04e7415c38c194d58e093aafed10e2e698 Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 17:51:40 -0700 Subject: [PATCH 7/9] Fix the tar command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eb8823530..10546e8a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,4 +61,4 @@ before_install: - stack install stylish-haskell # Elm - curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.1-alpha2/elm-format-0.1-alpha2-mac-x64.tgz - - tar xvzf -C /usr/local/bin /tmp/elm-format.tgz + - tar xvzf /tmp/elm-format.tgz -C /usr/local/bin From 1c20df5da62cb2668fffe3b877bca18f71e0f8fa Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 18:48:55 -0700 Subject: [PATCH 8/9] Clean up lint error! --- src/beautifiers/elm-format.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index 327c5bd8f..7216a2bbd 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -25,5 +25,5 @@ module.exports = class ElmFormat extends Beautifier '--yes', newName ]) - .then () => + .then () -> readFile newName, {encoding: 'utf-8'} From b85a2a9be769ff3b3d5356bb8ee5b68e2e561b14 Mon Sep 17 00:00:00 2001 From: Murphy Randle Date: Thu, 10 Dec 2015 20:04:11 -0700 Subject: [PATCH 9/9] Cleanup, address comments, and docs --- docs/options.md | 55 +++++++++++++++++++++++++++++++ src/beautifiers/beautifier.coffee | 4 +-- src/beautifiers/elm-format.coffee | 21 +++++------- test.elm | 9 ----- 4 files changed, 65 insertions(+), 24 deletions(-) delete mode 100644 test.elm diff --git a/docs/options.md b/docs/options.md index 295175fa0..308f987df 100644 --- a/docs/options.md +++ b/docs/options.md @@ -2467,6 +2467,61 @@ Automatically beautify EJS files on save 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Language Config - EJS - Beautify On Save*" and change it to your desired configuration. +#### [Language Config - Elm - Disable Beautifying Language](#language-config---elm---disable-beautifying-language) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Disable Elm Beautification + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Language Config - Elm - Disable Beautifying Language*" and change it to your desired configuration. + +#### [Language Config - Elm - Default Beautifier](#language-config---elm---default-beautifier) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Default**: `elm-format` + +**Type**: `string` + +**Enum**: `elm-format` + +**Description**: + +Default Beautifier to be used for Elm + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Language Config - Elm - Default Beautifier*" and change it to your desired configuration. + +#### [Language Config - Elm - Beautify On Save](#language-config---elm---beautify-on-save) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Automatically beautify Elm files on save + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Language Config - Elm - Beautify On Save*" and change it to your desired configuration. + #### [Language Config - ERB - Disable Beautifying Language](#language-config---erb---disable-beautifying-language) **Important**: This option is only configurable from within Atom Beautify's setting panel. diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index 355e08e7f..78e825605 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -54,10 +54,10 @@ module.exports = class Beautifier ### Create temporary file ### - tempFile: (name = "atom-beautify-temp", contents = "") -> + tempFile: (name = "atom-beautify-temp", contents = "", ext = "") -> return new Promise((resolve, reject) => # create temp file - temp.open(name, (err, info) => + temp.open({prefix: name, suffix: ext}, (err, info) => @debug('tempFile', name, err, info) return reject(err) if err fs.write(info.fd, contents, (err) -> diff --git a/src/beautifiers/elm-format.coffee b/src/beautifiers/elm-format.coffee index 7216a2bbd..27151d007 100644 --- a/src/beautifiers/elm-format.coffee +++ b/src/beautifiers/elm-format.coffee @@ -3,10 +3,6 @@ Requires https://github.com/avh4/elm-format ### "use strict" Beautifier = require('./beautifier') -Promise = require("bluebird") -fs = require("fs") -readFile = Promise.promisify(fs.readFile) -rename = Promise.promisify(fs.rename) module.exports = class ElmFormat extends Beautifier name: "elm-format" @@ -16,14 +12,13 @@ module.exports = class ElmFormat extends Beautifier } beautify: (text, language, options) -> - tempfile = @tempFile("input", text) + tempfile = @tempFile("input", text, ".elm") .then (name) => - newName = name + ".elm" - rename name, newName + @run("elm-format", [ + '--yes', + name + ], + { help: { link: 'https://github.com/avh4/elm-format' } } + ) .then () => - @run("elm-format", [ - '--yes', - newName - ]) - .then () -> - readFile newName, {encoding: 'utf-8'} + @readFile(name) diff --git a/test.elm b/test.elm deleted file mode 100644 index c92e50527..000000000 --- a/test.elm +++ /dev/null @@ -1,9 +0,0 @@ -module Main (..) where - - -addThings x y = - Signal.map (x + y) - - -main = - addThings 4 5