Fixes #736. Change unformatted option default value to match js-beautify

This commit is contained in:
Glavin Wiechert 2016-01-12 14:27:30 -04:00
parent 9914fc35ab
commit 99299e5d30
19 changed files with 186 additions and 101 deletions

View File

@ -941,7 +941,7 @@ Number of line-breaks to be preserved in one chunk (Supported by JS Beautify)
**Key**: `unformatted`
**Default**: `a,sub,sup,b,i,u`
**Default**: `a,span,img,bdo,em,strong,dfn,code,samp,kbd,var,cite,abbr,acronym,q,sub,sup,tt,i,b,big,small,u,s,strike,font,ins,del,pre,address,dt,h1,h2,h3,h4,h5,h6`
**Type**: `array`
@ -958,11 +958,42 @@ List of tags (defaults to inline) that should not be reformatted (Supported by J
"html": {
"unformatted": [
"a",
"span",
"img",
"bdo",
"em",
"strong",
"dfn",
"code",
"samp",
"kbd",
"var",
"cite",
"abbr",
"acronym",
"q",
"sub",
"sup",
"b",
"tt",
"i",
"u"
"b",
"big",
"small",
"u",
"s",
"strike",
"font",
"ins",
"del",
"pre",
"address",
"dt",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
]
}
}
@ -5093,7 +5124,7 @@ Number of line-breaks to be preserved in one chunk (Supported by JS Beautify)
**Key**: `unformatted`
**Default**: `a,sub,sup,b,i,u`
**Default**: `a,span,img,bdo,em,strong,dfn,code,samp,kbd,var,cite,abbr,acronym,q,sub,sup,tt,i,b,big,small,u,s,strike,font,ins,del,pre,address,dt,h1,h2,h3,h4,h5,h6`
**Type**: `array`
@ -5110,11 +5141,42 @@ List of tags (defaults to inline) that should not be reformatted (Supported by J
"html": {
"unformatted": [
"a",
"span",
"img",
"bdo",
"em",
"strong",
"dfn",
"code",
"samp",
"kbd",
"var",
"cite",
"abbr",
"acronym",
"q",
"sub",
"sup",
"b",
"tt",
"i",
"u"
"b",
"big",
"small",
"u",
"s",
"strike",
"font",
"ins",
"del",
"pre",
"address",
"dt",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
]
}
}

View File

@ -6,13 +6,6 @@
indent_size: 2
max_preserve_newlines: 1
preserve_newlines: true
unformatted:
- "a"
- "sub"
- "sup"
- "b"
- "i"
- "u"
wrap_line_length: 0
css:
indent_char: " "

View File

