Updated change without Docs

This commit is contained in:
Deforder 2017-01-14 15:58:01 +07:00
parent 97d62680e4
commit c7d20d0c10
4 changed files with 43 additions and 4 deletions

View File

@ -97,6 +97,25 @@ 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) ->
switch atom.config.get('line-ending-selector.defaultLineEnding')
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

@ -6,6 +6,15 @@ 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
@ -27,9 +36,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 = options.eol ? @getDefaultLineEnding('\r\n','\n')
return new @Promise((resolve, reject) =>
try
switch language

View File

@ -42,6 +42,14 @@ 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
@ -70,6 +78,7 @@ module.exports = class PrettyDiff extends Beautifier
beautify: (text, language, options) ->
options.crlf = options.crlf ? @getDefaultLineEnding(true,false)
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"
}