From cc56ba34b062bac4363e18f21c5be93912cf592d Mon Sep 17 00:00:00 2001 From: Steven Zeck Date: Mon, 19 Feb 2018 11:13:43 -0600 Subject: [PATCH] Fix up options for Prettier, add new bracket_spacing option --- docs/options.md | 360 +++++++++++++++++++++++++++++++- src/beautifiers/prettier.coffee | 9 +- src/languages/javascript.coffee | 4 + src/options.json | 105 +++++++++- 4 files changed, 467 insertions(+), 11 deletions(-) diff --git a/docs/options.md b/docs/options.md index 470de85..6e3422d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1077,6 +1077,7 @@ Automatically beautify Clojure files on save | `default_beautifier` | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | | `brace_style` | :white_check_mark: | :x: | +| `bracket_spacing` | :white_check_mark: | :x: | | `break_chained_methods` | :white_check_mark: | :x: | | `end_of_line` | :white_check_mark: | :x: | | `end_with_comma` | :white_check_mark: | :x: | @@ -1184,6 +1185,30 @@ Automatically beautify CoffeeScript files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Coffee Formatter`](#coffee-formatter) + +**Description**: + +Insert spaces between brackets in object literals (Supported by Coffee Formatter) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -2519,6 +2544,7 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) | `default_beautifier` | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | | `brace_style` | :white_check_mark: | :x: | +| `bracket_spacing` | :white_check_mark: | :x: | | `break_chained_methods` | :white_check_mark: | :white_check_mark: | | `end_of_line` | :white_check_mark: | :x: | | `end_with_comma` | :white_check_mark: | :white_check_mark: | @@ -2632,6 +2658,30 @@ Automatically beautify EJS files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -5518,6 +5568,7 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) | `default_beautifier` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | `brace_style` | :x: | :white_check_mark: | :x: | :x: | :x: | +| `bracket_spacing` | :x: | :white_check_mark: | :x: | :white_check_mark: | :x: | | `break_chained_methods` | :x: | :white_check_mark: | :x: | :x: | :white_check_mark: | | `end_of_line` | :x: | :white_check_mark: | :x: | :x: | :x: | | `end_with_comma` | :x: | :white_check_mark: | :x: | :x: | :white_check_mark: | @@ -5525,8 +5576,8 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) | `eval_code` | :x: | :white_check_mark: | :x: | :x: | :x: | | `indent_char` | :x: | :white_check_mark: | :x: | :x: | :white_check_mark: | | `indent_level` | :x: | :white_check_mark: | :x: | :x: | :x: | -| `indent_size` | :x: | :white_check_mark: | :x: | :x: | :white_check_mark: | -| `indent_with_tabs` | :x: | :white_check_mark: | :x: | :x: | :white_check_mark: | +| `indent_size` | :x: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | +| `indent_with_tabs` | :x: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | | `jslint_happy` | :x: | :white_check_mark: | :x: | :x: | :x: | | `keep_array_indentation` | :x: | :white_check_mark: | :x: | :x: | :x: | | `keep_function_indentation` | :x: | :white_check_mark: | :x: | :x: | :x: | @@ -5625,6 +5676,30 @@ Automatically beautify JavaScript files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify, Prettier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -5809,11 +5884,11 @@ Initial indentation level (Supported by JS Beautify) **Type**: `integer` -**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Pretty Diff`](#pretty-diff) +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) [`Pretty Diff`](#pretty-diff) **Description**: -Indentation size/length (Supported by JS Beautify, Pretty Diff) +Indentation size/length (Supported by JS Beautify, Prettier, Pretty Diff) **Example `.jsbeautifyrc` Configuration** @@ -5833,11 +5908,11 @@ Indentation size/length (Supported by JS Beautify, Pretty Diff) **Type**: `boolean` -**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Pretty Diff`](#pretty-diff) +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) [`Pretty Diff`](#pretty-diff) **Description**: -Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by JS Beautify, Pretty Diff) +Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by JS Beautify, Prettier, Pretty Diff) **Example `.jsbeautifyrc` Configuration** @@ -6105,6 +6180,7 @@ Wrap lines at next opportunity after N characters (Supported by JS Beautify, Pre | `default_beautifier` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | `brace_style` | :white_check_mark: | :x: | :x: | +| `bracket_spacing` | :white_check_mark: | :x: | :x: | | `break_chained_methods` | :white_check_mark: | :x: | :white_check_mark: | | `end_of_line` | :white_check_mark: | :x: | :x: | | `end_with_comma` | :white_check_mark: | :x: | :white_check_mark: | @@ -6212,6 +6288,30 @@ Automatically beautify JSON files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -6692,6 +6792,7 @@ Wrap lines at next opportunity after N characters (Supported by JS Beautify, Pre | `default_beautifier` | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | | `brace_style` | :white_check_mark: | :x: | +| `bracket_spacing` | :white_check_mark: | :x: | | `break_chained_methods` | :white_check_mark: | :white_check_mark: | | `e4x` | :white_check_mark: | :x: | | `end_of_line` | :white_check_mark: | :x: | @@ -6800,6 +6901,30 @@ Automatically beautify JSX files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -13003,6 +13128,7 @@ Maximum characters per line (0 disables) (Supported by Pretty Diff) | `default_beautifier` | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | | `brace_style` | :white_check_mark: | +| `bracket_spacing` | :white_check_mark: | | `break_chained_methods` | :white_check_mark: | | `end_of_line` | :white_check_mark: | | `end_with_comma` | :white_check_mark: | @@ -13110,6 +13236,30 @@ Automatically beautify TypeScript files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter) + +**Description**: + +Insert spaces between brackets in object literals (Supported by TypeScript Formatter) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -14038,6 +14188,7 @@ Maximum characters per line (0 disables) (Supported by Pretty Diff) | `default_beautifier` | :white_check_mark: | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | | `brace_style` | :x: | :white_check_mark: | +| `bracket_spacing` | :x: | :white_check_mark: | | `break_chained_methods` | :x: | :white_check_mark: | | `end_of_line` | :x: | :white_check_mark: | | `end_with_comma` | :x: | :white_check_mark: | @@ -14151,6 +14302,30 @@ Automatically beautify Vue files on save } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Vue Beautifier`](#vue-beautifier) + +**Description**: + +Insert spaces between brackets in object literals (Supported by Vue Beautifier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Break chained methods](#break-chained-methods) **Namespace**: `js` @@ -16182,6 +16357,30 @@ Override EOL from line-ending-selector (Supported by Coffee Formatter) } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Coffee Formatter`](#coffee-formatter) + +**Description**: + +Insert spaces between brackets in object literals (Supported by Coffee Formatter) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ### Fortran Beautifier @@ -16870,6 +17069,30 @@ Override EOL from line-ending-selector (Supported by JS Beautify) } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Indent inner html](#indent-inner-html) **Namespace**: `html` @@ -18177,6 +18400,83 @@ Specify a configuration file which will override the default name of .perltidyrc ``` +### Prettier + +##### [Indent size](#indent-size) + +**Namespace**: `js` + +**Key**: `indent_size` + +**Default**: `4` + +**Type**: `integer` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) [`Pretty Diff`](#pretty-diff) + +**Description**: + +Indentation size/length (Supported by JS Beautify, Prettier, Pretty Diff) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "indent_size": 4 + } +} +``` + +##### [Indent with tabs](#indent-with-tabs) + +**Namespace**: `js` + +**Key**: `indent_with_tabs` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) [`Pretty Diff`](#pretty-diff) + +**Description**: + +Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by JS Beautify, Prettier, Pretty Diff) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "indent_with_tabs": false + } +} +``` + +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`JS Beautify`](#js-beautify) [`Prettier`](#prettier) + +**Description**: + +Insert spaces between brackets in object literals (Supported by JS Beautify, Prettier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + + ### Pretty Diff ##### [Indent size](#indent-size) @@ -19300,6 +19600,30 @@ Override EOL from line-ending-selector (Supported by TypeScript Formatter) } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter) + +**Description**: + +Insert spaces between brackets in object literals (Supported by TypeScript Formatter) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ### Uncrustify @@ -19830,6 +20154,30 @@ Override EOL from line-ending-selector (Supported by Vue Beautifier) } ``` +##### [Bracket spacing](#bracket-spacing) + +**Namespace**: `js` + +**Key**: `bracket_spacing` + +**Type**: `boolean` + +**Supported Beautifiers**: [`Vue Beautifier`](#vue-beautifier) + +**Description**: + +Insert spaces between brackets in object literals (Supported by Vue Beautifier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "js": { + "bracket_spacing": false + } +} +``` + ##### [Indent inner html](#indent-inner-html) **Namespace**: `html` diff --git a/src/beautifiers/prettier.coffee b/src/beautifiers/prettier.coffee index e7fea61..3c083ae 100644 --- a/src/beautifiers/prettier.coffee +++ b/src/beautifiers/prettier.coffee @@ -7,7 +7,11 @@ module.exports = class Prettier extends Beautifier name: "Prettier" link: "https://github.com/prettier/prettier" options: { - JavaScript: false + _: + tabWidth: "indent_size" + useTabs: "indent_with_tabs" + JavaScript: + bracketSpacing: "bracket_spacing" CSS: false LESS: false SCSS: false @@ -28,8 +32,7 @@ module.exports = class Prettier extends Beautifier try result = prettier.format(text, { - tabWidth: options.indent_size, - useTabs: options.indent_with_tabs + options parser }); resolve result diff --git a/src/languages/javascript.coffee b/src/languages/javascript.coffee index 04dd35b..5d795c3 100644 --- a/src/languages/javascript.coffee +++ b/src/languages/javascript.coffee @@ -108,5 +108,9 @@ module.exports = { default: "System Default" enum: ["CRLF","LF","System Default"] description: "Override EOL from line-ending-selector" + bracket_spacing: + type: 'boolean' + default: false + description: "Insert spaces between brackets in object literals" } diff --git a/src/options.json b/src/options.json index b5c0ec2..12228a2 100644 --- a/src/options.json +++ b/src/options.json @@ -642,6 +642,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by Coffee Formatter)", + "title": "Bracket spacing", + "beautifiers": [ + "Coffee Formatter" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3, @@ -1565,6 +1579,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by JS Beautify)", + "title": "Bracket spacing", + "beautifiers": [ + "JS Beautify" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "indent_inner_html": { "type": "boolean", "default": false, @@ -3155,10 +3183,11 @@ "type": "integer", "default": null, "minimum": 0, - "description": "Indentation size/length (Supported by JS Beautify, Pretty Diff)", + "description": "Indentation size/length (Supported by JS Beautify, Prettier, Pretty Diff)", "title": "Indent size", "beautifiers": [ "JS Beautify", + "Prettier", "Pretty Diff" ], "key": "indent_size", @@ -3199,10 +3228,11 @@ "indent_with_tabs": { "type": "boolean", "default": null, - "description": "Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by JS Beautify, Pretty Diff)", + "description": "Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by JS Beautify, Prettier, Pretty Diff)", "title": "Indent with tabs", "beautifiers": [ "JS Beautify", + "Prettier", "Pretty Diff" ], "key": "indent_with_tabs", @@ -3453,6 +3483,21 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by JS Beautify, Prettier)", + "title": "Bracket spacing", + "beautifiers": [ + "JS Beautify", + "Prettier" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3, @@ -3802,6 +3847,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by JS Beautify)", + "title": "Bracket spacing", + "beautifiers": [ + "JS Beautify" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3, @@ -4166,6 +4225,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by JS Beautify)", + "title": "Bracket spacing", + "beautifiers": [ + "JS Beautify" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3, @@ -7894,6 +7967,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by TypeScript Formatter)", + "title": "Bracket spacing", + "beautifiers": [ + "TypeScript Formatter" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3, @@ -8383,6 +8470,20 @@ "namespace": "js" } }, + "bracket_spacing": { + "type": "boolean", + "default": false, + "description": "Insert spaces between brackets in object literals (Supported by Vue Beautifier)", + "title": "Bracket spacing", + "beautifiers": [ + "Vue Beautifier" + ], + "key": "bracket_spacing", + "language": { + "name": "JavaScript", + "namespace": "js" + } + }, "indent_inner_html": { "type": "boolean", "default": false,