Skip to content

Commit da3f560

Browse files
committed
Revert "Add readable message for exception"
This reverts commit a9b6a11.
1 parent a9b6a11 commit da3f560

File tree

2 files changed

+16
-66
lines changed

2 files changed

+16
-66
lines changed

lib/sort-json-core.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,13 @@ function checkIfNeedTailingComma(objectString) {
180180
return objectString.match(/,[\s\t\n]*\}/);
181181
}
182182

183-
function checkIsObjectText(selectedText) {
184-
return (
185-
selectedText.length > 2 &&
186-
selectedText[0] === '{' &&
187-
selectedText[selectedText.length - 1] === '}'
188-
);
189-
}
190-
191183
function selectedTextToSortedText(
192184
selectedText,
193185
indent,
194186
jsonParser,
195187
sortOrder,
196188
sortOptions
197189
) {
198-
var isObejct = checkIsObjectText(selectedText);
199-
200-
if (!isObejct) {
201-
throw 'Please make sure your selected text is a JS obejct!';
202-
}
203-
204190
var autoIndent = getAutoIndent(selectedText, indent);
205191

206192
var marks = [];
@@ -215,15 +201,7 @@ function selectedTextToSortedText(
215201
console.log('marks');
216202
console.log(marks);
217203

218-
try {
219-
var initialJSON = sorter.textToJSON(jsonParser, json);
220-
} catch (e) {
221-
if (e.name == 'SyntaxError') {
222-
throw 'Please make sure your selected text is a JS obejct!';
223-
} else {
224-
throw e;
225-
}
226-
}
204+
var initialJSON = sorter.textToJSON(jsonParser, json);
227205
var sortedJSON = sorter.sortJSON(initialJSON, sortOrder, sortOptions);
228206

229207
var sortedJsonText = sorter.jsonToText(jsonParser, sortedJSON, indent);

test/extension.test.js

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var assert = require('assert');
1313
var sorter = require('../lib/sort-json-core');
1414
var JSON5 = require('json5');
1515

16-
suite('Extension Tests', function() {
17-
test('normal js object asc', function() {
16+
suite('Extension Tests', function () {
17+
test('normal js object asc', function () {
1818
var jsObject = `{
1919
user: 'user',
2020
aaa: 'aaa',
@@ -35,35 +35,7 @@ suite('Extension Tests', function() {
3535
);
3636
});
3737

38-
test('Not js object', function() {
39-
var jsObject = `aaa: 1`;
40-
41-
var result;
42-
try {
43-
result = sorter.sort(jsObject, 4, JSON5, ['asc'], {});
44-
} catch (e) {
45-
result = e;
46-
}
47-
48-
assert.equal(result, 'Please make sure your selected text is a JS obejct!');
49-
});
50-
51-
test('Not js object 2', function() {
52-
var jsObject = `{test('normal js object desc', function() {
53-
var jsObject = '';
54-
}`;
55-
56-
var result;
57-
try {
58-
result = sorter.sort(jsObject, 4, JSON5, ['asc'], {});
59-
} catch (e) {
60-
result = e;
61-
}
62-
63-
assert.equal(result, 'Please make sure your selected text is a JS obejct!');
64-
});
65-
66-
test('normal js object desc', function() {
38+
test('normal js object desc', function () {
6739
var jsObject = `{
6840
user: 'user',
6941
aaa: 'aaa',
@@ -84,7 +56,7 @@ suite('Extension Tests', function() {
8456
);
8557
});
8658

87-
test('normal js object indent 2', function() {
59+
test('normal js object indent 2', function () {
8860
var jsObject = `{
8961
user: 'user',
9062
aaa: 'aaa',
@@ -105,7 +77,7 @@ suite('Extension Tests', function() {
10577
);
10678
});
10779

108-
test('format js object', function() {
80+
test('format js object', function () {
10981
var jsObject = `{
11082
user : 'user',
11183
@@ -127,7 +99,7 @@ suite('Extension Tests', function() {
12799
);
128100
});
129101

130-
test('ES6 feature test', function() {
102+
test('ES6 feature test', function () {
131103
var jsObject = `{
132104
user: 'user',
133105
aaa,
@@ -148,7 +120,7 @@ suite('Extension Tests', function() {
148120
);
149121
});
150122

151-
test('Multi lines value test', function() {
123+
test('Multi lines value test', function () {
152124
var jsObject = `{
153125
b: new String('b')
154126
.length,
@@ -166,7 +138,7 @@ suite('Extension Tests', function() {
166138
);
167139
});
168140

169-
test('Auto add comma', function() {
141+
test('Auto add comma', function () {
170142
var jsObject = `{
171143
b: 'b',
172144
a: 'a',
@@ -183,7 +155,7 @@ suite('Extension Tests', function() {
183155
);
184156
});
185157

186-
test('Support line comments', function() {
158+
test('Support line comments', function () {
187159
var jsObject = `{
188160
b: 2,
189161
// some comment
@@ -208,7 +180,7 @@ suite('Extension Tests', function() {
208180
);
209181
});
210182

211-
test('Support line comments for indent 2', function() {
183+
test('Support line comments for indent 2', function () {
212184
var jsObject = `{
213185
b: 2,
214186
// some comment
@@ -233,7 +205,7 @@ suite('Extension Tests', function() {
233205
);
234206
});
235207

236-
test('Support line comments at the end of the object', function() {
208+
test('Support line comments at the end of the object', function () {
237209
var jsObject = `{
238210
b: 2,
239211
// some comment
@@ -260,7 +232,7 @@ suite('Extension Tests', function() {
260232
);
261233
});
262234

263-
test("Support ' in string", function() {
235+
test("Support ' in string", function () {
264236
var jsObject = `{
265237
b: 'test \\'',
266238
c: 'test \\' test',
@@ -279,7 +251,7 @@ suite('Extension Tests', function() {
279251
);
280252
});
281253

282-
test('Not change " in string ', function() {
254+
test('Not change " in string ', function () {
283255
var jsObject = `{
284256
d: "\\" test",
285257
b: 'test " test',
@@ -302,7 +274,7 @@ suite('Extension Tests', function() {
302274
);
303275
});
304276

305-
test('Support ES6 string key', function() {
277+
test('Support ES6 string key', function () {
306278
var jsObject = `{
307279
'b': 'test',
308280
a: 1,
@@ -322,4 +294,4 @@ suite('Extension Tests', function() {
322294
}`
323295
);
324296
});
325-
});
297+
});

0 commit comments

Comments
 (0)