Skip to content

Commit

Permalink
Fixes #9. Nested options in .jsbeautifyrc are properly handled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Jun 14, 2014
1 parent b9d7869 commit 54e61a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/simple-jsbeautifyrc/.jsbeautifyrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": true,
"indent_handlebars": true
"indent_handlebars": true,
"object": {}
}
10 changes: 5 additions & 5 deletions examples/simple-jsbeautifyrc/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html>

<head>
<title>Test Page</title>
<title>Test Page</title>
</head>

<body>
<h1>Hello</h1>
<p>
World!
</p>
<h1>Hello</h1>
<p>
World!
</p>
</body>

</html>
9 changes: 7 additions & 2 deletions lib/atom-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ function beautify() {
var softTabs = editor.softTabs;
var tabLength = editor.getTabLength();

// Supported unique configuration keys
// Used for detecting nested configurations in .jsbeautifyrc
var languages = ['js', 'html', 'css', 'sql'];

var defaultOptions = {
'indent_size': softTabs ? tabLength : 1,
'indent_char': softTabs ? ' ' : '\t',
Expand All @@ -182,7 +186,7 @@ function beautify() {
encoding: 'utf8'
})));
} catch (e) {
console.log('Failed parsing config JSON at '+configPath);
console.log('Failed parsing config JSON at ' + configPath);
externalOptions = {};
}
} else {
Expand Down Expand Up @@ -218,7 +222,8 @@ function beautify() {

// Check to see if config file uses nested object format to split up js/css/html options
for (key in currOptions) {
if (typeof currOptions[key] === 'object') {
if (_.indexOf(languages, key) >= 0 && // Check if is supported language
typeof currOptions[key] === 'object') { // Check if nested object (more options in value)
containsNested = true;
break; // Found, break out of loop, no need to continue
}
Expand Down

0 comments on commit 54e61a8

Please sign in to comment.