@@ -92,6 +92,104 @@ ruleTester.run("prefer-numeric-literals", rule, {
9292errors :[ { message :"Use hexadecimal literals instead of Number.parseInt()." } ]
9393} ,
9494
95+ // Adjacent tokens tests
96+ {
97+ code :"parseInt('11', 2)" ,
98+ output :"0b11" ,
99+ errors :[ { message :"Use binary literals instead of parseInt()." } ]
100+ } ,
101+ {
102+ code :"Number.parseInt('67', 8)" ,
103+ output :"0o67" ,
104+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
105+ } ,
106+ {
107+ code :"5+parseInt('A', 16)" ,
108+ output :"5+0xA" ,
109+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
110+ } ,
111+ {
112+ code :"function *f(){ yield(Number).parseInt('11', 2) }" ,
113+ output :"function *f(){ yield 0b11 }" ,
114+ parserOptions :{ ecmaVersion :6 } ,
115+ errors :[ { message :"Use binary literals instead of (Number).parseInt()." } ]
116+ } ,
117+ {
118+ code :"function *f(){ yield(Number.parseInt)('67', 8) }" ,
119+ output :"function *f(){ yield 0o67 }" ,
120+ parserOptions :{ ecmaVersion :6 } ,
121+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
122+ } ,
123+ {
124+ code :"function *f(){ yield(parseInt)('A', 16) }" ,
125+ output :"function *f(){ yield 0xA }" ,
126+ parserOptions :{ ecmaVersion :6 } ,
127+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
128+ } ,
129+ {
130+ code :"function *f(){ yield Number.parseInt('11', 2) }" ,
131+ output :"function *f(){ yield 0b11 }" ,
132+ parserOptions :{ ecmaVersion :6 } ,
133+ errors :[ { message :"Use binary literals instead of Number.parseInt()." } ]
134+ } ,
135+ {
136+ code :"function *f(){ yield/**/Number.parseInt('67', 8) }" ,
137+ output :"function *f(){ yield/**/0o67 }" ,
138+ parserOptions :{ ecmaVersion :6 } ,
139+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
140+ } ,
141+ {
142+ code :"function *f(){ yield(parseInt('A', 16)) }" ,
143+ output :"function *f(){ yield(0xA) }" ,
144+ parserOptions :{ ecmaVersion :6 } ,
145+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
146+ } ,
147+ {
148+ code :"parseInt('11', 2)+5" ,
149+ output :"0b11+5" ,
150+ errors :[ { message :"Use binary literals instead of parseInt()." } ]
151+ } ,
152+ {
153+ code :"Number.parseInt('17', 8)+5" ,
154+ output :"0o17+5" ,
155+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
156+ } ,
157+ {
158+ code :"parseInt('A', 16)+5" ,
159+ output :"0xA+5" ,
160+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
161+ } ,
162+ {
163+ code :"parseInt('11', 2)in foo" ,
164+ output :"0b11 in foo" ,
165+ errors :[ { message :"Use binary literals instead of parseInt()." } ]
166+ } ,
167+ {
168+ code :"Number.parseInt('17', 8)in foo" ,
169+ output :"0o17 in foo" ,
170+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
171+ } ,
172+ {
173+ code :"parseInt('A', 16)in foo" ,
174+ output :"0xA in foo" ,
175+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
176+ } ,
177+ {
178+ code :"parseInt('11', 2) in foo" ,
179+ output :"0b11 in foo" ,
180+ errors :[ { message :"Use binary literals instead of parseInt()." } ]
181+ } ,
182+ {
183+ code :"Number.parseInt('17', 8)/**/in foo" ,
184+ output :"0o17/**/in foo" ,
185+ errors :[ { message :"Use octal literals instead of Number.parseInt()." } ]
186+ } ,
187+ {
188+ code :"(parseInt('A', 16))in foo" ,
189+ output :"(0xA)in foo" ,
190+ errors :[ { message :"Use hexadecimal literals instead of parseInt()." } ]
191+ } ,
192+
95193// Should not autofix if it would remove comments
96194{
97195code :"/* comment */Number.parseInt('11', 2);" ,