Merge pull request #1469 from deforder/atom-beautify/issue1457

Added override EOL option for JS , JSX
This commit is contained in:
Glavin Wiechert 2017-04-15 12:39:51 -03:00 committed by GitHub
commit 0f691d5116
5 changed files with 331 additions and 26 deletions

View File

@ -785,6 +785,7 @@ Automatically beautify Clojure files on save
| `beautify_on_save` | :white_check_mark: | :white_check_mark: |
| `brace_style` | :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: |
| `end_with_newline` | :white_check_mark: | :x: |
| `eval_code` | :white_check_mark: | :x: |
@ -914,6 +915,34 @@ Break chained method calls across subsequent lines (Supported by Coffee Formatte
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`Coffee Formatter`](#coffee-formatter)
**Description**:
Override EOL from line-ending-selector (Supported by Coffee Formatter)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -2198,6 +2227,7 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify)
| `beautify_on_save` | :white_check_mark: | :white_check_mark: |
| `brace_style` | :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: |
| `end_with_newline` | :white_check_mark: | :x: |
| `eval_code` | :white_check_mark: | :x: |
@ -2333,6 +2363,34 @@ Break chained method calls across subsequent lines (Supported by JS Beautify, Pr
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`JS Beautify`](#js-beautify)
**Description**:
Override EOL from line-ending-selector (Supported by JS Beautify)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -5297,6 +5355,34 @@ Break chained method calls across subsequent lines (Supported by JS Beautify, Pr
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`JS Beautify`](#js-beautify)
**Description**:
Override EOL from line-ending-selector (Supported by JS Beautify)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -5726,6 +5812,7 @@ Wrap lines at next opportunity after N characters (Supported by JS Beautify, Pre
| `beautify_on_save` | :white_check_mark: | :white_check_mark: |
| `brace_style` | :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: |
| `end_with_newline` | :white_check_mark: | :x: |
| `eval_code` | :white_check_mark: | :x: |
@ -5855,6 +5942,34 @@ Break chained method calls across subsequent lines (Supported by JS Beautify, Pr
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`JS Beautify`](#js-beautify)
**Description**:
Override EOL from line-ending-selector (Supported by JS Beautify)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -6284,6 +6399,7 @@ Wrap lines at next opportunity after N characters (Supported by JS Beautify, Pre
| `beautify_on_save` | :white_check_mark: | :white_check_mark: |
| `brace_style` | :white_check_mark: | :x: |
| `break_chained_methods` | :white_check_mark: | :white_check_mark: |
| `end_of_line` | :white_check_mark: | :x: |
| `e4x` | :white_check_mark: | :x: |
| `end_with_comma` | :white_check_mark: | :white_check_mark: |
| `end_with_newline` | :white_check_mark: | :x: |
@ -6414,6 +6530,18 @@ Break chained method calls across subsequent lines (Supported by JS Beautify, Pr
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
##### [E4x](#e4x)
**Namespace**: `jsx`
@ -6428,13 +6556,16 @@ Break chained method calls across subsequent lines (Supported by JS Beautify, Pr
**Description**:
Override EOL from line-ending-selector (Supported by JS Beautify)
Support e4x/jsx syntax (Supported by JS Beautify)
**Example `.jsbeautifyrc` Configuration**
```json
{
"jsx": {
"js": {
"end_of_line": "System Default"
"e4x": true
}
}
@ -12237,6 +12368,7 @@ Maximum characters per line (0 disables) (Supported by Pretty Diff)
| `beautify_on_save` | :white_check_mark: |
| `brace_style` | :white_check_mark: |
| `break_chained_methods` | :white_check_mark: |
| `end_of_line` | :white_check_mark: |
| `end_with_comma` | :white_check_mark: |
| `end_with_newline` | :white_check_mark: |
| `eval_code` | :white_check_mark: |
@ -12366,6 +12498,34 @@ Break chained method calls across subsequent lines (Supported by TypeScript Form
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter)
**Description**:
Override EOL from line-ending-selector (Supported by TypeScript Formatter)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -13243,6 +13403,7 @@ Maximum characters per line (0 disables) (Supported by Pretty Diff)
| `beautify_on_save` | :white_check_mark: |
| `brace_style` | :white_check_mark: |
| `break_chained_methods` | :white_check_mark: |
| `end_of_line` | :white_check_mark: |
| `end_with_comma` | :white_check_mark: |
| `end_with_newline` | :white_check_mark: |
| `eval_code` | :white_check_mark: |
@ -13378,6 +13539,34 @@ Break chained method calls across subsequent lines (Supported by Vue Beautifier)
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`Vue Beautifier`](#vue-beautifier)
**Description**:
Override EOL from line-ending-selector (Supported by Vue Beautifier)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [End with comma](#end-with-comma)
**Namespace**: `js`
@ -15235,6 +15424,34 @@ If a terminating comma should be inserted into arrays, object literals, and dest
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`Coffee Formatter`](#coffee-formatter)
**Description**:
Override EOL from line-ending-selector (Supported by Coffee Formatter)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
### Fortran Beautifier
@ -15895,6 +16112,34 @@ If a terminating comma should be inserted into arrays, object literals, and dest
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`JS Beautify`](#js-beautify)
**Description**:
Override EOL from line-ending-selector (Supported by JS Beautify)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [Indent inner html](#indent-inner-html)
**Namespace**: `html`
@ -18134,6 +18379,34 @@ If a terminating comma should be inserted into arrays, object literals, and dest
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter)
**Description**:
Override EOL from line-ending-selector (Supported by TypeScript Formatter)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
### Uncrustify
@ -18636,6 +18909,34 @@ If a terminating comma should be inserted into arrays, object literals, and dest
}
```
##### [End of line](#end-of-line)
**Namespace**: `js`
**Key**: `end_of_line`
**Default**: `System Default`
**Type**: `string`
**Enum**: `CRLF` `LF` `System Default`
**Supported Beautifiers**: [`Vue Beautifier`](#vue-beautifier)
**Description**:
Override EOL from line-ending-selector (Supported by Vue Beautifier)
**Example `.jsbeautifyrc` Configuration**
```json
{
"js": {
"end_of_line": "System Default"
}
}
```
##### [Indent inner html](#indent-inner-html)
**Namespace**: `html`

View File

@ -102,6 +102,28 @@ module.exports = class Beautifier
startDir.pop()
return null
# Retrieves the default line ending based upon the Atom configuration
# `line-ending-selector.defaultLineEnding`. If the Atom configuration
# indicates "OS Default", the `process.platform` is queried, returning
# CRLF for Windows systems and LF for all other systems.
# Code modified from atom/line-ending-selector
# returns: The correct line-ending character sequence based upon the Atom
# configuration, or `null` if the Atom line ending configuration was not
# recognized.
# see: https://github.com/atom/line-ending-selector/blob/master/lib/main.js
getDefaultLineEnding: (crlf,lf,optionEol) ->
if (!optionEol || optionEol == 'System Default')
optionEol = atom.config.get('line-ending-selector.defaultLineEnding')
switch optionEol
when 'LF'
return lf
when 'CRLF'
return crlf
when 'OS Default'
return if process.platform is 'win32' then crlf else lf
else
return lf
###
If platform is Windows
###

View File

@ -27,9 +27,7 @@ module.exports = class JSBeautify extends Beautifier
beautify: (text, language, options) ->
@verbose("JS Beautify language #{language}")
@info("JS Beautify Options: #{JSON.stringify(options, null, 4)}")
#TODO reconsider handling of EOL once js-beautify adds EOL detection
#see https://github.com/beautify-web/js-beautify/issues/899
options.eol = getDefaultLineEnding() ? options.eol #fixes issue #707
options.eol = @getDefaultLineEnding('\r\n','\n',options.end_of_line)
return new @Promise((resolve, reject) =>
try
switch language
@ -60,23 +58,3 @@ module.exports = class JSBeautify extends Beautifier
reject(err)
)
# Retrieves the default line ending based upon the Atom configuration
# `line-ending-selector.defaultLineEnding`. If the Atom configuration
# indicates "OS Default", the `process.platform` is queried, returning
# CRLF for Windows systems and LF for all other systems.
# Code modified from atom/line-ending-selector
# returns: The correct line-ending character sequence based upon the Atom
# configuration, or `null` if the Atom line ending configuration was not
# recognized.
# see: https://github.com/atom/line-ending-selector/blob/master/lib/main.js
getDefaultLineEnding= ->
switch atom.config.get('line-ending-selector.defaultLineEnding')
when 'LF'
return '\n'
when 'CRLF'
return '\r\n'
when 'OS Default'
return if process.platform is 'win32' then '\r\n' else '\n'
else
return null

View File

@ -71,7 +71,7 @@ module.exports = class PrettyDiff extends Beautifier
}
beautify: (text, language, options) ->
options.crlf = @getDefaultLineEnding(true,false,options.end_of_line)
return new @Promise((resolve, reject) =>
prettydiff = require("prettydiff")
_ = require('lodash')

View File

@ -28,7 +28,6 @@ module.exports = {
defaultBeautifier: "JS Beautify"
###
###
options:
# JavaScript
@ -111,5 +110,10 @@ module.exports = {
default: false
description: "If a terminating comma should be inserted into \
arrays, object literals, and destructured objects."
end_of_line:
type: 'string'
default: "System Default"
enum: ["CRLF","LF","System Default"]
description: "Override EOL from line-ending-selector"
}