Skip to content

Commit

Permalink
Merge pull request #2 from mrmlnc/vscode-1.3.0
Browse files Browse the repository at this point in the history
Merge after release VS Code v1.3.0
  • Loading branch information
mrmlnc authored Jul 7, 2016
2 parents 38db193 + 5d8c523 commit 06e9620
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 32 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# VS Code Post​CSS Sorting

> VS Code plugin to sort CSS rules content with specified order. Powered by [postcss-sorting](https://github.com/hudochenkov/postcss-sorting).
>
> Now works only with CSS and SCSS. Waiting support for [Less](https://github.com/webschik/postcss-less).
![2016-04-10_02-46-24](https://cloud.githubusercontent.com/assets/7034281/14407132/77dd07c4-fec6-11e5-8361-a47af434459c.gif)

Expand All @@ -12,7 +10,15 @@ To install, press `F1` and select `Extensions: Install Extensions` and then sear

## Usage

Press `F1` and run the command named `Post​CSS Sorting`.
Press `F1` and run the command named `Post​CSS Sorting: Run`.

## Supported languages

* CSS
* Less (experimental support)
* SCSS
* Sass (experimental and by [sass-indented](https://marketplace.visualstudio.com/items?itemName=robinbentley.sass-indented))
* Stylus (experimental, only indent-based CSS syntax and by [extensions](https://marketplace.visualstudio.com/search?term=stylu&target=VSCode&sortBy=Relevance))

## Keyboard shortcuts

Expand All @@ -21,19 +27,19 @@ For changes keyboard shortcuts, create a new rule in `File -> Preferences -> Key
```json
{
"key": "ctrl+shift+c",
"command": "PostCSSSorting.processEditor"
"command": "postcssSorting.sort"
}
```

## Options

You can override the default and user settings for individual projects. Just add an `PostCSSSorting` object to the `settings.json`file.
You can override the default and user settings for individual projects. Just add an `postcssSorting` object to the `settings.json`file.

For example:

```json
{
"PostCSSSorting": {
"postcssSorting": {
"sort-order": ["padding", "margin"],
"preserve-empty-lines-between-children-rules": true
}
Expand Down
33 changes: 20 additions & 13 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,41 @@
const vscode = require('vscode');
const postcss = require('postcss');
const sorting = require('postcss-sorting');
const scssSyntax = require('postcss-scss');

function getSyntax(language) {
switch (language) {
case 'less':
return require('postcss-less');
case 'scss':
return require('postcss-scss');
case 'sass-indented':
case 'sass':
case 'stylus':
return require('sugarss');
default:
return false;
}
}

function activate(context) {
const processEditor = vscode.commands.registerTextEditorCommand('PostCSSSorting.processEditor', (textEditor) => {
const processEditor = vscode.commands.registerTextEditorCommand('postcssSorting.sort', (textEditor) => {
const options = Object.assign({
'sort-order': 'default',
'empty-lines-between-children-rules': 0,
'empty-lines-between-media-rules': 0,
'preserve-empty-lines-between-children-rules': false
}, vscode.workspace.getConfiguration('PostCSSSorting'));
}, vscode.workspace.getConfiguration('postcssSorting'));

const document = textEditor.document;
const documentText = document.getText();
const lastLine = document.lineAt(document.lineCount - 1);
const selectAll = new vscode.Range(0, 0, lastLine.lineNumber, lastLine.range.end.character);

const lang = document.languageId || document._languageId;
const syntax = getSyntax(lang);

postcss([sorting(options)])
.process(documentText, lang === 'sass' && {
syntax: scssSyntax
})
.process(documentText, syntax && { syntax })
.then((result) => {
textEditor.edit((editBuilder) => {
editBuilder.replace(selectAll, result.css);
Expand All @@ -38,10 +52,3 @@ function activate(context) {
}

exports.activate = activate;

// this method is called when your extension is deactivated
function deactivate() {

}

exports.deactivate = deactivate;
12 changes: 9 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=759670
// for the documentation about the jsconfig.json format
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"target": "ES5",
"noLib": true
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
"node_modules",
"bower_components",
"jspm_packages",
"tmp",
"temp"
]
}
29 changes: 19 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@
"name": "vscode-postcss-sorting",
"displayName": "PostCSS Sorting",
"description": "VS Code plugin to sort CSS rules content with specified order.",
"version": "1.4.1",
"version": "2.0.0",
"publisher": "mrmlnc",
"engines": {
"vscode": "^0.10.10"
"vscode": "^1.3.0"
},
"icon": "icon.png",
"homepage": "https://github.com/mrmlnc/vscode-postcss-sorting",
"categories": [
"Other"
],
"keywords": [
"css",
"less",
"scss",
"sass",
"stylus"
],
"activationEvents": [
"onCommand:PostCSSSorting.processEditor"
"onCommand:postcssSorting.sort"
],
"main": "./extension.js",
"contributes": {
"commands": [{
"command": "PostCSSSorting.processEditor",
"title": "PostCSS Sorting"
"command": "postcssSorting.sort",
"title": "PostCSS Sorting: Run"
}],
"configuration": {
"type": "object",
"title": "PostCSSSorting configuration",
"title": "Post​CSS Sorting configuration",
"properties": {
"PostCSSSorting": {
"postcssSorting": {
"default": {},
"description": "Settings for PostCSS Sorting plugin"
}
Expand All @@ -37,9 +44,11 @@
"xo": "^0.16.0"
},
"dependencies": {
"postcss": "=5.0.21",
"postcss-scss": "=0.1.8",
"postcss-sorting": "=1.6.1"
"postcss": "5.0.21",
"postcss-scss": "0.1.8",
"postcss-less": "0.14.0",
"postcss-sorting": "1.6.1",
"sugarss": "0.1.4"
},
"scripts": {
"test": "xo"
Expand Down

0 comments on commit 06e9620

Please sign in to comment.