Skip to content

Commit

Permalink
Add file extension options
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Hoekstra committed Dec 17, 2015
1 parent 0763e64 commit d296605
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 46 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

[![Build Status](https://api.travis-ci.org/HookyQR/VSCodeBeautify.svg?branch=master)](https://travis-ci.org/HookyQR/VSCodeBeautify)

VS Code has its own code formater. But it lacks the ability to modify the style you wish to use. This extension enables running [js-beautify](http://jsbeautifier.org/) in VS Code, and searches for `.jsbeautifyrc` file in the files path tree to load *your* code styling.
VS Code has its own code formater. But it lacks the ability to modify the style you wish to use. This extension enables running [js-beautify](http://jsbeautifier.org/) in VS Code, and searches for `.jsbeautifyrc` file in the files path tree to load *your* code styling. Run with **⌘⇧P** `Beautify`.

See [js-beautify on gitHub](https://github.com/beautify-web/js-beautify) for available options in the rc file. The file must be valid JSON to be used. Only the first file of the correct name found will be used. If the format is bad, the default js-beautify settings will be used.

Also runs http and css beautify from the same package, as determined by the file extension. If the file is unsaved, js-beautify will be attempted by default.

Extra file extenstion may be added under user or workspace settings.

Embeded version of js-beautify is v1.5.10.

## Changes:
### 0.0.2: 17 Dec 2015
* Add options for other file extensions.

15 changes: 10 additions & 5 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ function activate(context) {
var doBeautify = function (active, doc, opts) {
var better = doc.getText();
var type = doc.isUntitled ? "js" : doc.fileName.split('.').pop().toLowerCase();

if (type === 'htm' || type === 'html') better = beautify.html(better, opts);
else if (type === 'css') better = beautify.css(better, opts);
else if (type === 'js' || type === 'json') better = beautify.js(better, opts);
var cfg = vscode.workspace.getConfiguration('beautify');
if ( cfg.HTMLfiles.indexOf(type)+1){
better = beautify.html(better, opts);
}
else if (cfg.CSSfiles.indexOf(type)+1){
better = beautify.css(better, opts);
}
else if (cfg.JSfiles.indexOf(type)+1){
better = beautify.js(better, opts);
}
else return;

//get the whole file:
var range = new vscode.Range(new vscode.Position(0, 0), doc.positionAt(Infinity));
//and make the change:
Expand Down
14 changes: 7 additions & 7 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES6",
"noLib": true
},
"exclude": [
"node_modules"
]
"compilerOptions": {
"target": "ES6",
"noLib": true
},
"exclude": [
"node_modules"
]
}
85 changes: 52 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
{
"name": "beautify",
"displayName": "beautify",
"description": "Beautify code in place for VS Code",
"version": "0.0.1",
"publisher": "HookyQR",
"engines": {
"vscode": "^0.10.1"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:HookyQR.beautify"
],
"main": "./extension",
"contributes": {
"commands": [
{
"command": "HookyQR.beautify",
"title": "Beautify"
}
]
},
"devDependencies": {
"vscode": "0.10.x"
},
"dependencies": {
"js-beautify": "^1.5.0"
},
"repository": {
"type": "git",
"url": "https://github.com/HookyQR/VSCodeBeautify"
}
"name": "beautify",
"displayName": "beautify",
"description": "Beautify code in place for VS Code",
"version": "0.0.2",
"publisher": "HookyQR",
"engines": {
"vscode": "^0.10.1"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:HookyQR.beautify"
],
"main": "./extension",
"contributes": {
"commands": [{
"command": "HookyQR.beautify",
"title": "Beautify"
}],
"configuration": {
"type": "object",
"title": "Beautify config",
"properties": {
"beautify.JSfiles": {
"type": "array",
"default": ["js","json","jsbeautifyrc","jshintrc"],
"description": "File extensions that can be minified as javascript or JSON."
},
"beautify.HTMLfiles": {
"type": "array",
"default": ["htm","html"],
"description": "File extensions that can be minified as HTML."
},
"beautify.CSSfiles": {
"type": "array",
"default": ["css"],
"description": "File extensions that can be minified as CSS."
}
}
}
},
"devDependencies": {
"vscode": "0.10.x"
},
"dependencies": {
"js-beautify": "^1.5.0"
},
"repository": {
"type": "git",
"url": "https://github.com/HookyQR/VSCodeBeautify"
}
}

0 comments on commit d296605

Please sign in to comment.