Skip to content

Commit 74033bd

Browse files
committed
style(linter/plugins): use prettier-ignore in test fixtures (#15602)
Follow-on after #15593 and #15600. Use `// prettier-ignore` comments in test fixture files to prevent them being formatted, where formatting would break the test.
1 parent 68703b9 commit 74033bd

File tree

5 files changed

+101
-99
lines changed

5 files changed

+101
-99
lines changed

apps/oxlint/test/fixtures/estree/files/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
let a = { x: y };
55

66
// No `ParenthesizedExpression`s in AST
7+
// prettier-ignore
78
const b = (x * ((('str' + ((123))))));
89

910
// TS syntax
1011
type T = string;
1112

1213
// No `TSParenthesizedType`s in AST
14+
// prettier-ignore
1315
type U = (((((string)) | ((number)))));

apps/oxlint/test/fixtures/estree/output.snap.md

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,35 @@
3838
4 | ,-> let a = { x: y };
3939
5 | |
4040
6 | | // No `ParenthesizedExpression`s in AST
41-
7 | | const b = (x * ((('str' + ((123))))));
42-
8 | |
43-
9 | | // TS syntax
44-
10 | | type T = string;
45-
11 | |
46-
12 | | // No `TSParenthesizedType`s in AST
47-
13 | `-> type U = (((((string)) | ((number)))));
41+
7 | | // prettier-ignore
42+
8 | | const b = (x * ((('str' + ((123))))));
43+
9 | |
44+
10 | | // TS syntax
45+
11 | | type T = string;
46+
12 | |
47+
13 | | // No `TSParenthesizedType`s in AST
48+
14 | | // prettier-ignore
49+
15 | `-> type U = (((((string)) | ((number)))));
4850
`----
4951
5052
x estree-check(check): program:
51-
| start/end: [37,243]
52-
| range: [37,243]
53-
| loc: [{"start":{"line":4,"column":0},"end":{"line":14,"column":0}}]
53+
| start/end: [37,281]
54+
| range: [37,281]
55+
| loc: [{"start":{"line":4,"column":0},"end":{"line":16,"column":0}}]
5456
,-[files/index.ts:4:1]
5557
3 | // All `Identifier`s
5658
4 | ,-> let a = { x: y };
5759
5 | |
5860
6 | | // No `ParenthesizedExpression`s in AST
59-
7 | | const b = (x * ((('str' + ((123))))));
60-
8 | |
61-
9 | | // TS syntax
62-
10 | | type T = string;
63-
11 | |
64-
12 | | // No `TSParenthesizedType`s in AST
65-
13 | `-> type U = (((((string)) | ((number)))));
61+
7 | | // prettier-ignore
62+
8 | | const b = (x * ((('str' + ((123))))));
63+
9 | |
64+
10 | | // TS syntax
65+
11 | | type T = string;
66+
12 | |
67+
13 | | // No `TSParenthesizedType`s in AST
68+
14 | | // prettier-ignore
69+
15 | `-> type U = (((((string)) | ((number)))));
6670
`----
6771
6872
x estree-check(check): ident "a":
@@ -99,45 +103,45 @@
99103
`----
100104
101105
x estree-check(check): ident "b":
102-
| start/end: [102,103]
103-
| range: [102,103]
104-
| loc: [{"start":{"line":7,"column":6},"end":{"line":7,"column":7}}]
105-
,-[files/index.ts:7:7]
106-
6 | // No `ParenthesizedExpression`s in AST
107-
7 | const b = (x * ((('str' + ((123))))));
106+
| start/end: [121,122]
107+
| range: [121,122]
108+
| loc: [{"start":{"line":8,"column":6},"end":{"line":8,"column":7}}]
109+
,-[files/index.ts:8:7]
110+
7 | // prettier-ignore
111+
8 | const b = (x * ((('str' + ((123))))));
108112
: ^
109-
8 |
113+
9 |
110114
`----
111115
112116
x estree-check(check): ident "x":
113-
| start/end: [107,108]
114-
| range: [107,108]
115-
| loc: [{"start":{"line":7,"column":11},"end":{"line":7,"column":12}}]
116-
,-[files/index.ts:7:12]
117-
6 | // No `ParenthesizedExpression`s in AST
118-
7 | const b = (x * ((('str' + ((123))))));
117+
| start/end: [126,127]
118+
| range: [126,127]
119+
| loc: [{"start":{"line":8,"column":11},"end":{"line":8,"column":12}}]
120+
,-[files/index.ts:8:12]
121+
7 | // prettier-ignore
122+
8 | const b = (x * ((('str' + ((123))))));
119123
: ^
120-
8 |
124+
9 |
121125
`----
122126
123127
x estree-check(check): ident "T":
124-
| start/end: [154,155]
125-
| range: [154,155]
126-
| loc: [{"start":{"line":10,"column":5},"end":{"line":10,"column":6}}]
127-
,-[files/index.ts:10:6]
128-
9 | // TS syntax
129-
10 | type T = string;
128+
| start/end: [173,174]
129+
| range: [173,174]
130+
| loc: [{"start":{"line":11,"column":5},"end":{"line":11,"column":6}}]
131+
,-[files/index.ts:11:6]
132+
10 | // TS syntax
133+
11 | type T = string;
130134
: ^
131-
11 |
135+
12 |
132136
`----
133137
134138
x estree-check(check): ident "U":
135-
| start/end: [208,209]
136-
| range: [208,209]
137-
| loc: [{"start":{"line":13,"column":5},"end":{"line":13,"column":6}}]
138-
,-[files/index.ts:13:6]
139-
12 | // No `TSParenthesizedType`s in AST
140-
13 | type U = (((((string)) | ((number)))));
139+
| start/end: [246,247]
140+
| range: [246,247]
141+
| loc: [{"start":{"line":15,"column":5},"end":{"line":15,"column":6}}]
142+
,-[files/index.ts:15:6]
143+
14 | // prettier-ignore
144+
15 | type U = (((((string)) | ((number)))));
141145
: ^
142146
`----
143147

apps/oxlint/test/fixtures/estree/plugin.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ const plugin: Plugin = {
3434
VariableDeclarator(decl) {
3535
// `init` should not be `ParenthesizedExpression`
3636
visits.push(`${decl.type}: (init: ${decl.init.type})`);
37-
38-
// Make sure the fixture hasn't been formatted by accident,
39-
// which would prevent this test from testing what it's meant to.
40-
// Formatter would remove all the parentheses.
41-
if (decl.id.type === 'Identifier' && decl.id.name === 'b') {
42-
assert(context.sourceCode.getText(decl) === "b = (x * ((('str' + ((123))))))");
43-
}
4437
},
4538
Identifier(ident) {
4639
// Check `loc` property returns same object each time it's accessed
@@ -75,13 +68,6 @@ const plugin: Plugin = {
7568
TSTypeAliasDeclaration(decl) {
7669
// `typeAnnotation` should not be `TSParenthesizedType`
7770
visits.push(`${decl.type}: (typeAnnotation: ${decl.typeAnnotation.type})`);
78-
79-
// Make sure the fixture hasn't been formatted by accident,
80-
// which would prevent this test from testing what it's meant to.
81-
// Formatter would remove all the parentheses.
82-
if (decl.id.name === 'U') {
83-
assert(context.sourceCode.getText(decl) === 'type U = (((((string)) | ((number)))));');
84-
}
8571
},
8672
'TSTypeAliasDeclaration:exit'(decl) {
8773
// `typeAnnotation` should not be `TSParenthesizedType`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
// prettier-ignore
12
noSpace=1;
23

4+
// prettier-ignore
35
singleSpaceBefore =2;
46

7+
// prettier-ignore
58
singleSpaceAfter= 3;
69

10+
// prettier-ignore
711
multipleSpaces = 4;
812

13+
// prettier-ignore
914
newlineBefore=
1015
5;
1116

17+
// prettier-ignore
1218
newlineAfter
1319
=6;
1420

21+
// prettier-ignore
1522
nested = 7 + 8;
1623

1724
// We should return `false` for `isSpaceBetween(beforeString, afterString)`, but we currently return `true`
25+
// prettier-ignore
1826
beforeString," ",afterString;

apps/oxlint/test/fixtures/isSpaceBetween/output.snap.md

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010
| isSpaceBetween(node, left): false
1111
| isSpaceBetween(right, node): false
1212
| isSpaceBetween(node, right): false
13-
,-[files/index.js:1:1]
14-
1 | noSpace=1;
13+
,-[files/index.js:2:1]
14+
1 | // prettier-ignore
15+
2 | noSpace=1;
1516
: ^^^^^^^^^
16-
2 |
17+
3 |
1718
`----
1819
1920
x test-plugin(is-space-between):
2021
| isSpaceBetween(leftExtended, right): false
2122
| isSpaceBetween(right, leftExtended): false
22-
,-[files/index.js:1:1]
23-
1 | noSpace=1;
23+
,-[files/index.js:2:1]
24+
1 | // prettier-ignore
25+
2 | noSpace=1;
2426
: ^^^^^^^^^
25-
2 |
27+
3 |
2628
`----
2729
2830
x test-plugin(is-space-between):
@@ -32,11 +34,11 @@
3234
| isSpaceBetween(node, left): false
3335
| isSpaceBetween(right, node): false
3436
| isSpaceBetween(node, right): false
35-
,-[files/index.js:3:1]
36-
2 |
37-
3 | singleSpaceBefore =2;
37+
,-[files/index.js:5:1]
38+
4 | // prettier-ignore
39+
5 | singleSpaceBefore =2;
3840
: ^^^^^^^^^^^^^^^^^^^^
39-
4 |
41+
6 |
4042
`----
4143
4244
x test-plugin(is-space-between):
@@ -46,11 +48,11 @@
4648
| isSpaceBetween(node, left): false
4749
| isSpaceBetween(right, node): false
4850
| isSpaceBetween(node, right): false
49-
,-[files/index.js:5:1]
50-
4 |
51-
5 | singleSpaceAfter= 3;
51+
,-[files/index.js:8:1]
52+
7 | // prettier-ignore
53+
8 | singleSpaceAfter= 3;
5254
: ^^^^^^^^^^^^^^^^^^^
53-
6 |
55+
9 |
5456
`----
5557
5658
x test-plugin(is-space-between):
@@ -60,12 +62,12 @@
6062
| isSpaceBetween(node, left): false
6163
| isSpaceBetween(right, node): false
6264
| isSpaceBetween(node, right): false
63-
,-[files/index.js:7:1]
64-
6 |
65-
7 | multipleSpaces = 4;
66-
: ^^^^^^^^^^^^^^^^^^^^^^
67-
8 |
68-
`----
65+
,-[files/index.js:11:1]
66+
10 | // prettier-ignore
67+
11 | multipleSpaces = 4;
68+
: ^^^^^^^^^^^^^^^^^^^^^^
69+
12 |
70+
`----
6971
7072
x test-plugin(is-space-between):
7173
| isSpaceBetween(left, right): true
@@ -74,11 +76,11 @@
7476
| isSpaceBetween(node, left): false
7577
| isSpaceBetween(right, node): false
7678
| isSpaceBetween(node, right): false
77-
,-[files/index.js:9:1]
78-
8 |
79-
9 | ,-> newlineBefore=
80-
10 | `-> 5;
81-
11 |
79+
,-[files/index.js:14:1]
80+
13 | // prettier-ignore
81+
14 | ,-> newlineBefore=
82+
15 | `-> 5;
83+
16 |
8284
`----
8385
8486
x test-plugin(is-space-between):
@@ -88,21 +90,21 @@
8890
| isSpaceBetween(node, left): false
8991
| isSpaceBetween(right, node): false
9092
| isSpaceBetween(node, right): false
91-
,-[files/index.js:12:1]
92-
11 |
93-
12 | ,-> newlineAfter
94-
13 | `-> =6;
95-
14 |
93+
,-[files/index.js:18:1]
94+
17 | // prettier-ignore
95+
18 | ,-> newlineAfter
96+
19 | `-> =6;
97+
20 |
9698
`----
9799
98100
x test-plugin(is-space-between):
99101
| isSpaceBetween(node, binaryLeft): false
100102
| isSpaceBetween(binaryLeft, node): false
101-
,-[files/index.js:15:1]
102-
14 |
103-
15 | nested = 7 + 8;
103+
,-[files/index.js:22:1]
104+
21 | // prettier-ignore
105+
22 | nested = 7 + 8;
104106
: ^^^^^^^^^^^^^^
105-
16 |
107+
23 |
106108
`----
107109
108110
x test-plugin(is-space-between):
@@ -112,19 +114,19 @@
112114
| isSpaceBetween(node, left): false
113115
| isSpaceBetween(right, node): false
114116
| isSpaceBetween(node, right): false
115-
,-[files/index.js:15:1]
116-
14 |
117-
15 | nested = 7 + 8;
117+
,-[files/index.js:22:1]
118+
21 | // prettier-ignore
119+
22 | nested = 7 + 8;
118120
: ^^^^^^^^^^^^^^
119-
16 |
121+
23 |
120122
`----
121123
122124
x test-plugin(is-space-between):
123125
| isSpaceBetween(beforeString, afterString): true
124126
| isSpaceBetween(afterString, beforeString): true
125-
,-[files/index.js:18:1]
126-
17 | // We should return `false` for `isSpaceBetween(beforeString, afterString)`, but we currently return `true`
127-
18 | beforeString," ",afterString;
127+
,-[files/index.js:26:1]
128+
25 | // prettier-ignore
129+
26 | beforeString," ",afterString;
128130
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129131
`----
130132

0 commit comments

Comments
 (0)