@@ -92,6 +92,62 @@ ruleTester.run("no-undef-init", rule, {
9292 output : "for(var i in [1,2,3]){let a; for(var j in [1,2,3]){}}" ,
9393 parserOptions : { ecmaVersion : 6 } ,
9494 errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
95+ } ,
96+
97+ // Should not autofix if it would remove comments
98+ {
99+ code : "let /* comment */a = undefined;" ,
100+ output : "let /* comment */a;" ,
101+ parserOptions : { ecmaVersion : 6 } ,
102+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
103+ } ,
104+ {
105+ code : "let a/**/ = undefined;" ,
106+ output : null ,
107+ parserOptions : { ecmaVersion : 6 } ,
108+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
109+ } ,
110+ {
111+ code : "let a /**/ = undefined;" ,
112+ output : null ,
113+ parserOptions : { ecmaVersion : 6 } ,
114+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
115+ } ,
116+ {
117+ code : "let a//\n= undefined;" ,
118+ output : null ,
119+ parserOptions : { ecmaVersion : 6 } ,
120+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
121+ } ,
122+ {
123+ code : "let a = /**/undefined;" ,
124+ output : null ,
125+ parserOptions : { ecmaVersion : 6 } ,
126+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
127+ } ,
128+ {
129+ code : "let a = //\nundefined;" ,
130+ output : null ,
131+ parserOptions : { ecmaVersion : 6 } ,
132+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
133+ } ,
134+ {
135+ code : "let a = undefined/* comment */;" ,
136+ output : "let a/* comment */;" ,
137+ parserOptions : { ecmaVersion : 6 } ,
138+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
139+ } ,
140+ {
141+ code : "let a = undefined/* comment */, b;" ,
142+ output : "let a/* comment */, b;" ,
143+ parserOptions : { ecmaVersion : 6 } ,
144+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
145+ } ,
146+ {
147+ code : "let a = undefined//comment\n, b;" ,
148+ output : "let a//comment\n, b;" ,
149+ parserOptions : { ecmaVersion : 6 } ,
150+ errors : [ { message : "It's not necessary to initialize 'a' to undefined." , type : "VariableDeclarator" } ]
95151 }
96152 ]
97153} ) ;
0 commit comments