Change logic to prevent eol feature override setting value

New logic + document (only insertion)
This commit is contained in:
Deforder 2017-01-24 21:26:19 +07:00
parent fa266a2e26
commit 77da64f4f0
4 changed files with 323 additions and 23 deletions

View File

@ -766,6 +766,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: |
@ -895,6 +896,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`
@ -2179,6 +2208,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: |
@ -2314,6 +2344,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`
@ -4972,6 +5030,7 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify)
| `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `brace_style` | :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: |
| `end_with_newline` | :white_check_mark: | :x: | :x: |
| `eval_code` | :white_check_mark: | :x: | :x: |
@ -5101,6 +5160,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`
@ -5530,6 +5617,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: |
@ -5659,6 +5747,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`
@ -6088,6 +6204,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: |
@ -6217,6 +6334,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`
@ -11779,6 +11924,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: |
@ -11908,6 +12054,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`
@ -12785,6 +12959,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: |
@ -12920,6 +13095,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`
@ -14777,6 +14980,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
@ -15437,6 +15668,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`
@ -17569,6 +17828,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
@ -18071,6 +18358,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

@ -106,8 +106,10 @@ module.exports = class Beautifier
# 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) ->
switch atom.config.get('line-ending-selector.defaultLineEnding')
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'
@ -116,6 +118,7 @@ module.exports = class Beautifier
return if process.platform is 'win32' then crlf else lf
else
return lf
###
If platform is Windows
###

View File

@ -6,15 +6,6 @@ module.exports = class JSBeautify extends Beautifier
link: "https://github.com/beautify-web/js-beautify"
options: {
_:
eol: ['end_of_line', (end_of_line) ->
if (end_of_line == 'CRLF')
'\r\n'
else if (end_of_line == 'LF')
'\n'
else
null
]
HTML: true
XML: true
Handlebars: true
@ -36,7 +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)}")
options.eol = options.eol ? @getDefaultLineEnding('\r\n','\n')
options.eol = @getDefaultLineEnding('\r\n','\n',options.end_of_line)
return new @Promise((resolve, reject) =>
try
switch language

View File

@ -42,14 +42,6 @@ module.exports = class PrettyDiff extends Beautifier
]
ternaryline: "preserve_ternary_lines"
bracepadding: "space_in_paren"
crlf: ['end_of_line', (end_of_line) ->
if (end_of_line == 'CRLF')
true
else if (end_of_line == 'LF')
false
else
null
]
# Apply language-specific options
CSV: true
Coldfusion: true
@ -77,8 +69,7 @@ module.exports = class PrettyDiff extends Beautifier
}
beautify: (text, language, options) ->
options.crlf = options.crlf ? @getDefaultLineEnding(true,false)
options.crlf = @getDefaultLineEnding(true,false,options.end_of_line)
return new @Promise((resolve, reject) =>
prettydiff = require("prettydiff")
_ = require('lodash')