Skip to content

Commit 8c332c7

Browse files
committed
Rename the files and update readme
1 parent c79e44f commit 8c332c7

8 files changed

+25
-183
lines changed

CHANGELOG.md

+10-125
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,21 @@
11
# Change Log
22
All notable changes to the "sort*js*object*keys" extension will be documented in this file.
33

4-
### [0.0.1]
4+
### [1.0.0]
55

6-
* Initial release of a testing version
7-
8-
* Add `Sort JS object keys` command
9-
10-
* Add `Sort JS object keys (Reverse)` command
11-
12-
### [0.0.3]
13-
14-
* Support ES6 shorthand object
15-
16-
e.g:
17-
```js
18-
{
19-
user,
20-
password
21-
}
22-
```
23-
Will be sorted to
24-
```js
25-
{
26-
password: password,
27-
user: user
28-
}
29-
```
30-
31-
* Support value which is multiple lines or have space in it.
6+
* Use babylon + babel/generator to parse and genertate the code
327

33-
e.g:
34-
```js
35-
{
36-
b: new String('b')
37-
.length,
38-
a: new String('a')
39-
}
40-
```
41-
Will be sorted to
42-
```js
43-
{
44-
a: new String('a'),
45-
b: new String('b').length
46-
}
47-
```
48-
* Will automatically add trailing comma if the prevs object has trailing comma
8+
* Support all the existing feature except:
9+
* Auto add tailing comma (Too much bugs for this feature)
10+
* End line comments (Babel can't parse it correctly)
4911

50-
e.g:
51-
```js
52-
{
53-
b: 'b',
54-
a: 'a'
55-
}
56-
```
57-
Will be sorted to
58-
```js
59-
{
60-
a: 'a',
61-
b: 'b'
62-
}
63-
```
64-
But this object which already has trailing comma:
65-
```js
66-
{
67-
b: 'b',
68-
a: 'a',
69-
}
70-
```
71-
Will be sorted to
72-
```js
73-
{
74-
a: 'a',
75-
b: 'b',
76-
}
77-
```
78-
### [0.0.6]
12+
### [0.0.x]
7913

80-
* Support Array in object
81-
82-
* Auto indent object if it is not in the first collumn
83-
84-
* Auto use ES6 short hand value
85-
86-
### [0.0.7]
87-
88-
* Support line comments in object
89-
90-
e.g:
91-
```js
92-
{
93-
b: 2,
94-
// some comment
95-
a: 1,
96-
// another comment
97-
d: 5,
98-
c: 4,
99-
}
100-
```
101-
Will be sorted to
102-
```js
103-
{
104-
// some comment
105-
a: 1,
106-
b: 2,
107-
c: 4,
108-
// another comment
109-
d: 5,
110-
}
111-
```
112-
113-
### [0.0.8]
14+
* Initial release of a testing version
11415

115-
* Fix an indent not correct bug
16+
* Add `Sort JS object keys` command
11617

117-
### [0.0.9]
18+
* Add `Sort JS object keys (Reverse)` command
11819

119-
* Support \' in string
20+
* Lots of feature in test version...
12021

121-
e.g:
122-
```js
123-
{
124-
b: 'test \'',
125-
c: 'test \' test',
126-
a: '\' test',
127-
}
128-
```
129-
Will be sorted to
130-
```js
131-
{
132-
a: '\' test',
133-
b: 'test \'',
134-
c: 'test \' test',
135-
}
136-
```

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ This is a VS code extension to alphabetically sort the keys in _selected_ js obj
44

55
## Reference
66

7-
Referred the source code from [Rich Somerfield](https://github.com/richie5um)'s extension
8-
[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.
7+
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
98

109
## Usage
1110

lib/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
var vscode = require('vscode');
2-
var sortJSON = require('./sort-json');
2+
var sortJSON = require('./sort-js-object');
33

44
function activate(context) {
55
var commands = [
6-
vscode.commands.registerCommand('sortJsObjectKeys.sortJsObjectKeys', sortJSON.sortNormal),
7-
vscode.commands.registerCommand('sortJsObjectKeys.sortJsObjectKeysReverse', sortJSON.sortReverse)
6+
vscode.commands.registerCommand(
7+
'sortJsObjectKeys.sortJsObjectKeys',
8+
sortJSON.sortNormal
9+
),
10+
vscode.commands.registerCommand(
11+
'sortJsObjectKeys.sortJsObjectKeysReverse',
12+
sortJSON.sortReverse
13+
),
814
];
915

10-
commands.forEach(function (command) {
16+
commands.forEach(function(command) {
1117
context.subscriptions.push(command);
1218
});
1319
}
File renamed without changes.

lib/sort-json.js renamed to lib/sort-js-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var vscode = require('vscode');
2-
var sorterCore = require('./sort-json-core');
2+
var sorterCore = require('./sort-js-object-core');
33

44
function getSelection(textEditor, startLine, startPos, endLine, endPos) {
55
var selectedLines = [];

lib/sort-json-utils.js

-18
This file was deleted.

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sort-js-object-keys",
33
"displayName": "Sort JS object keys",
44
"description": "An extension to sort the js object keys",
5-
"version": "0.0.12",
5+
"version": "1.0.0",
66
"publisher": "zengxingxin",
77
"engines": {
88
"vscode": "^1.12.0"
@@ -15,9 +15,7 @@
1515
"url": "https://github.com/SBeator/sort-js-object-keys/issues",
1616
"email": "[email protected]"
1717
},
18-
"categories": [
19-
"Other"
20-
],
18+
"categories": ["Other"],
2119
"activationEvents": [
2220
"onCommand:sortJsObjectKeys.sortJsObjectKeys",
2321
"onCommand:sortJsObjectKeys.sortJsObjectKeysReverse"

test/extension.test.js

+1-29
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var assert = require('assert');
1010

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

1515
suite('Extension Tests', function() {
1616
test('normal js object asc', function() {
@@ -244,34 +244,6 @@ suite('Extension Tests', function() {
244244
);
245245
});
246246

247-
// NOT suppot end line comments because babel not suppot it correctly
248-
// test('Support line comments at the end of the object', function() {
249-
// var jsObject = `{
250-
// b: 2,
251-
// // some comment
252-
// a: 1,
253-
// // another comment
254-
// d: 5,
255-
// c: 4,
256-
// // end comment
257-
// }`;
258-
259-
// var result = sorter.sort(jsObject, 4, ['asc'], {});
260-
261-
// assert.equal(
262-
// result,
263-
// `{
264-
// // some comment
265-
// a: 1,
266-
// b: 2,
267-
// c: 4,
268-
// // another comment
269-
// d: 5,
270-
// // end comment
271-
// }`
272-
// );
273-
// });
274-
275247
test("Support ' in string", function() {
276248
var jsObject = `{
277249
b: 'test \\'',

0 commit comments

Comments
 (0)