Added Overrided EOL option for JS , JSX
This commit is contained in:
parent
d091570860
commit
c48eaf967e
3362
docs/options.md
3362
docs/options.md
File diff suppressed because it is too large
Load Diff
|
@ -97,6 +97,26 @@ module.exports = class Beautifier
|
||||||
startDir.pop()
|
startDir.pop()
|
||||||
return null
|
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
|
If platform is Windows
|
||||||
###
|
###
|
||||||
|
|
|
@ -6,6 +6,15 @@ module.exports = class JSBeautify extends Beautifier
|
||||||
link: "https://github.com/beautify-web/js-beautify"
|
link: "https://github.com/beautify-web/js-beautify"
|
||||||
|
|
||||||
options: {
|
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
|
HTML: true
|
||||||
XML: true
|
XML: true
|
||||||
Handlebars: true
|
Handlebars: true
|
||||||
|
@ -25,11 +34,10 @@ module.exports = class JSBeautify extends Beautifier
|
||||||
}
|
}
|
||||||
|
|
||||||
beautify: (text, language, options) ->
|
beautify: (text, language, options) ->
|
||||||
|
|
||||||
@verbose("JS Beautify language #{language}")
|
@verbose("JS Beautify language #{language}")
|
||||||
@info("JS Beautify Options: #{JSON.stringify(options, null, 4)}")
|
@info("JS Beautify Options: #{JSON.stringify(options, null, 4)}")
|
||||||
#TODO reconsider handling of EOL once js-beautify adds EOL detection
|
options.eol = options.eol ? @getDefaultLineEnding('\r\n','\n')
|
||||||
#see https://github.com/beautify-web/js-beautify/issues/899
|
|
||||||
options.eol = getDefaultLineEnding() ? options.eol #fixes issue #707
|
|
||||||
return new @Promise((resolve, reject) =>
|
return new @Promise((resolve, reject) =>
|
||||||
try
|
try
|
||||||
switch language
|
switch language
|
||||||
|
@ -58,23 +66,3 @@ module.exports = class JSBeautify extends Beautifier
|
||||||
reject(err)
|
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
|
|
||||||
|
|
|
@ -42,6 +42,14 @@ module.exports = class PrettyDiff extends Beautifier
|
||||||
]
|
]
|
||||||
ternaryline: "preserve_ternary_lines"
|
ternaryline: "preserve_ternary_lines"
|
||||||
bracepadding: "space_in_paren"
|
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
|
# Apply language-specific options
|
||||||
CSV: true
|
CSV: true
|
||||||
Coldfusion: true
|
Coldfusion: true
|
||||||
|
@ -70,6 +78,7 @@ module.exports = class PrettyDiff extends Beautifier
|
||||||
|
|
||||||
beautify: (text, language, options) ->
|
beautify: (text, language, options) ->
|
||||||
|
|
||||||
|
options.crlf = options.crlf ? @getDefaultLineEnding(true,false)
|
||||||
return new @Promise((resolve, reject) =>
|
return new @Promise((resolve, reject) =>
|
||||||
prettydiff = require("prettydiff")
|
prettydiff = require("prettydiff")
|
||||||
_ = require('lodash')
|
_ = require('lodash')
|
||||||
|
|
|
@ -111,5 +111,10 @@ module.exports = {
|
||||||
default: false
|
default: false
|
||||||
description: "If a terminating comma should be inserted into \
|
description: "If a terminating comma should be inserted into \
|
||||||
arrays, object literals, and destructured objects."
|
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"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue