-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstdin-filepath.js
More file actions
151 lines (140 loc) · 3.48 KB
/
stdin-filepath.js
File metadata and controls
151 lines (140 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { runCli } from "../utils";
import dedent from "dedent";
describe("format correctly if stdin content compatible with stdin-filepath", () => {
runCli(
"",
["--stdin-filepath", "abc.css"],
{ input: ".name { display: none; }" }, // css
).test({
status: 0,
});
});
describe("throw error if stdin content incompatible with stdin-filepath", () => {
runCli(
"",
["--stdin-filepath", "abc.js"],
{ input: ".name { display: none; }" }, // css
).test({
status: "non-zero",
});
});
describe("gracefully handle stdin-filepath with nonexistent directory", () => {
runCli(
"",
["--stdin-filepath", "definitely/nonexistent/path.css"],
{ input: ".name { display: none; }" }, // css
).test({
status: 0,
});
});
describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
runCli("editorconfig", ["--stdin-filepath", "nonexistent.js"], {
input: dedent`
function f() {
console.log("should be indented with a tab");
}
`, // js
}).test({
status: 0,
});
});
describe("apply editorconfig for stdin-filepath with nonexistent directory", () => {
runCli(
"editorconfig",
["--stdin-filepath", "nonexistent/one/two/three.js"],
{
input: dedent`
function f() {
console.log("should be indented with a tab");
}
`, // js
},
).test({
status: 0,
});
});
describe("apply editorconfig for stdin-filepath with a deep path", () => {
runCli(
"editorconfig",
["--stdin-filepath", "a/".repeat(30) + "three.js"],
{
input: dedent`
function f() {
console.log("should be indented with a tab");
}
`, // js
},
).test({
status: 0,
});
});
// TODO: This is currently a false positive as no config actually gets resolved, but Prettier
// somehow formats the input correctly anyway.
describe("apply editorconfig for stdin-filepath in root", () => {
const code = dedent`
function f() {
console.log("should be indented with a tab");
}
`;
runCli("", ["--stdin-filepath", "/foo.js"], {
input: code, // js
}).test({
status: 0,
stdout: code,
stderr: "",
write: [],
});
});
describe("apply editorconfig for stdin-filepath with a deep path", () => {
runCli(
"editorconfig",
["--stdin-filepath", "a/".repeat(30) + "three.js"],
{
input: dedent`
function f() {
console.log("should be indented with a tab");
}
`, // js
},
).test({
status: 0,
});
});
// TODO: This is currently a false positive. Gotta investigate how it's handled in Prettier v3 to
// gauge the expected behavior.
describe("don't apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
runCli(
"",
[
"--stdin-filepath",
"editorconfig/repo-root/nonexistent/one/two/three.js",
],
{
input: dedent`
function f() {
console.log("should be indented with 2 spaces");
}
`, // js
},
).test({
status: 0,
});
});
describe("output file as-is if stdin-filepath matched patterns in ignore-path", () => {
runCli("stdin-ignore", ["--stdin-filepath", "ignore/example.js"], {
input: "hello_world( );",
}).test({
stdout: "hello_world( );",
status: 0,
});
});
describe("Should format stdin even if it's empty", () => {
runCli("", ["--stdin-filepath", "example.js"], {
isTTY: true,
}).test({
stdout: "",
status: 0,
stderr: "",
write: [],
});
});