Closed
Description
Complained in #4901 (comment)
Take this code for example (from that PR):
{
code: `
class Data {
member<T extends unknown>() {}
}
`,
errors: [
{
data: { constraint: 'unknown', name: 'T' },
messageId: 'unnecessaryConstraint',
endColumn: 27,
column: 10,
line: 3,
suggestions: [
{
messageId: 'removeUnnecessaryConstraint',
output: `
class Data {
member<T>() {}
}
`,
},
],
},
],
},
The test fails, suggesting that:
Expected value to strictly be equal to:
"
class Data {
member<T>() {}
}
"
Received:
"
class Data {
member<T>() {}
}
"
Okay, let's try another way by indenting everything—maybe it will be dedented? (Spoiler: I don't know how the snapshot works.)
{
code: `
class Data {
member<T extends unknown>() {}
}
`,
errors: [
{
data: { constraint: 'unknown', name: 'T' },
messageId: 'unnecessaryConstraint',
endColumn: 35,
column: 18,
line: 3,
suggestions: [
{
messageId: 'removeUnnecessaryConstraint',
output: `
class Data {
member<T>() {}
}
`,
},
],
},
],
},
- Expected
+ Received
- class Data {
- member<T>() {}
- }
-
+ class Data {
+ member<T>() {}
+ }
+
o_o
It turns out the only way to work around it is by either fighting the linter and adding ignore comments, or by using .trimEnd()
to each snapshot.
I think it's fine for the snapshots to be formatted nicely, so what about a sanitation step that removes all extraneous indentation, or removes trailing spaces (like .trimEnd()
)? I think ESLint's tests does that.