Debian Codegraph @

tests/data/cases/remove_newline_after_code_block_open.py

raw
1 import random
2
3
4 def foo1():
5
6 print("The newline above me should be kept!")
7
8
9 def foo2():
10
11
12
13 print("All the newlines above me should be kept!")
14
15
16 def foo3():
17
18 print("No newline above me!")
19
20 print("There is a newline above me, and that's OK!")
21
22
23 def foo4():
24
25 # There is a comment here
26
27 print("The newline above me should not be deleted!")
28
29
30 class Foo:
31 def bar(self):
32
33 print("The newline above me should be kept!")
34
35
36 for i in range(5):
37
38 print(f"{i}) The line above me should be kept!")
39
40
41 for i in range(5):
42
43
44
45 print(f"{i}) The lines above me should be kept!")
46
47
48 for i in range(5):
49
50 for j in range(7):
51
52 print(f"{i}) The lines above me should be kept!")
53
54
55 if random.randint(0, 3) == 0:
56
57 print("The new line above me will be kept!")
58
59
60 if random.randint(0, 3) == 0:
61
62
63
64
65 print("The new lines above me will be kept!")
66
67
68 if random.randint(0, 3) == 0:
69
70 if random.uniform(0, 1) > 0.5:
71
72 print("Two lines above me will be kept!")
73
74
75 while True:
76
77 print("The newline above me should be kept!")
78
79
80 while True:
81
82
83
84 print("The newlines above me should be kept!")
85
86
87 while True:
88
89 while False:
90
91 print("The newlines above me should be kept!")
92
93
94 with open("/path/to/file.txt", mode="w") as file:
95
96 file.write("The new line above me will be kept!")
97
98
99 with open("/path/to/file.txt", mode="w") as file:
100
101
102
103 file.write("The new lines above me will be kept!")
104
105
106 with open("/path/to/file.txt", mode="r") as read_file:
107
108 with open("/path/to/output_file.txt", mode="w") as write_file:
109
110 write_file.writelines(read_file.readlines())
111
112 # output
113
114 import random
115
116
117 def foo1():
118
119 print("The newline above me should be kept!")
120
121
122 def foo2():
123
124 print("All the newlines above me should be kept!")
125
126
127 def foo3():
128
129 print("No newline above me!")
130
131 print("There is a newline above me, and that's OK!")
132
133
134 def foo4():
135
136 # There is a comment here
137
138 print("The newline above me should not be deleted!")
139
140
141 class Foo:
142 def bar(self):
143
144 print("The newline above me should be kept!")
145
146
147 for i in range(5):
148
149 print(f"{i}) The line above me should be kept!")
150
151
152 for i in range(5):
153
154 print(f"{i}) The lines above me should be kept!")
155
156
157 for i in range(5):
158
159 for j in range(7):
160
161 print(f"{i}) The lines above me should be kept!")
162
163
164 if random.randint(0, 3) == 0:
165
166 print("The new line above me will be kept!")
167
168
169 if random.randint(0, 3) == 0:
170
171 print("The new lines above me will be kept!")
172
173
174 if random.randint(0, 3) == 0:
175
176 if random.uniform(0, 1) > 0.5:
177
178 print("Two lines above me will be kept!")
179
180
181 while True:
182
183 print("The newline above me should be kept!")
184
185
186 while True:
187
188 print("The newlines above me should be kept!")
189
190
191 while True:
192
193 while False:
194
195 print("The newlines above me should be kept!")
196
197
198 with open("/path/to/file.txt", mode="w") as file:
199
200 file.write("The new line above me will be kept!")
201
202
203 with open("/path/to/file.txt", mode="w") as file:
204
205 file.write("The new lines above me will be kept!")
206
207
208 with open("/path/to/file.txt", mode="r") as read_file:
209
210 with open("/path/to/output_file.txt", mode="w") as write_file:
211
212 write_file.writelines(read_file.readlines())