Skip to content

Commit 4d51667

Browse files
committed
chore: add version checking to some test cases
1 parent 644f97d commit 4d51667

File tree

1 file changed

+110
-33
lines changed

1 file changed

+110
-33
lines changed

Diff for: tests/lib/rules/no-implicit-coercion.js

+110-33
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55
'use strict'
66

7-
const RuleTester = require('../../eslint-compat').RuleTester
7+
const { RuleTester, ESLint } = require('../../eslint-compat')
8+
const semver = require('semver')
89
const rule = require('../../../lib/rules/no-implicit-coercion')
910

1011
const tester = new RuleTester({
@@ -38,7 +39,9 @@ tester.run('no-implicit-coercion', rule, {
3839
]
3940
},
4041
`<template><div :data-foo="Number(foo)" /></template>`,
41-
`<template><div :data-foo="foo * 1/4" /></template>`,
42+
...(semver.gte(ESLint.version, '8.28.0')
43+
? [`<template><div :data-foo="foo * 1/4" /></template>`]
44+
: []),
4245
{
4346
filename: 'test.vue',
4447
code: `<template><div :data-foo="+foo" /></template>`,
@@ -103,7 +106,9 @@ tester.run('no-implicit-coercion', rule, {
103106
output: `<template><div :data-foo="Boolean(foo)" /></template>`,
104107
errors: [
105108
{
106-
message: 'use `Boolean(foo)` instead.',
109+
message: semver.gte(ESLint.version, '9.0.0')
110+
? 'Unexpected implicit coercion encountered. Use `Boolean(foo)` instead.'
111+
: 'use `Boolean(foo)` instead.',
107112
line: 1,
108113
column: 27
109114
}
@@ -115,7 +120,9 @@ tester.run('no-implicit-coercion', rule, {
115120
output: null,
116121
errors: [
117122
{
118-
message: "use `foo.indexOf('.') !== -1` instead.",
123+
message: semver.gte(ESLint.version, '9.0.0')
124+
? "Unexpected implicit coercion encountered. Use `foo.indexOf('.') !== -1` instead."
125+
: "use `foo.indexOf('.') !== -1` instead.",
119126
line: 1,
120127
column: 27
121128
}
@@ -124,67 +131,137 @@ tester.run('no-implicit-coercion', rule, {
124131
{
125132
filename: 'test.vue',
126133
code: `<template><div :data-foo="+foo" /></template>`,
127-
output: `<template><div :data-foo="Number(foo)" /></template>`,
134+
output: semver.gte(ESLint.version, '9.0.0')
135+
? null
136+
: `<template><div :data-foo="Number(foo)" /></template>`,
128137
errors: [
129138
{
130-
message: 'use `Number(foo)` instead.',
139+
message: semver.gte(ESLint.version, '9.0.0')
140+
? 'Unexpected implicit coercion encountered. Use `Number(foo)` instead.'
141+
: 'use `Number(foo)` instead.',
131142
line: 1,
132-
column: 27
143+
column: 27,
144+
suggestions: semver.gte(ESLint.version, '9.0.0')
145+
? [
146+
{
147+
messageId: 'useRecommendation',
148+
data: { recommendation: 'Number(foo)' },
149+
output: '<template><div :data-foo="Number(foo)" /></template>'
150+
}
151+
]
152+
: []
133153
}
134154
]
135155
},
136156
{
137157
filename: 'test.vue',
138158
code: `<template><div :data-foo="1 * foo" /></template>`,
139-
output: `<template><div :data-foo="Number(foo)" /></template>`,
159+
output: semver.gte(ESLint.version, '9.0.0')
160+
? null
161+
: `<template><div :data-foo="Number(foo)" /></template>`,
140162
errors: [
141163
{
142-
message: 'use `Number(foo)` instead.',
164+
message: semver.gte(ESLint.version, '9.0.0')
165+
? 'Unexpected implicit coercion encountered. Use `Number(foo)` instead.'
166+
: 'use `Number(foo)` instead.',
143167
line: 1,
144-
column: 27
168+
column: 27,
169+
suggestions: semver.gte(ESLint.version, '9.0.0')
170+
? [
171+
{
172+
messageId: 'useRecommendation',
173+
data: { recommendation: 'Number(foo)' },
174+
output: '<template><div :data-foo="Number(foo)" /></template>'
175+
}
176+
]
177+
: []
145178
}
146179
]
147180
},
148181
{
149182
filename: 'test.vue',
150183
code: `<template><div :data-foo="'' + foo" /></template>`,
151-
output: `<template><div :data-foo="String(foo)" /></template>`,
184+
output: semver.gte(ESLint.version, '9.0.0')
185+
? null
186+
: `<template><div :data-foo="String(foo)" /></template>`,
152187
errors: [
153188
{
154-
message: 'use `String(foo)` instead.',
189+
message: semver.gte(ESLint.version, '9.0.0')
190+
? 'Unexpected implicit coercion encountered. Use `String(foo)` instead.'
191+
: 'use `String(foo)` instead.',
155192
line: 1,
156-
column: 27
193+
column: 27,
194+
suggestions: semver.gte(ESLint.version, '9.0.0')
195+
? [
196+
{
197+
messageId: 'useRecommendation',
198+
data: { recommendation: 'String(foo)' },
199+
output: '<template><div :data-foo="String(foo)" /></template>'
200+
}
201+
]
202+
: []
157203
}
158204
]
159205
},
160206
{
161207
filename: 'test.vue',
162208
code: `<template><div :data-foo="\`\` + foo" /></template>`,
163-
output: `<template><div :data-foo="String(foo)" /></template>`,
209+
output: semver.gte(ESLint.version, '9.0.0')
210+
? null
211+
: `<template><div :data-foo="String(foo)" /></template>`,
164212
errors: [
165213
{
166-
message: 'use `String(foo)` instead.',
214+
message: semver.gte(ESLint.version, '9.0.0')
215+
? 'Unexpected implicit coercion encountered. Use `String(foo)` instead.'
216+
: 'use `String(foo)` instead.',
167217
line: 1,
168-
column: 27
218+
column: 27,
219+
suggestions: semver.gte(ESLint.version, '9.0.0')
220+
? [
221+
{
222+
messageId: 'useRecommendation',
223+
data: { recommendation: 'String(foo)' },
224+
output: '<template><div :data-foo="String(foo)" /></template>'
225+
}
226+
]
227+
: []
169228
}
170229
]
171230
},
172-
{
173-
filename: 'test.vue',
174-
code: `<template><div :data-foo="\`\${foo}\`" /></template>`,
175-
output: `<template><div :data-foo="String(foo)" /></template>`,
176-
options: [
177-
{
178-
disallowTemplateShorthand: true
179-
}
180-
],
181-
errors: [
182-
{
183-
message: 'use `String(foo)` instead.',
184-
line: 1,
185-
column: 27
186-
}
187-
]
188-
}
231+
...(semver.gte(ESLint.version, '7.24.0')
232+
? [
233+
{
234+
filename: 'test.vue',
235+
code: `<template><div :data-foo="\`\${foo}\`" /></template>`,
236+
output: semver.gte(ESLint.version, '9.0.0')
237+
? null
238+
: `<template><div :data-foo="String(foo)" /></template>`,
239+
options: [
240+
{
241+
disallowTemplateShorthand: true
242+
}
243+
],
244+
errors: [
245+
{
246+
message: semver.gte(ESLint.version, '9.0.0')
247+
? 'Unexpected implicit coercion encountered. Use `String(foo)` instead.'
248+
: 'use `String(foo)` instead.',
249+
line: 1,
250+
column: 27,
251+
suggestions: semver.gte(ESLint.version, '9.0.0')
252+
? [
253+
{
254+
messageId: 'useRecommendation',
255+
data: { recommendation: 'String(foo)' },
256+
output:
257+
'<template><div :data-foo="String(foo)" /></template>'
258+
}
259+
]
260+
: []
261+
}
262+
]
263+
}
264+
]
265+
: [])
189266
]
190267
})

0 commit comments

Comments
 (0)