diff --git a/.gitignore b/.gitignore
index 28a2e04..a5282ff 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
node_modules
*.vsix
.vscodeignore
-typings
+.vscode-test
.vscode
-.jshintrc
\ No newline at end of file
+.jshintrc
+typings
diff --git a/.travis.yml b/.travis.yml
index 9ba38e4..d0fd497 100755
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,21 @@
-language: node_js
-node_js:
-- "4.1"
-- "stable"
+os:
+ - osx
+ - linux
+
+before_install:
+ - if [ $TRAVIS_OS_NAME == "linux" ]; then
+ export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
+ sh -e /etc/init.d/xvfb start;
+ sleep 3;
+ fi
+
+env:
+ - CODE_VERSION="0.10.1"
+ - CODE_VERSION="0.10.9"
+ - CODE_VERSION="1.0.0"
+
+install:
+ - npm install
+
+script:
+ - npm test --silent
\ No newline at end of file
diff --git a/README.md b/README.md
index ee581d5..a814135 100755
--- a/README.md
+++ b/README.md
@@ -55,6 +55,10 @@ If you wish to include the files that are included by default, set `"beautify.on
Embedded version of js-beautify is v1.6.2.
## Changes:
+### 0.1.3: 08 May 2016
+* Fix [Issue #14: Full file beautify doubles text on version 1.1.0](https://github.com/HookyQR/VSCodeBeautify/issues/11)
+* Add tests for supported formats and nested settings.
+
### 0.1.2: 20 Mar 2016
* Beautify with no .jsbeautifyrc file in path tree will use workspace settings for tabs/spaces indent. [Issue #11](https://github.com/HookyQR/VSCodeBeautify/issues/11)
Will use the editor setting if the file being beautified is visible, or workspace/user setting if it is not visible. (Beautify of a non-visible file can be envoked when beautify on save is enabled.)
diff --git a/extension.js b/extension.js
index c2005e5..7567b2f 100755
--- a/extension.js
+++ b/extension.js
@@ -12,7 +12,7 @@ const dumpError = e => {
const dropComments = inText => inText.replace(/(\/\*.*\*\/)|\/\/.*(?:[\r\n]|$)/g, "");
-const mergeOpts = function(opts, type) {
+const mergeOpts = function(opts, kind) {
const finOpts = {};
for (let a in opts) {
if (a !== 'js' && a !== 'html' && a !== 'css') {
@@ -20,10 +20,10 @@ const mergeOpts = function(opts, type) {
}
}
//merge in the per type settings
- if (type in opts) {
- for (let b in opts[type]) {
+ if (kind in opts) {
+ for (let b in opts[kind]) {
if (b === 'allowed_file_extensions') continue;
- finOpts[b] = opts[type][b];
+ finOpts[b] = opts[kind][b];
}
}
return finOpts;
@@ -64,9 +64,9 @@ const getBeautifyType = function(doc, dontAsk) {
});
if (vscode.languages.match(matcher, doc)) return "js";
}
- if (cfg.HTMLfiles.indexOf(type) + 1 || cfg.HTMLfiles.indexOf(type.slice(1)) + 1) return 'html';
- else if (cfg.CSSfiles.indexOf(type) + 1 || cfg.CSSfiles.indexOf(type.slice(1)) + 1) return 'css';
- else if (cfg.JSfiles.indexOf(type) + 1 || cfg.JSfiles.indexOf(type.slice(1)) + 1) return 'js';
+ if (cfg.HTMLfiles.includes(type) || cfg.HTMLfiles.includes(type.slice(1))) return 'html';
+ else if (cfg.CSSfiles.includes(type) || cfg.CSSfiles.includes(type.slice(1))) return 'css';
+ else if (cfg.JSfiles.includes(type) || cfg.JSfiles.includes(type.slice(1))) return 'js';
if (dontAsk) return;
return new Promise((resolve, reject) => {
@@ -178,10 +178,9 @@ function beautifyOnSave(doc) {
refType = getBeautifyType(doc, true);
if (!refType) return;
}
- if (cfg.onSave === true || (
- Array.isArray(cfg.onSave) && cfg.onSave.indexOf(refType) >= 0
- )) {
- const range = new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
+ if (cfg.onSave === true || (Array.isArray(cfg.onSave) && cfg.onSave.indexOf(refType) >= 0)) {
+ let range = new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
+ range = doc.validateRange(range);
//determine a default options
let defaultOptions = optionsFromFormat(vscode.workspace.getConfiguration('editor'));
//if this document is open, use the settings from that window
@@ -208,14 +207,14 @@ function activate(context) {
const active = vscode.window.activeTextEditor;
if (!active) return;
if (!active.document) return;
- const range = new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
-
- beautifyDoc(active.document, range, optionsFromFormat(active.options))
+ let range = new vscode.Range(0, 0, Number.MAX_VALUE, Number.MAX_VALUE);
+
+ range = active.document.validateRange(range);
+
+ return beautifyDoc(active.document, range, optionsFromFormat(active.options))
.then(newText => active.edit(editor => editor.replace(range, newText)), dumpError);
}));
- //VS Code won't allow the formatters to run for json, or js. The inbuild
- //js-beautify runs instead
context.subscriptions.push(
vscode.languages.registerDocumentRangeFormattingEditProvider('html', {
provideDocumentRangeFormattingEdits: rangeEditByType('html')
@@ -223,6 +222,8 @@ function activate(context) {
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider('css', {
provideDocumentRangeFormattingEdits: rangeEditByType('css')
}));
+ //VS Code won't allow the formatters to run for json, or js. The inbuild
+ //js-beautify runs instead
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider('javascript', {
provideDocumentRangeFormattingEdits: rangeEditByType('js')
}));
@@ -230,6 +231,5 @@ function activate(context) {
provideDocumentRangeFormattingEdits: rangeEditByType('js')
}));
vscode.workspace.onDidSaveTextDocument(beautifyOnSave);
-
}
exports.activate = activate;
diff --git a/package.json b/package.json
index bbd5597..5dc001f 100755
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "beautify",
"displayName": "beautify",
"description": "Beautify code in place for VS Code",
- "version": "0.1.2",
+ "version": "0.1.3",
"publisher": "HookyQR",
"engines": {
"vscode": "^0.10.1"
@@ -76,6 +76,14 @@
"js-beautify": "^1.6.2",
"minimatch": "^3.0.0"
},
+ "devDependencies": {
+ "vscode": "^0.11.x",
+ "mocha": "^2.4.5",
+ "expect.js": "~0.3.1"
+ },
+ "scripts": {
+ "test": "node ./node_modules/vscode/bin/test"
+ },
"repository": {
"type": "git",
"url": "https://github.com/HookyQR/VSCodeBeautify"
diff --git a/test/data/.jsbeautifyrc b/test/data/.jsbeautifyrc
new file mode 100644
index 0000000..6324cb8
--- /dev/null
+++ b/test/data/.jsbeautifyrc
@@ -0,0 +1,14 @@
+{
+ "indent_with_tabs": true,
+ "css": {
+ "selector_separator_newline": true
+ },
+ "js": {
+ "break_chained_methods": true,
+ "max_preserve_newlines": 2
+ },
+ "html": {
+ "brace_style": "none",
+ "preserve_newlines": false
+ }
+}
\ No newline at end of file
diff --git a/test/data/in.css b/test/data/in.css
new file mode 100644
index 0000000..afd3a4f
--- /dev/null
+++ b/test/data/in.css
@@ -0,0 +1 @@
+.a, #b{border: 1px solid green}
\ No newline at end of file
diff --git a/test/data/in.html b/test/data/in.html
new file mode 100644
index 0000000..c97c493
--- /dev/null
+++ b/test/data/in.html
@@ -0,0 +1,4 @@
+