@ -6,7 +6,6 @@
"indent_size": 6,
"max_preserve_newlines": 1,
"preserve_newlines": true,
"unformatted": ["a", "sub", "sup", "b", "i", "u"],
"wrap_line_length": 0
},
"css": {

View File

@ -1,8 +1,8 @@
<DOCTYPE "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" PUBLIC html>
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Shopping List for
<%= @date.strftime('%A, %d %B %Y') %></title>
</head>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<ul>
<li><code>foo:bar</code></li>
</ul>
</html>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html><html lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<ul>
<li><code>foo:bar</code></li>
</ul>
</html>

View File

@ -4,9 +4,7 @@
{{#items}}
{{#first}}
<li>
<strong>{{name}}</strong>
</li>
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>

View File

@ -12,8 +12,7 @@
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
<h1>My Webpage</h1> {{ a_variable }}
</body>
</html>

View File

@ -3,9 +3,9 @@
<!ENTITY nbsp "<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>">
]>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" encoding="utf-8" indent="yes" method="html"/>
<xsl:output method="html" indent="yes" encoding="utf-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<xsl:template match="/">
<html>

View File

@ -1,27 +1,27 @@
"Window": {
"Window" : {
exitOnClose: true,
backgroundColor: "#fff",
title: "Kochgut"
}
"Label": {
"Label" : {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#555",
touchEnabled: false
}
"Button": {
"Button" : {
backgroundColor: "#03a9f4",
color: "#fff",
borderRadius: 2
}
"#menu": {
"#menu" : {
backgroundImage: "/images/bg.png"
}
".button": {
".button" : {
backgroundColor: "#03a9f4",
color: "#fff",
borderRadius: 2,
@ -31,13 +31,13 @@
bottom: 16
}
".lbl_button": {
".lbl_button" : {
left: 20,
right: 20,
color: "#fff"
}
".headline": {
".headline" : {
color: "#aaa",
left: 16,
height: 48,
@ -46,40 +46,40 @@
}
}
".grid": {
".grid" : {
left: 2,
right: 2,
layout: "horizontal",
height: Ti.UI.SIZE
}
".card [platform=tablet]": {
".card [platform=tablet]" : {
width: "33%",
height: 150,
bottom: 2
}
".card": {
".card" : {
width: "50%",
height: 150,
bottom: 2
}
".padding": {
".padding" : {
right: 2,
left: 0,
top: 0,
bottom: 0,
backgroundImage: "/images/essen.jpg"
}
".card_overlay": {
".card_overlay" : {
bottom: 0,
left: 0,
right: 0,
height: 48
}
".card_overlay_bg": {
".card_overlay_bg" : {
left: 0,
right: 0,
bottom: 0,
@ -88,7 +88,7 @@
opacity: 0.3
}
".card_lbl": {
".card_lbl" : {
color: "#fff",
left: 16,
font: {

View File

@ -1,11 +1,11 @@
".container": {
".container" : {
backgroundImage: 'images/bgbg-builder.png',
width: 1024,
height: 752,
top: 0,
left: 0
},
"#blackArrow": {
"#blackArrow" : {
touchEnabled: false,
backgroundImage: 'images/arrow-builder.png',
width: 15,

View File

@ -1,5 +1,5 @@
<apex:page standardController="Contact">
<apex:sectionHeader subtitle="{!contact.account.name}" title="{!contact.firstname}"/>
<apex:sectionHeader title="{!contact.firstname}" subtitle="{!contact.account.name}"/>
</apex:page>

View File

@ -1,6 +1,6 @@
<apex:page standardController="Contact">
<apex:sectionHeader subtitle="{!contact.account.name}" title="{!contact.firstname}"/>
<apex:sectionHeader title="{!contact.firstname}" subtitle="{!contact.account.name}"/>
<apex:form >
<apex:pageBlock title="Contact">
@ -9,7 +9,7 @@
<apex:inputfield value="{!contact.lastname}"/>
<apex:inputfield value="{!contact.salutation}"/>
<apex:inputfield value="{!contact.birthdate}"/>
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

View File

@ -1,6 +1,6 @@
<apex:page standardController="Contact">
<apex:sectionHeader subtitle="{!contact.account.name}" title="{!contact.firstname}"/>
<apex:sectionHeader title="{!contact.firstname}" subtitle="{!contact.account.name}"/>
<apex:pageBlock title="Contact">
<apex:pageBlockSection title="Details">

View File

@ -84,13 +84,13 @@
"extend": "^3.0.0",
"gherkin": "2.12.2",
"handlebars": "^4.0.2",
"js-beautify": "^1.5.7",
"js-beautify": "^1.5.10",
"jscs": "^2.1.1",
"lodash": "3.10.1",
"loophole": "^1.0.0",
"node-dir": "^0.1.8",
"node-uuid": "^1.4.3",
"prettydiff": "^1.16.5",
"prettydiff": "^1.16.8",
"season": "^5.3.0",
"space-pen": "^5.1.1",
"strip-json-comments": "^1.0.2",

View File

@ -156,51 +156,59 @@ describe "BeautifyLanguages", ->
beautifyCompleted = false
completionFun = (text) ->
expect(text instanceof Error).not.toEqual(true, text)
return beautifyCompleted = true if text instanceof Error
# logger.verbose(expectedTestPath, text) if ext is ".less"
# if text instanceof Error
# return beautifyCompleted = text # text == Error
try
expect(text instanceof Error).not.toEqual(true, text)
return beautifyCompleted = true if text instanceof Error
# logger.verbose(expectedTestPath, text) if ext is ".less"
# if text instanceof Error
# return beautifyCompleted = text # text == Error
expect(text).not.toEqual(null, "Language or Beautifier not found")
return beautifyCompleted = true if text is null
expect(text).not.toEqual(null, "Language or Beautifier not found")
return beautifyCompleted = true if text is null
expect(typeof text).toEqual("string", "Text: #{text}")
return beautifyCompleted = true if typeof text isnt "string"
expect(typeof text).toEqual("string", "Text: #{text}")
return beautifyCompleted = true if typeof text isnt "string"
# Replace Newlines
text = text.replace(/(?:\r\n|\r|\n)/g, '\n')
expectedContents = expectedContents\
.replace(/(?:\r\n|\r|\n)/g, '\n')
# Replace tabs
text = text.replace(/(?:\t)/g, '')
expectedContents = expectedContents\
.replace(/(?:\t)/g, '')
# Replace spaces
text = text.replace(/(?:\ )/g, '')
expectedContents = expectedContents\
.replace(/(?:\ )/g, '')
# Replace Newlines
text = text.replace(/(?:\r\n|\r|\n)/g, '\n')
expectedContents = expectedContents\
.replace(/(?:\r\n|\r|\n)/g, '\n')
# Replace tabs
text = text.replace(/(?:\t)/g, '')
expectedContents = expectedContents\
.replace(/(?:\t)/g, '')
# Replace spaces
text = text.replace(/(?:\ )/g, '')
expectedContents = expectedContents\
.replace(/(?:\ )/g, '')
# Check for beautification errors
if text isnt expectedContents
# console.warn(allOptions, text, expectedContents)
fileName = expectedTestPath
oldStr=text
newStr=expectedContents
oldHeader="beautified"
newHeader="expected"
diff = JsDiff.createPatch(fileName, oldStr, \
newStr, oldHeader, newHeader)
# Get options
opts = beautifier.getOptionsForLanguage(allOptions, language)
# Show error message with debug information
expect(text).toEqual(expectedContents, \
"Beautifier output does not match expected \
output:\n#{diff}\n\n\
With options:\n\
#{JSON.stringify(opts, undefined, 4)}")
# All done!
beautifyCompleted = true
# Check for beautification errors
if text isnt expectedContents
# console.warn(allOptions, text, expectedContents)
fileName = expectedTestPath
oldStr=text
newStr=expectedContents
oldHeader="beautified"
newHeader="expected"
diff = JsDiff.createPatch(fileName, oldStr, \
newStr, oldHeader, newHeader)
# Get options
opts = beautifier.getOptionsForLanguage(allOptions, language)
selectedBeautifier = beautifier.getBeautifierForLanguage(language)
if selectedBeautifier?
opts = beautifier.transformOptions(selectedBeautifier, language.name, opts)
# Show error message with debug information
expect(text).toEqual(expectedContents, \
"Beautifier '#{selectedBeautifier?.name}' output does not match expected \
output:\n#{diff}\n\n\
With options:\n\
#{JSON.stringify(opts, undefined, 4)}")
# All done!
beautifyCompleted = true
catch e
console.error(e)
beautifyCompleted = e
runs ->
try

View File

@ -301,6 +301,16 @@ module.exports = class Beautifiers extends EventEmitter
_.contains(beautifier.languages, language)
)
getBeautifierForLanguage : (language) ->
beautifiers = @getBeautifiers(language.name)
logger.verbose('beautifiers', _.map(beautifiers, 'name'))
# Select beautifier from language config preferences
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
beautifier = _.find(beautifiers, (beautifier) ->
beautifier.name is preferredBeautifierName
) or beautifiers[0]
return beautifier
getLanguage : (grammar, filePath) ->
# Get language
fileExtension = path.extname(filePath)
@ -415,7 +425,6 @@ module.exports = class Beautifiers extends EventEmitter
return resolve( null )
# Get more language config
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save")
legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave")
@ -430,22 +439,17 @@ module.exports = class Beautifiers extends EventEmitter
# Get Beautifier
logger.verbose(grammar, language)
beautifiers = @getBeautifiers(language.name)
logger.verbose("language options: #{JSON.stringify(options, null, 4)}")
logger.verbose('beautifiers', _.map(beautifiers, 'name'))
logger.verbose(language.name, filePath, options, allOptions)
# Check if unsupported language
if beautifiers.length < 1
beautifier = @getBeautifierForLanguage(language)
if not beautifier?
unsupportedGrammar = true
logger.verbose('Beautifier for language not found')
else
# Select beautifier from language config preferences
beautifier = _.find(beautifiers, (beautifier) ->
beautifier.name is preferredBeautifierName
) or beautifiers[0]
logger.verbose('beautifier', beautifier.name)
# Apply language-specific option transformations
@ -521,7 +525,6 @@ module.exports = class Beautifiers extends EventEmitter
)
findFileResults : {}

View File

@ -344,11 +344,8 @@ debug = () ->
# Beautifier
beautifiers = beautifier.getBeautifiers(language.name)
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
addInfo('Supported Beautifiers', _.map(beautifiers, 'name').join(', '))
selectedBeautifier = _.find(beautifiers, (beautifier) ->
beautifier.name is preferredBeautifierName
) or beautifiers[0]
selectedBeautifier = beautifier.getBeautifierForLanguage(language)
addInfo('Selected Beautifier', selectedBeautifier.name)
# Get current editor's text

View File

@ -74,7 +74,9 @@ module.exports = {
description: "Number of line-breaks to be preserved in one chunk"
unformatted:
type: 'array'
default: ['a', 'sub', 'sup', 'b', 'i', 'u']
default: ['a', 'span', 'img', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd',
'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike',
'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']
items:
type: 'string'
description: "List of tags (defaults to inline) that should not be reformatted"