diff --git a/CHANGELOG.md b/CHANGELOG.md index a674ec3..67ed656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Next +- Add GN language and beautifier - ... # v0.30.9 (2017-11-22) diff --git a/README.md b/README.md index 601c4b1..0b33fde 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall | formatR | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):
1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) with `docker pull unibeautify/rscript`

:bookmark_tabs: Manually:
1. Install [Rscript (`rscript`)](https://github.com/yihui/formatR) by following https://github.com/yihui/formatR
| | Fortran Beautifier | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:
1. Install [Emacs (`emacs`)](https://www.gnu.org/software/emacs/) by following https://www.gnu.org/software/emacs/
| | Gherkin formatter | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | +| GN | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:
1. Install [gn (`gn`)](https://chromium.googlesource.com/chromium/src/tools/gn) by following https://www.chromium.org/developers/how-tos/get-the-code
| | gofmt | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to https://golang.org/cmd/gofmt/ and follow the instructions. | | goimports | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):
1. Install [goimports (`goimports`)](https://godoc.org/golang.org/x/tools/cmd/goimports) with `docker pull unibeautify/goimports`

:bookmark_tabs: Manually:
1. Install [goimports (`goimports`)](https://godoc.org/golang.org/x/tools/cmd/goimports) by following https://godoc.org/golang.org/x/tools/cmd/goimports
| | hh_format | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to http://hhvm.com/ and follow the instructions. | @@ -159,6 +160,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti | Fortran | `Fortran - Modern` |`.f90`, `.F90`, `.f95`, `.F95`, `.f03`, `.F03`, `.f08`, `.F08` | **[`Fortran Beautifier`](https://www.gnu.org/software/emacs/)** | | gherkin | `Gherkin` |`.feature` | **[`Gherkin formatter`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/gherkin.coffee)** | | GLSL | `C`, `opencl`, `GLSL` |`.vert`, `.frag` | **[`clang-format`](https://clang.llvm.org/docs/ClangFormat.html)** | +| GN | `gn` |`.gn`, `.gni` | **[`GN`](https://chromium.googlesource.com/chromium/src/tools/gn)** | | Go | `Go` |`.go` | **[`gofmt`](https://golang.org/cmd/gofmt/)**, [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports) | | Golang Template | `HTML (Go)`, `Go Template` |`.gohtml` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** | | Handlebars | `Handlebars`, `HTML (Handlebars)` |`.hbs`, `.handlebars` | **[`JS Beautify`](https://github.com/beautify-web/js-beautify)**, [`Pretty Diff`](https://github.com/prettydiff/prettydiff) | diff --git a/docs/options.md b/docs/options.md index 7f3311d..93e44ae 100644 --- a/docs/options.md +++ b/docs/options.md @@ -249,6 +249,23 @@ Options for Emacs executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Emacs*" and change it to your desired configuration. +##### [gn](#gn) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for gn executable. + +**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 "*gn*" and change it to your desired configuration. + ##### [goimports](#goimports) **Important**: This option is only configurable from within Atom Beautify's setting panel. @@ -3952,6 +3969,75 @@ Path to clang-format config file. i.e. clang-format.cfg (Supported by clang-form } ``` +#### [GN](#gn) + +**Supported Beautifiers**: [`GN`](#gn) + +| Option | GN | +| --- | --- | +| `disabled` | :white_check_mark: | +| `default_beautifier` | :white_check_mark: | +| `beautify_on_save` | :white_check_mark: | + +**Description**: + +Options for language GN + +##### [Disable Beautifying Language](#disable-beautifying-language) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Disable GN 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**: `GN` + +**Type**: `string` + +**Enum**: `GN` + +**Description**: + +Default Beautifier to be used for GN + +**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 GN 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. + #### [Go](#go) **Supported Beautifiers**: [`gofmt`](#gofmt) [`goimports`](#goimports) diff --git a/examples/nested-jsbeautifyrc/gn/expected/test.gn b/examples/nested-jsbeautifyrc/gn/expected/test.gn new file mode 100644 index 0000000..46d9ff9 --- /dev/null +++ b/examples/nested-jsbeautifyrc/gn/expected/test.gn @@ -0,0 +1,19 @@ +shared_library("test") { + # NOSORT + sources = [ + "z.cc", + "a.cc", + ] + + deps = [ + "//abc:deps", + ] + include_dirs = [ "." ] + + if (is_win) { + sources += [ + "a.cpp", + "b.cpp", + ] + } +} diff --git a/examples/nested-jsbeautifyrc/gn/original/test.gn b/examples/nested-jsbeautifyrc/gn/original/test.gn new file mode 100644 index 0000000..ffc6003 --- /dev/null +++ b/examples/nested-jsbeautifyrc/gn/original/test.gn @@ -0,0 +1,18 @@ +shared_library("test") { + +# NOSORT +sources = [ + "z.cc", + "a.cc", +] + + +deps=["//abc:deps"] + include_dirs = [ + ".", + ] + + if (is_win) { + sources += ["b.cpp","a.cpp"] + } +} diff --git a/package.json b/package.json index 8898cdd..74aa74f 100644 --- a/package.json +++ b/package.json @@ -277,7 +277,8 @@ "atom-beautify:beautify-language-xml", "atom-beautify:beautify-language-xtemplate", "atom-beautify:beautify-language-yaml", - "atom-beautify:beautify-language-terraform" + "atom-beautify:beautify-language-terraform", + "atom-beautify:beautify-language-gn" ], ".tree-view .file .name": [ "atom-beautify:beautify-file" @@ -412,7 +413,8 @@ "align-yaml", "goimports", "terraform", - "terraformfmt" + "terraformfmt", + "gn" ], "devDependencies": { "coffeelint": "1.16.0" @@ -449,4 +451,4 @@ "prettydiff2" ] } -} +} \ No newline at end of file diff --git a/src/beautifiers/gn.coffee b/src/beautifiers/gn.coffee new file mode 100644 index 0000000..ce306c6 --- /dev/null +++ b/src/beautifiers/gn.coffee @@ -0,0 +1,34 @@ +### +Requires [gn](https://chromium.googlesource.com/chromium/src/tools/gn) +### +"use strict" +Beautifier = require('./beautifier') +path = require('path') +semver = require('semver') + +module.exports = class GN extends Beautifier + name: "GN" + link: "https://chromium.googlesource.com/chromium/src/tools/gn" + executables: [ + { + name: "gn" + cmd: "gn" + homepage: "https://chromium.googlesource.com/chromium/src/tools/gn" + installation: "https://www.chromium.org/developers/how-tos/get-the-code" + version: { + parse: (text) -> semver.clean("0.0." + text) + } + } + ] + + options: { + GN: false + } + + beautify: (text, language, options, context) -> + cwd = context.filePath and path.dirname context.filePath + @exe("gn").run(["format", "--stdin"], { + cwd: cwd + onStdin: (stdin) -> + stdin.end text + }) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index cc3f237..12dfccc 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -48,6 +48,7 @@ module.exports = class Beautifiers extends EventEmitter 'htmlbeautifier' 'csscomb' 'gherkin' + 'gn' 'gofmt' 'goimports' 'latex-beautify' diff --git a/src/languages/gn.coffee b/src/languages/gn.coffee new file mode 100644 index 0000000..5e1799b --- /dev/null +++ b/src/languages/gn.coffee @@ -0,0 +1,23 @@ +module.exports = { + + name: "GN" + namespace: "gn" + + ### + Supported Grammars + ### + grammars: [ + "gn" + ] + + ### + Supported extensions + ### + extensions: [ + "gn" + "gni" + ] + + defaultBeautifier: "GN" + +} diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 7cc1e5c..5811229 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -31,6 +31,7 @@ module.exports = class Languages "erlang" "gherkin" "glsl" + "gn" "go" "gohtml" "fortran" diff --git a/src/options.json b/src/options.json index 0eca25e..e15b234 100644 --- a/src/options.json +++ b/src/options.json @@ -2079,6 +2079,48 @@ } } }, + "gn": { + "title": "GN", + "type": "object", + "description": "Options for language GN", + "collapsed": true, + "beautifiers": [ + "GN" + ], + "grammars": [ + "gn" + ], + "extensions": [ + "gn", + "gni" + ], + "properties": { + "disabled": { + "title": "Disable Beautifying Language", + "order": -3, + "type": "boolean", + "default": false, + "description": "Disable GN Beautification" + }, + "default_beautifier": { + "title": "Default Beautifier", + "order": -2, + "type": "string", + "default": "GN", + "description": "Default Beautifier to be used for GN", + "enum": [ + "GN" + ] + }, + "beautify_on_save": { + "title": "Beautify On Save", + "order": -1, + "type": "boolean", + "default": false, + "description": "Automatically beautify GN files on save" + } + } + }, "go": { "title": "Go", "type": "object", @@ -9288,6 +9330,22 @@ } } }, + "gn": { + "key": "gn", + "title": "gn", + "type": "object", + "collapsed": true, + "description": "Options for gn executable.", + "properties": { + "path": { + "key": "path", + "title": "Binary/Script Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"gn\" executable's binary/script." + } + } + }, "goimports": { "key": "goimports", "title": "goimports",