From 48bd5584dab3573c3bb036f6154d724a159e6aa6 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sat, 15 Apr 2017 21:03:25 -0300 Subject: [PATCH] See #312. Add align-yaml as YAML beautifier --- README.md | 2 + docs/options.md | 121 ++++++++++++++++++ examples/nested-jsbeautifyrc/.jsbeautifyrc | 2 + .../yaml/expected/test.yaml | 3 + .../yaml/original/test.yaml | 3 + package.json | 8 +- src/beautifiers/align-yaml.coffee | 18 +++ src/beautifiers/index.coffee | 1 + src/languages/index.coffee | 1 + src/languages/yaml.coffee | 33 +++++ 10 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 examples/nested-jsbeautifyrc/yaml/expected/test.yaml create mode 100644 examples/nested-jsbeautifyrc/yaml/original/test.yaml create mode 100644 src/beautifiers/align-yaml.coffee create mode 100644 src/languages/yaml.coffee diff --git a/README.md b/README.md index 6a93c16..86b5f4b 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall | Beautifier | Is Pre-Installed? | Installation Instructions | | --- | --- | --- | +| align-yaml | :white_check_mark: | Nothing! | | autopep8 | :x: | Go to https://github.com/hhatto/autopep8 and follow the instructions. | | beautysh | :x: | Go to https://github.com/bemeurer/beautysh and follow the instructions. | | clang-format | :x: | Go to https://clang.llvm.org/docs/ClangFormat.html and follow the instructions. | @@ -177,6 +178,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti | Vue | `Vue Component` |`.vue` | [`Vue Beautifier`](https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/vue-beautifier.coffee) (Default) | | XML | `SLD`, `XML`, `XHTML`, `XSD`, `XSL`, `JSP`, `GSP` |`.sld`, `.xml`, `.xhtml`, `.xsd`, `.xsl`, `.jsp`, `.gsp`, `.plist`, `.recipe` | [`JS Beautify`](https://github.com/beautify-web/js-beautify), [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) | | XTemplate | `XTemplate` |`.xtemplate` | [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) | +| YAML | `YAML` |`.yml`, `.yaml` | [`align-yaml`](https://github.com/jonschlinkert/align-yaml) (Default) | ## Usage diff --git a/docs/options.md b/docs/options.md index dd22fdd..18a49d2 100644 --- a/docs/options.md +++ b/docs/options.md @@ -14902,6 +14902,100 @@ Maximum characters per line (0 disables) (Supported by Pretty Diff) } ``` +#### [YAML](#yaml) + +**Supported Beautifiers**: [`align-yaml`](#align-yaml) + +| Option | align-yaml | +| --- | --- | +| `disabled` | :white_check_mark: | +| `default_beautifier` | :white_check_mark: | +| `beautify_on_save` | :white_check_mark: | +| `padding` | :white_check_mark: | + +**Description**: + +Options for language YAML + +##### [Disable Beautifying Language](#disable-beautifying-language) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Disable YAML 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**: `align-yaml` + +**Type**: `string` + +**Enum**: `align-yaml` + +**Description**: + +Default Beautifier to be used for YAML + +**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 YAML 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. + +##### [Padding](#padding) + +**Namespace**: `yaml` + +**Key**: `padding` + +**Type**: `integer` + +**Supported Beautifiers**: [`align-yaml`](#align-yaml) + +**Description**: + +The amount of padding to add next to each line. (Supported by align-yaml) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "yaml": { + "padding": 0 + } +} +``` + ## Beautifier Options @@ -19179,6 +19273,33 @@ List of tags (defaults to [head,body,/html] that should have an extra newline be ``` +### align-yaml + +##### [Padding](#padding) + +**Namespace**: `yaml` + +**Key**: `padding` + +**Type**: `integer` + +**Supported Beautifiers**: [`align-yaml`](#align-yaml) + +**Description**: + +The amount of padding to add next to each line. (Supported by align-yaml) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "yaml": { + "padding": 0 + } +} +``` + + ### autopep8 ##### [Max line length](#max-line-length) diff --git a/examples/nested-jsbeautifyrc/.jsbeautifyrc b/examples/nested-jsbeautifyrc/.jsbeautifyrc index 229895f..693c649 100644 --- a/examples/nested-jsbeautifyrc/.jsbeautifyrc +++ b/examples/nested-jsbeautifyrc/.jsbeautifyrc @@ -64,3 +64,5 @@ space_before_conditional: false space_after_anon_function: false jslint_happy: false + yaml: + padding: 5 diff --git a/examples/nested-jsbeautifyrc/yaml/expected/test.yaml b/examples/nested-jsbeautifyrc/yaml/expected/test.yaml new file mode 100644 index 0000000..37c1c20 --- /dev/null +++ b/examples/nested-jsbeautifyrc/yaml/expected/test.yaml @@ -0,0 +1,3 @@ +one: two +three: four +seventeen: five \ No newline at end of file diff --git a/examples/nested-jsbeautifyrc/yaml/original/test.yaml b/examples/nested-jsbeautifyrc/yaml/original/test.yaml new file mode 100644 index 0000000..695346b --- /dev/null +++ b/examples/nested-jsbeautifyrc/yaml/original/test.yaml @@ -0,0 +1,3 @@ +one: two +three: four +seventeen: five \ No newline at end of file diff --git a/package.json b/package.json index 91e54f7..f75435c 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "atom": ">=1.6.0 <2.0.0" }, "dependencies": { + "align-yaml": "^0.1.8", "async": "^2.0.1", "atom-message-panel": "^1.2.4", "atom-space-pen-views": "^2.0.5", @@ -162,8 +163,8 @@ "loophole": "^1.0.0", "marko-prettyprint": "^1.2.0", "nginxbeautify": "^2.0.0", - "node-dir": "^0.1.16", "node-cljfmt": "^0.5.3-1", + "node-dir": "^0.1.16", "node-uuid": "^1.4.3", "open": "0.0.5", "prettydiff": "^1.16.27", @@ -319,7 +320,8 @@ "hh_format", "nginx", "nginx beautify", - "golang template" + "golang template", + "align-yaml" ], "devDependencies": { "coffeelint": "^1.10.1", @@ -332,4 +334,4 @@ "lint": "coffeelint src/ spec/", "code-docs": "codo && open docs/code/index.html" } -} +} \ No newline at end of file diff --git a/src/beautifiers/align-yaml.coffee b/src/beautifiers/align-yaml.coffee new file mode 100644 index 0000000..b54f114 --- /dev/null +++ b/src/beautifiers/align-yaml.coffee @@ -0,0 +1,18 @@ +"use strict" +Beautifier = require('./beautifier') + +module.exports = class AlignYaml extends Beautifier + name: "align-yaml" + link: "https://github.com/jonschlinkert/align-yaml" + + options: { + YAML: + padding: true + } + + beautify: (text, language, options) -> + return new @Promise((resolve, reject) -> + align = require('align-yaml') + result = align(text, options.padding) + resolve(result) + ) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 73a643b..8d6d227 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -35,6 +35,7 @@ module.exports = class Beautifiers extends EventEmitter ### beautifierNames : [ 'uncrustify' + 'align-yaml' 'autopep8' 'coffee-formatter' 'coffee-fmt' diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 3c7f92d..9ea2e36 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -76,6 +76,7 @@ module.exports = class Languages "visualforce" "xml" "xtemplate" + "yaml" ] ### diff --git a/src/languages/yaml.coffee b/src/languages/yaml.coffee new file mode 100644 index 0000000..2d88d19 --- /dev/null +++ b/src/languages/yaml.coffee @@ -0,0 +1,33 @@ +module.exports = { + + name: "YAML" + namespace: "yaml" + fallback: [] + scope: ['source.yaml'] + + ### + Supported Grammars + ### + grammars: [ + "YAML" + ] + + ### + Supported extensions + ### + extensions: [ + "yml", + "yaml" + ] + + defaultBeautifier: "align-yaml" + + options: { + padding: + type: 'integer' + default: null + minimum: 0 + description: "The amount of padding to add next to each line." + } + +}