Python · 1527 bytes Raw Blame History
1 # LSP Test 7: Code Formatting (Ctrl+Shift+F)
2 # ==========================================
3 #
4 # Instructions:
5 # 1. Press Ctrl+Shift+F to format the entire file
6 # 2. The LSP server (ruff or black via pylsp) will reformat the code
7 # 3. Observe the changes in whitespace, line breaks, etc.
8 #
9 # This file has intentionally poor formatting for testing:
10
11 x=1+2+3
12 y = 4 * 5
13 z=x+y
14
15 def badly_formatted( a,b,c ):
16 return a+b+c
17
18 result=badly_formatted(1,2,3)
19
20 my_list=[1,2,3,4,5,6,7,8,9,10]
21 my_dict={"key1":"value1","key2":"value2","key3":"value3"}
22
23 class BadlyFormatted:
24 def __init__(self,x,y):
25 self.x=x
26 self.y=y
27 def method(self):
28 return self.x+self.y
29
30 if x>0:
31 print("positive")
32 elif x<0:
33 print("negative")
34 else:
35 print("zero")
36
37 for i in range(10):
38 if i%2==0:
39 print(i)
40
41 data=[{"name":"alice","age":30},{"name":"bob","age":25},{"name":"charlie","age":35}]
42
43 long_string="this is a very long string that should probably be wrapped or reformatted in some way by the formatter"
44
45 # Inconsistent quotes
46 single = 'single quotes'
47 double = "double quotes"
48 mixed = 'mixed' + "quotes"
49
50 # Extra blank lines
51
52
53
54 # and missing blank lines
55 def func1():
56 pass
57 def func2():
58 pass
59 def func3():
60 pass
61
62 # Trailing whitespace on next line (may not be visible):
63 x = 1
64
65 # Long function call
66 result = some_function_with_long_name(argument1, argument2, argument3, argument4, argument5, argument6)
67
68 # Lambda
69 f=lambda x:x*2
70
71 # Comprehension
72 squares=[x**2 for x in range(10)if x%2==0]