@@ -44,36 +44,187 @@ ruleTester.run("no-empty", rule, {
4444 { code : "try { foo(); } catch (ex) {} finally { bar(); }" , options : [ { allowEmptyCatch : true } ] }
4545 ] ,
4646 invalid : [
47- { code : "try {} catch (ex) {throw ex}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
48- { code : "try { foo() } catch (ex) {}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
49- { code : "try { foo() } catch (ex) {throw ex} finally {}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
50- { code : "if (foo) {}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
51- { code : "while (foo) {}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
52- { code : "for (;foo;) {}" , errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ] } ,
53- { code : "switch(foo) {}" , errors : [ { messageId : "unexpected" , data : { type : "switch" } , type : "SwitchStatement" } ] } ,
47+ {
48+ code : "try {} catch (ex) {throw ex}" ,
49+ errors : [ {
50+ messageId : "unexpected" ,
51+ data : { type : "block" } ,
52+ type : "BlockStatement" ,
53+ suggestions : [ {
54+ messageId : "suggestComment" ,
55+ data : { type : "block" } ,
56+ output : "try { /* empty */ } catch (ex) {throw ex}"
57+ } ]
58+ } ]
59+ } ,
60+ {
61+ code : "try { foo() } catch (ex) {}" ,
62+ errors : [ {
63+ messageId : "unexpected" ,
64+ data : { type : "block" } ,
65+ type : "BlockStatement" ,
66+ suggestions : [ {
67+ messageId : "suggestComment" ,
68+ data : { type : "block" } ,
69+ output : "try { foo() } catch (ex) { /* empty */ }"
70+ } ]
71+ } ]
72+ } ,
73+ {
74+ code : "try { foo() } catch (ex) {throw ex} finally {}" ,
75+ errors : [ {
76+ messageId : "unexpected" ,
77+ data : { type : "block" } ,
78+ type : "BlockStatement" ,
79+ suggestions : [ {
80+ messageId : "suggestComment" ,
81+ data : { type : "block" } ,
82+ output : "try { foo() } catch (ex) {throw ex} finally { /* empty */ }"
83+ } ]
84+ } ]
85+ } ,
86+ {
87+ code : "if (foo) {}" ,
88+ errors : [ {
89+ messageId : "unexpected" ,
90+ data : { type : "block" } ,
91+ type : "BlockStatement" ,
92+ suggestions : [ {
93+ messageId : "suggestComment" ,
94+ data : { type : "block" } ,
95+ output : "if (foo) { /* empty */ }"
96+ } ]
97+ } ]
98+ } ,
99+ {
100+ code : "while (foo) {}" ,
101+ errors : [ {
102+ messageId : "unexpected" ,
103+ data : { type : "block" } ,
104+ type : "BlockStatement" ,
105+ suggestions : [ {
106+ messageId : "suggestComment" ,
107+ data : { type : "block" } ,
108+ output : "while (foo) { /* empty */ }"
109+ } ]
110+ } ]
111+ } ,
112+ {
113+ code : "for (;foo;) {}" ,
114+ errors : [ {
115+ messageId : "unexpected" ,
116+ data : { type : "block" } ,
117+ type : "BlockStatement" ,
118+ suggestions : [ {
119+ messageId : "suggestComment" ,
120+ data : { type : "block" } ,
121+ output : "for (;foo;) { /* empty */ }"
122+ } ]
123+ } ]
124+ } ,
125+ {
126+ code : "switch(foo) {}" ,
127+ errors : [ {
128+ messageId : "unexpected" ,
129+ data : { type : "switch" } ,
130+ type : "SwitchStatement" ,
131+ suggestions : null
132+ } ]
133+ } ,
134+ {
135+ code : "switch (foo) { /* empty */ }" ,
136+ errors : [ {
137+ messageId : "unexpected" ,
138+ data : { type : "switch" } ,
139+ type : "SwitchStatement" ,
140+ suggestions : null
141+ } ]
142+ } ,
54143 {
55144 code : "try {} catch (ex) {}" ,
56145 options : [ { allowEmptyCatch : true } ] ,
57- errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ]
146+ errors : [ {
147+ messageId : "unexpected" ,
148+ data : { type : "block" } ,
149+ type : "BlockStatement" ,
150+ suggestions : [ {
151+ messageId : "suggestComment" ,
152+ data : { type : "block" } ,
153+ output : "try { /* empty */ } catch (ex) {}"
154+ } ]
155+ } ]
58156 } ,
59157 {
60158 code : "try { foo(); } catch (ex) {} finally {}" ,
61159 options : [ { allowEmptyCatch : true } ] ,
62- errors : [ { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ]
160+ errors : [ {
161+ messageId : "unexpected" ,
162+ data : { type : "block" } ,
163+ type : "BlockStatement" ,
164+ suggestions : [ {
165+ messageId : "suggestComment" ,
166+ data : { type : "block" } ,
167+ output : "try { foo(); } catch (ex) {} finally { /* empty */ }"
168+ } ]
169+ } ]
63170 } ,
64171 {
65172 code : "try {} catch (ex) {} finally {}" ,
66173 options : [ { allowEmptyCatch : true } ] ,
67174 errors : [
68- { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ,
69- { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" }
175+ {
176+ messageId : "unexpected" ,
177+ data : { type : "block" } ,
178+ type : "BlockStatement" ,
179+ suggestions : [
180+ {
181+ messageId : "suggestComment" ,
182+ data : { type : "block" } ,
183+ output : "try { /* empty */ } catch (ex) {} finally {}"
184+ }
185+ ]
186+ } ,
187+ {
188+ messageId : "unexpected" ,
189+ data : { type : "block" } ,
190+ type : "BlockStatement" ,
191+ suggestions : [
192+ {
193+ messageId : "suggestComment" ,
194+ data : { type : "block" } ,
195+ output : "try {} catch (ex) {} finally { /* empty */ }"
196+ }
197+ ]
198+ }
70199 ]
71200 } ,
72201 {
73202 code : "try { foo(); } catch (ex) {} finally {}" ,
74203 errors : [
75- { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" } ,
76- { messageId : "unexpected" , data : { type : "block" } , type : "BlockStatement" }
204+ {
205+ messageId : "unexpected" ,
206+ data : { type : "block" } ,
207+ type : "BlockStatement" ,
208+ suggestions : [
209+ {
210+ messageId : "suggestComment" ,
211+ data : { type : "block" } ,
212+ output : "try { foo(); } catch (ex) { /* empty */ } finally {}"
213+ }
214+ ]
215+ } ,
216+ {
217+ messageId : "unexpected" ,
218+ data : { type : "block" } ,
219+ type : "BlockStatement" ,
220+ suggestions : [
221+ {
222+ messageId : "suggestComment" ,
223+ data : { type : "block" } ,
224+ output : "try { foo(); } catch (ex) {} finally { /* empty */ }"
225+ }
226+ ]
227+ }
77228 ]
78229 }
79230 ]
0 commit comments