@@ -38,7 +38,6 @@ def temp_document(doc_text, workspace):
38
38
name = temp_file .name
39
39
temp_file .write (doc_text )
40
40
doc = Document (uris .from_fs_path (name ), workspace )
41
-
42
41
return name , doc
43
42
44
43
@@ -118,21 +117,24 @@ def get_ruff_cfg_settings(workspace, doc, config_str):
118
117
119
118
def test_ruff_config (workspace ):
120
119
config_str = r"""[tool.ruff]
121
- ignore = ["F481 "]
120
+ ignore = ["F841 "]
122
121
exclude = [
123
- "blah",
122
+ "blah/__init__.py ",
124
123
"file_2.py"
125
124
]
126
125
[tool.ruff.per-file-ignores]
127
- "__init__.py" = ["F401", "E402"]
128
- "test_something.py" = ["E402"]
129
- """
126
+ "test_something.py" = ["F401"]
127
+ """
130
128
131
- doc_str = "print('hi')\n import os\n "
129
+ doc_str = r"""
130
+ print('hi')
131
+ import os
132
+ def f():
133
+ a = 2
134
+ """
132
135
133
- doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/ __init__.py" ))
136
+ doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "__init__.py" ))
134
137
workspace .put_document (doc_uri , doc_str )
135
- workspace ._config .update ({"plugins" : {"ruff" : {"select" : ["E" , "F" ]}}})
136
138
137
139
ruff_settings = get_ruff_cfg_settings (
138
140
workspace , workspace .get_document (doc_uri ), config_str
@@ -150,21 +152,52 @@ def test_ruff_config(workspace):
150
152
mock_instance .communicate .return_value = [bytes (), bytes ()]
151
153
152
154
doc = workspace .get_document (doc_uri )
153
- ruff_lint .pylsp_lint (workspace , doc )
155
+ diags = ruff_lint .pylsp_lint (workspace , doc )
154
156
155
157
call_args = popen_mock .call_args [0 ][0 ]
156
158
assert call_args == [
157
159
"ruff" ,
158
160
"--quiet" ,
159
161
"--format=json" ,
160
162
"--no-fix" ,
163
+ "--force-exclude" ,
164
+ "--stdin-filename" ,
165
+ os .path .join (workspace .root_path , "__init__.py" ),
161
166
"--" ,
162
167
"-" ,
163
168
]
164
169
165
170
diags = ruff_lint .pylsp_lint (workspace , doc )
166
171
172
+ _list = []
173
+ for diag in diags :
174
+ _list .append (diag ["code" ])
175
+ # Assert that ignore is working as intended
176
+ assert "E402" in _list
177
+ assert "F841" not in _list
178
+
179
+ # Excludes
180
+ doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
181
+ workspace .put_document (doc_uri , doc_str )
182
+
183
+ ruff_settings = get_ruff_cfg_settings (
184
+ workspace , workspace .get_document (doc_uri ), config_str
185
+ )
186
+
187
+ doc = workspace .get_document (doc_uri )
188
+ diags = ruff_lint .pylsp_lint (workspace , doc )
189
+ assert diags == []
190
+
191
+ # For per-file-ignores
192
+ doc_uri_per_file_ignores = uris .from_fs_path (
193
+ os .path .join (workspace .root_path , "blah/test_something.py" )
194
+ )
195
+ workspace .put_document (doc_uri_per_file_ignores , doc_str )
196
+
197
+ doc = workspace .get_document (doc_uri )
198
+ diags = ruff_lint .pylsp_lint (workspace , doc )
199
+
167
200
for diag in diags :
168
- assert diag ["code" ] != "F841 "
201
+ assert diag ["code" ] != "F401 "
169
202
170
203
os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
0 commit comments