@@ -116,25 +116,34 @@ def get_ruff_cfg_settings(workspace, doc, config_str):
116
116
return ruff_lint .load_config (workspace , doc )
117
117
118
118
119
- def test_ruff_multiline (workspace ):
119
+ def test_ruff_config (workspace ):
120
120
config_str = r"""[tool.ruff]
121
+ ignore = ["F481"]
121
122
exclude = [
122
123
"blah",
123
124
"file_2.py"
124
125
]
126
+ [tool.ruff.per-file-ignores]
127
+ "__init__.py" = ["F401", "E402"]
128
+ "test_something.py" = ["E402"]
125
129
"""
126
130
127
131
doc_str = "print('hi')\n import os\n "
128
132
129
133
doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
130
134
workspace .put_document (doc_uri , doc_str )
135
+ workspace ._config .update ({"plugins" : {"ruff" : {"select" : ["E" , "F" ]}}})
131
136
132
137
ruff_settings = get_ruff_cfg_settings (
133
138
workspace , workspace .get_document (doc_uri ), config_str
134
139
)
135
140
136
- assert "exclude" in ruff_settings
137
- assert len (ruff_settings ["exclude" ]) == 2
141
+ # Check that user config is ignored
142
+ for key , value in ruff_settings .items ():
143
+ if key == "executable" :
144
+ assert value == "ruff"
145
+ continue
146
+ assert value is None
138
147
139
148
with patch ("pylsp_ruff.ruff_lint.Popen" ) as popen_mock :
140
149
mock_instance = popen_mock .return_value
@@ -149,66 +158,13 @@ def test_ruff_multiline(workspace):
149
158
"--quiet" ,
150
159
"--format=json" ,
151
160
"--no-fix" ,
152
- "--exclude=blah,file_2.py" ,
153
161
"--" ,
154
162
"-" ,
155
163
]
156
164
157
- os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
158
-
159
-
160
- def test_ruff_per_file_ignores (workspace ):
161
- config_str = r"""[tool.ruff]
162
- ignore = ["F403"]
163
- exclude = [
164
- "file_1.py",
165
- "file_2.py",
166
- ]
167
- [tool.ruff.per-file-ignores]
168
- "__init__.py" = ["F401", "E402"]
169
- "test_something.py" = ["E402"]
170
- """
171
-
172
- doc_str = "print('hi')\n import os\n "
173
-
174
- doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
175
- workspace .put_document (doc_uri , doc_str )
176
-
177
- ruff_settings = get_ruff_cfg_settings (
178
- workspace , workspace .get_document (doc_uri ), config_str
179
- )
180
-
181
- assert "per-file-ignores" in ruff_settings
182
- assert len (ruff_settings ["per-file-ignores" ]) == 2
183
- assert "exclude" in ruff_settings
184
- assert len (ruff_settings ["exclude" ]) == 2
185
-
186
- doc = workspace .get_document (doc_uri )
187
- res = ruff_lint .pylsp_lint (workspace , doc )
188
- assert not res
189
-
190
- os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
191
-
192
-
193
- def test_per_file_ignores_alternative_syntax (workspace ):
194
- config_str = r"""[tool.ruff.per-file-ignores]
195
- "__init__.py" = ["F401", "E402"]
196
- """
197
-
198
- doc_str = "print('hi')\n import os\n "
199
-
200
- doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
201
- workspace .put_document (doc_uri , doc_str )
202
-
203
- ruff_settings = get_ruff_cfg_settings (
204
- workspace , workspace .get_document (doc_uri ), config_str
205
- )
206
-
207
- assert "per-file-ignores" in ruff_settings
208
- assert ruff_settings ["per-file-ignores" ] == {"__init__.py" : ["F401" , "E402" ]}
165
+ diags = ruff_lint .pylsp_lint (workspace , doc )
209
166
210
- doc = workspace .get_document (doc_uri )
211
- res = ruff_lint .pylsp_lint (workspace , doc )
212
- assert not res
167
+ for diag in diags :
168
+ assert diag ["code" ] != "F841"
213
169
214
170
os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
0 commit comments