Skip to content

Commit

Permalink
Rename the files and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SBeator committed May 8, 2018
1 parent c79e44f commit 8c332c7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 183 deletions.
135 changes: 10 additions & 125 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,136 +1,21 @@
# Change Log
All notable changes to the "sort*js*object*keys" extension will be documented in this file.

### [0.0.1]
### [1.0.0]

* Initial release of a testing version

* Add `Sort JS object keys` command

* Add `Sort JS object keys (Reverse)` command

### [0.0.3]

* Support ES6 shorthand object

e.g:
```js
{
user,
password
}
```
Will be sorted to
```js
{
password: password,
user: user
}
```

* Support value which is multiple lines or have space in it.
* Use babylon + babel/generator to parse and genertate the code

e.g:
```js
{
b: new String('b')
.length,
a: new String('a')
}
```
Will be sorted to
```js
{
a: new String('a'),
b: new String('b').length
}
```
* Will automatically add trailing comma if the prevs object has trailing comma
* Support all the existing feature except:
* Auto add tailing comma (Too much bugs for this feature)
* End line comments (Babel can't parse it correctly)

e.g:
```js
{
b: 'b',
a: 'a'
}
```
Will be sorted to
```js
{
a: 'a',
b: 'b'
}
```
But this object which already has trailing comma:
```js
{
b: 'b',
a: 'a',
}
```
Will be sorted to
```js
{
a: 'a',
b: 'b',
}
```
### [0.0.6]
### [0.0.x]

* Support Array in object

* Auto indent object if it is not in the first collumn

* Auto use ES6 short hand value

### [0.0.7]

* Support line comments in object

e.g:
```js
{
b: 2,
// some comment
a: 1,
// another comment
d: 5,
c: 4,
}
```
Will be sorted to
```js
{
// some comment
a: 1,
b: 2,
c: 4,
// another comment
d: 5,
}
```

### [0.0.8]
* Initial release of a testing version

* Fix an indent not correct bug
* Add `Sort JS object keys` command

### [0.0.9]
* Add `Sort JS object keys (Reverse)` command

* Support \' in string
* Lots of feature in test version...

e.g:
```js
{
b: 'test \'',
c: 'test \' test',
a: '\' test',
}
```
Will be sorted to
```js
{
a: '\' test',
b: 'test \'',
c: 'test \' test',
}
```
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ This is a VS code extension to alphabetically sort the keys in _selected_ js obj

## Reference

Referred the source code from [Rich Somerfield](https://github.com/richie5um)'s extension
[vscode-sort-json](https://github.com/richie5um/vscode-sort-json), his extension can only sort JSON, I added new feature base on his extension so this extension can sort the JS object keys in source code.
Use [babylon](https://github.com/babel/babel/tree/master/packages/babylon) to parse the code, and sort the parsed code, then use [@babel/generator](https://github.com/babel/babel/tree/master/packages/babel-generator) to genertate the code back to document

## Usage

Expand Down
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
var vscode = require('vscode');
var sortJSON = require('./sort-json');
var sortJSON = require('./sort-js-object');

function activate(context) {
var commands = [
vscode.commands.registerCommand('sortJsObjectKeys.sortJsObjectKeys', sortJSON.sortNormal),
vscode.commands.registerCommand('sortJsObjectKeys.sortJsObjectKeysReverse', sortJSON.sortReverse)
vscode.commands.registerCommand(
'sortJsObjectKeys.sortJsObjectKeys',
sortJSON.sortNormal
),
vscode.commands.registerCommand(
'sortJsObjectKeys.sortJsObjectKeysReverse',
sortJSON.sortReverse
),
];

commands.forEach(function (command) {
commands.forEach(function(command) {
context.subscriptions.push(command);
});
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/sort-json.js → lib/sort-js-object.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var vscode = require('vscode');
var sorterCore = require('./sort-json-core');
var sorterCore = require('./sort-js-object-core');

function getSelection(textEditor, startLine, startPos, endLine, endPos) {
var selectedLines = [];
Expand Down
18 changes: 0 additions & 18 deletions lib/sort-json-utils.js

This file was deleted.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sort-js-object-keys",
"displayName": "Sort JS object keys",
"description": "An extension to sort the js object keys",
"version": "0.0.12",
"version": "1.0.0",
"publisher": "zengxingxin",
"engines": {
"vscode": "^1.12.0"
Expand All @@ -15,9 +15,7 @@
"url": "https://github.com/SBeator/sort-js-object-keys/issues",
"email": "star_yes@qq.com"
},
"categories": [
"Other"
],
"categories": ["Other"],
"activationEvents": [
"onCommand:sortJsObjectKeys.sortJsObjectKeys",
"onCommand:sortJsObjectKeys.sortJsObjectKeysReverse"
Expand Down
30 changes: 1 addition & 29 deletions test/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var assert = require('assert');

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
var sorter = require('../lib/sort-json-core');
var sorter = require('../lib/sort-js-object-core');

suite('Extension Tests', function() {
test('normal js object asc', function() {
Expand Down Expand Up @@ -244,34 +244,6 @@ suite('Extension Tests', function() {
);
});

// NOT suppot end line comments because babel not suppot it correctly
// test('Support line comments at the end of the object', function() {
// var jsObject = `{
// b: 2,
// // some comment
// a: 1,
// // another comment
// d: 5,
// c: 4,
// // end comment
// }`;

// var result = sorter.sort(jsObject, 4, ['asc'], {});

// assert.equal(
// result,
// `{
// // some comment
// a: 1,
// b: 2,
// c: 4,
// // another comment
// d: 5,
// // end comment
// }`
// );
// });

test("Support ' in string", function() {
var jsObject = `{
b: 'test \\'',
Expand Down

0 comments on commit 8c332c7

Please sign in to comment.