@@ -6,16 +6,17 @@ import { TestHelper } from './TestHelper';
66describe ( 'noCommentedOutCodeRule' , ( ) :void => {
77const ruleName :string = 'no-commented-out-code' ;
88
9- it ( 'should pass on single word' , ( ) :void => {
10- const script :string = `
9+ context ( 'when inside inline comment' , ( ) :void => {
10+ it ( 'should pass on single word' , ( ) :void => {
11+ const script :string = `
1112 // lorem
12- ` ;
13+ `;
1314
14- TestHelper . assertNoViolation ( ruleName , script ) ;
15- } ) ;
15+ TestHelper . assertNoViolation ( ruleName , script ) ;
16+ } ) ;
1617
17- it ( 'should pass oninline comment ' , ( ) :void => {
18- const script :string = `
18+ it ( 'should pass onmultiple words ' , ( ) :void => {
19+ const script :string = `
1920 // Lorem ipsum dolor sit
2021
2122 const obj = {
@@ -25,71 +26,97 @@ describe('noCommentedOutCodeRule', (): void => {
2526 // Lorem ipsum dolor sit
2627 baz: true
2728 }
28- ` ;
29+ `;
2930
30- TestHelper . assertNoViolation ( ruleName , script ) ;
31- } ) ;
31+ TestHelper . assertNoViolation ( ruleName , script ) ;
32+ } ) ;
3233
33- it ( 'should fail on commented-out code with inline comment ' , ( ) :void => {
34- const script :string = `
34+ it ( 'should fail on commented-out code' , ( ) :void => {
35+ const script :string = `
3536 // console.log("Lorem ipsum");
36- ` ;
37-
38- TestHelper . assertViolations ( ruleName , script , [
39- noCommentedOutCodeError ( {
40- character :13 ,
41- line :2 ,
42- } ) ,
43- ] ) ;
37+ ` ;
38+
39+ TestHelper . assertViolations ( ruleName , script , [
40+ noCommentedOutCodeError ( {
41+ character :13 ,
42+ line :2 ,
43+ } ) ,
44+ ] ) ;
45+ } ) ;
4446} ) ;
4547
46- it ( 'should pass on block comments' , ( ) :void => {
47- const script :string = `
48+ context ( 'when inside block comment' , ( ) :void => {
49+ it ( 'should pass on single word' , ( ) :void => {
50+ const script :string = `
4851 /*
49- Lorem ipsum dolor sit
52+ lorem
5053 */
5154
52- /*Lorem ipsum dolor sit */
55+ /*lorem */
5356 ` ;
57+ TestHelper . assertNoViolation ( ruleName , script ) ;
58+ } ) ;
5459
55- TestHelper . assertNoViolation ( ruleName , script ) ;
56- } ) ;
60+ it ( 'should pass on multiple words' , ( ) :void => {
61+ const script :string = `
62+ /*
63+ Lorem ipsum dolor sit
64+ */
65+
66+ /* Lorem ipsum dolor sit */
67+ ` ;
5768
58- it ( 'should fail on commented-out code with block comments' , ( ) :void => {
59- const script :string = `
69+ TestHelper . assertNoViolation ( ruleName , script ) ;
70+ } ) ;
71+
72+ it ( 'should fail on commented-out code' , ( ) :void => {
73+ const script :string = `
6074 /*
6175 console.log("Lorem ipsum");
6276 */
6377
6478 /* console.log("Lorem ipsum"); */
65- ` ;
66-
67- TestHelper . assertViolations ( ruleName , script , [
68- noCommentedOutCodeError ( {
69- character :13 ,
70- line :2 ,
71- } ) ,
72- noCommentedOutCodeError ( {
73- character :13 ,
74- line :6 ,
75- } ) ,
76- ] ) ;
79+ ` ;
80+
81+ TestHelper . assertViolations ( ruleName , script , [
82+ noCommentedOutCodeError ( {
83+ character :13 ,
84+ line :2 ,
85+ } ) ,
86+ noCommentedOutCodeError ( {
87+ character :13 ,
88+ line :6 ,
89+ } ) ,
90+ ] ) ;
91+ } ) ;
7792} ) ;
7893
79- it ( 'should pass on JSDoc-style block comment' , ( ) :void => {
80- const script :string = `
94+ context ( 'when inside JSDoc-style block comment' , ( ) :void => {
95+ it ( 'should pass on single word' , ( ) :void => {
96+ const script :string = `
8197 /**
98+ * lorem
99+ */
100+
101+ /** lorem */
102+ ` ;
103+ TestHelper . assertNoViolation ( ruleName , script ) ;
104+ } ) ;
105+
106+ it ( 'should pass on multiple words' , ( ) :void => {
107+ const script :string = `
108+ /**
82109 * Lorem ipsum dolor sit
83110 */
84111
85112 /** Lorem ipsum dolor sit */
86- ` ;
113+ `;
87114
88- TestHelper . assertNoViolation ( ruleName , script ) ;
89- } ) ;
115+ TestHelper . assertNoViolation ( ruleName , script ) ;
116+ } ) ;
90117
91- it ( 'should pass on JSDoc with tags' , ( ) :void => {
92- const script :string = `
118+ it ( 'should pass on JSDoc with tags' , ( ) :void => {
119+ const script :string = `
93120 /**
94121 * @constructor
95122 */
@@ -109,61 +136,65 @@ describe('noCommentedOutCodeRule', (): void => {
109136 */
110137 ` ;
111138
112- TestHelper . assertNoViolation ( ruleName , script ) ;
113- } ) ;
139+ TestHelper . assertNoViolation ( ruleName , script ) ;
140+ } ) ;
114141
115- it ( 'should fail on commented-out code with JSDoc-style block comment ' , ( ) :void => {
116- const script :string = `
142+ it ( 'should fail on commented-out code' , ( ) :void => {
143+ const script :string = `
117144 /**
118145 * console.log("Lorem ipsum");
119146 */
120147
121148 /** console.log("Lorem ipsum"); */
122149 ` ;
123150
124- TestHelper . assertViolations ( ruleName , script , [
125- noCommentedOutCodeError ( {
126- character :13 ,
127- line :2 ,
128- } ) ,
129- noCommentedOutCodeError ( {
130- character :13 ,
131- line :6 ,
132- } ) ,
133- ] ) ;
151+ TestHelper . assertViolations ( ruleName , script , [
152+ noCommentedOutCodeError ( {
153+ character :13 ,
154+ line :2 ,
155+ } ) ,
156+ noCommentedOutCodeError ( {
157+ character :13 ,
158+ line :6 ,
159+ } ) ,
160+ ] ) ;
161+ } ) ;
134162} ) ;
135163
136- it ( 'should pass on tslint:disable comment' , ( ) :void => {
137- const script :string = `
164+ context ( 'when tslint comment' , ( ) :void => {
165+ it ( 'should pass on tslint:disable comment' , ( ) :void => {
166+ const script :string = `
138167 // tslint:disable:no-reserved-keywords
139- ` ;
168+ `;
140169
141- TestHelper . assertNoViolation ( ruleName , script ) ;
142- } ) ;
170+ TestHelper . assertNoViolation ( ruleName , script ) ;
171+ } ) ;
143172
144- it ( 'should pass on tslint:enable comment' , ( ) :void => {
145- const script :string = `
173+ it ( 'should pass on tslint:enable comment' , ( ) :void => {
174+ const script :string = `
146175 // tslint:enable:no-reserved-keywords
147- ` ;
176+ `;
148177
149- TestHelper . assertNoViolation ( ruleName , script ) ;
178+ TestHelper . assertNoViolation ( ruleName , script ) ;
179+ } ) ;
150180} ) ;
151181
152- it ( 'should allow commenting-out code if prefixed with uppercase TODO-like note' , ( ) :void => {
153- const script :string = `
182+ context ( 'when comment contains TODO-like note' , ( ) :void => {
183+ it ( 'should allow commenting-out code if prefixed with uppercase TODO-like note' , ( ) :void => {
184+ const script :string = `
154185 // TODO: a + b
155186 // NOTE: a + b
156187 // FIXME: a + b
157188 // BUG: a + b
158189 // HACK: a + b
159190 // XXX: a + b
160- ` ;
191+ `;
161192
162- TestHelper . assertNoViolation ( ruleName , script ) ;
163- } ) ;
193+ TestHelper . assertNoViolation ( ruleName , script ) ;
194+ } ) ;
164195
165- it ( 'should validate as usual if prefixed with unexpected TODO-like note' , ( ) :void => {
166- const script :string = `
196+ it ( 'should validate as usual if prefixed with unexpected TODO-like note' , ( ) :void => {
197+ const script :string = `
167198 // todo: a + b
168199 // ToDo: a + b
169200 // Foo: a + b
@@ -175,22 +206,23 @@ describe('noCommentedOutCodeRule', (): void => {
175206 // TODO(foo): a + b
176207 // TODO({foo: "bar"}) a + b
177208 // TODO({foo: "bar"}): a + b
178- ` ;
179-
180- TestHelper . assertViolations ( ruleName , script , [
181- noCommentedOutCodeError ( {
182- character :13 ,
183- line :2 ,
184- } ) ,
185- noCommentedOutCodeError ( {
186- character :13 ,
187- line :3 ,
188- } ) ,
189- noCommentedOutCodeError ( {
190- character :13 ,
191- line :4 ,
192- } ) ,
193- ] ) ;
209+ ` ;
210+
211+ TestHelper . assertViolations ( ruleName , script , [
212+ noCommentedOutCodeError ( {
213+ character :13 ,
214+ line :2 ,
215+ } ) ,
216+ noCommentedOutCodeError ( {
217+ character :13 ,
218+ line :3 ,
219+ } ) ,
220+ noCommentedOutCodeError ( {
221+ character :13 ,
222+ line :4 ,
223+ } ) ,
224+ ] ) ;
225+ } ) ;
194226} ) ;
195227} ) ;
196228