Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Add elixir formatter. Fix Glavin001#545
Browse files Browse the repository at this point in the history
  • Loading branch information
kumekay committed Jun 20, 2017
1 parent f6a4990 commit 67b9267
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall
| elm-format | :x: | Go to https://github.com/avh4/elm-format and follow the instructions. |
| erl_tidy | :x: | Go to http://erlang.org/doc/man/erl_tidy.html and follow the instructions. |
| ESLint Fixer | :white_check_mark: | Nothing! |
| exfmt | :x: | Go to https://github.com/lpil/exfmt and follow the instructions. |
| formatR | :x: | Go to https://github.com/yihui/formatR and follow the instructions. |
| Fortran Beautifier | :x: | Go to https://www.gnu.org/software/emacs/ and follow the instructions. |
| Gherkin formatter | :white_check_mark: | Nothing! |
Expand Down Expand Up @@ -138,6 +139,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti
| Elm | `Elm` |`.elm` | [`elm-format`](https://github.com/avh4/elm-format) (Default) |
| ERB | `HTML (Ruby - ERB)`, `HTML (Rails)` |`.erb` | [`HTML Beautifier`](https://github.com/threedaymonk/htmlbeautifier), [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) |
| Erlang | `Erlang` |`.erl` | [`erl_tidy`](http://erlang.org/doc/man/erl_tidy.html) (Default) |
| Elixir | `Elixir` |`.ex`, `.exs` | [`exfmt`](https://github.com/lpil/exfmt) (Default) |
| Fortran | `Fortran - Modern` |`.f90`, `.F90`, `.f95`, `.F95` | [`Fortran Beautifier`](https://www.gnu.org/software/emacs/) (Default) |
| gherkin | `Gherkin` |`.feature` | [`Gherkin formatter`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/gherkin.coffee) (Default) |
| GLSL | `C`, `opencl`, `GLSL` |`.vert`, `.frag` | [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) (Default) |
Expand Down
69 changes: 69 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,75 @@ Automatically beautify Erlang files on save
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Beautify On Save*" and change it to your desired configuration.

#### [Elixir](#elixir)

**Supported Beautifiers**: [`exfmt`](#exfmt)

| Option | exfmt |
| --- | --- |
| `disabled` | :white_check_mark: |
| `default_beautifier` | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: |

**Description**:

Options for language Elixir

##### [Disable Beautifying Language](#disable-beautifying-language)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Disable Elixir 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 "*Disable Beautifying Language*" and change it to your desired configuration.

##### [Default Beautifier](#default-beautifier)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Default**: `exfmt`

**Type**: `string`

**Enum**: `exfmt`

**Description**:

Default Beautifier to be used for Elixir

**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 "*Default Beautifier*" and change it to your desired configuration.

##### [Beautify On Save](#beautify-on-save)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Automatically beautify Elixir 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 "*Beautify On Save*" and change it to your desired configuration.

#### [Fortran](#fortran)

**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier)
Expand Down
7 changes: 7 additions & 0 deletions examples/nested-jsbeautifyrc/elixir/expected/test.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule MyApp do
use SomeLib

def run(data) do
{:ok, data}
end
end
7 changes: 7 additions & 0 deletions examples/nested-jsbeautifyrc/elixir/original/test.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule MyApp, do: (
use( SomeLib )
def run( data ), do: {
:ok,
data
}
)
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@
"atom-beautify:beautify-language-visualforce",
"atom-beautify:beautify-language-xml",
"atom-beautify:beautify-language-xtemplate",
"atom-beautify:beautify-language-yaml"
"atom-beautify:beautify-language-yaml",
"atom-beautify:beautify-language-elixir"
],
".tree-view .file .name": [
"atom-beautify:beautify-file"
Expand Down Expand Up @@ -394,7 +395,9 @@
"nginx",
"nginx beautify",
"golang template",
"align-yaml"
"align-yaml",
"elixir",
"exfmt"
],
"devDependencies": {
"coffeelint": "^1.10.1",
Expand All @@ -407,4 +410,4 @@
"lint": "coffeelint src/ spec/",
"code-docs": "codo && open docs/code/index.html"
}
}
}
21 changes: 21 additions & 0 deletions src/beautifiers/exfmt.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
###
Requires https://github.com/lpil/exfmt
###
"use strict"
Beautifier = require('./beautifier')

module.exports = class Exfmt extends Beautifier
name: "exfmt"
link: "https://github.com/lpil/exfmt"
isPreInstalled: false

options: {
Elixir: true
}

beautify: (text, language, options) ->
@run("mix", [
'exfmt',
@tempFile("input", text, ".ex")
]
)
1 change: 1 addition & 0 deletions src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = class Beautifiers extends EventEmitter
'crystal'
'dfmt'
'elm-format'
'exfmt'
'hh_format'
'htmlbeautifier'
'csscomb'
Expand Down
26 changes: 26 additions & 0 deletions src/languages/elixir.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {

name: "Elixir"
namespace: "ex"

###
Supported Grammars
###
grammars: [
"Elixir"
]

###
Supported extensions
###
extensions: [
"ex",
"exs"
]

defaultBeautifier: "exfmt"

###
###
options: []
}
1 change: 1 addition & 0 deletions src/languages/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = class Languages
"csv"
"d"
"ejs"
"elixir"
"elm"
"erb"
"erlang"
Expand Down
42 changes: 42 additions & 0 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,48 @@
}
}
},
"ex": {
"title": "Elixir",
"type": "object",
"description": "Options for language Elixir",
"collapsed": true,
"beautifiers": [
"exfmt"
],
"grammars": [
"Elixir"
],
"extensions": [
"ex",
"exs"
],
"properties": {
"disabled": {
"title": "Disable Beautifying Language",
"order": -3,
"type": "boolean",
"default": false,
"description": "Disable Elixir Beautification"
},
"default_beautifier": {
"title": "Default Beautifier",
"order": -2,
"type": "string",
"default": "exfmt",
"description": "Default Beautifier to be used for Elixir",
"enum": [
"exfmt"
]
},
"beautify_on_save": {
"title": "Beautify On Save",
"order": -1,
"type": "boolean",
"default": false,
"description": "Automatically beautify Elixir files on save"
}
}
},
"elm": {
"title": "Elm",
"type": "object",
Expand Down

0 comments on commit 67b9267

Please sign in to comment.