@@ -116,25 +116,34 @@ def get_ruff_cfg_settings(workspace, doc, config_str):
116116 return ruff_lint .load_config (workspace , doc )
117117
118118
119- def test_ruff_multiline (workspace ):
119+ def test_ruff_config (workspace ):
120120 config_str = r"""[tool.ruff]
121+ ignore = ["F481"]
121122exclude = [
122123 "blah",
123124 "file_2.py"
124125]
126+ [tool.ruff.per-file-ignores]
127+ "__init__.py" = ["F401", "E402"]
128+ "test_something.py" = ["E402"]
125129 """
126130
127131 doc_str = "print('hi')\n import os\n "
128132
129133 doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
130134 workspace .put_document (doc_uri , doc_str )
135+ workspace ._config .update ({"plugins" : {"ruff" : {"select" : ["E" , "F" ]}}})
131136
132137 ruff_settings = get_ruff_cfg_settings (
133138 workspace , workspace .get_document (doc_uri ), config_str
134139 )
135140
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
138147
139148 with patch ("pylsp_ruff.ruff_lint.Popen" ) as popen_mock :
140149 mock_instance = popen_mock .return_value
@@ -149,66 +158,13 @@ def test_ruff_multiline(workspace):
149158 "--quiet" ,
150159 "--format=json" ,
151160 "--no-fix" ,
152- "--exclude=blah,file_2.py" ,
153161 "--" ,
154162 "-" ,
155163 ]
156164
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 )
209166
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"
213169
214170 os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
0 commit comments