@@ -38,7 +38,6 @@ def temp_document(doc_text, workspace):
3838 name = temp_file .name
3939 temp_file .write (doc_text )
4040 doc = Document (uris .from_fs_path (name ), workspace )
41-
4241 return name , doc
4342
4443
@@ -118,21 +117,24 @@ def get_ruff_cfg_settings(workspace, doc, config_str):
118117
119118def test_ruff_config (workspace ):
120119 config_str = r"""[tool.ruff]
121- ignore = ["F481 "]
120+ ignore = ["F841 "]
122121exclude = [
123- "blah",
122+ "blah/__init__.py ",
124123 "file_2.py"
125124]
126125[tool.ruff.per-file-ignores]
127- "__init__.py" = ["F401", "E402"]
128- "test_something.py" = ["E402"]
129- """
126+ "test_something.py" = ["F401"]
127+ """
130128
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+ """
132135
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" ))
134137 workspace .put_document (doc_uri , doc_str )
135- workspace ._config .update ({"plugins" : {"ruff" : {"select" : ["E" , "F" ]}}})
136138
137139 ruff_settings = get_ruff_cfg_settings (
138140 workspace , workspace .get_document (doc_uri ), config_str
@@ -150,21 +152,52 @@ def test_ruff_config(workspace):
150152 mock_instance .communicate .return_value = [bytes (), bytes ()]
151153
152154 doc = workspace .get_document (doc_uri )
153- ruff_lint .pylsp_lint (workspace , doc )
155+ diags = ruff_lint .pylsp_lint (workspace , doc )
154156
155157 call_args = popen_mock .call_args [0 ][0 ]
156158 assert call_args == [
157159 "ruff" ,
158160 "--quiet" ,
159161 "--format=json" ,
160162 "--no-fix" ,
163+ "--force-exclude" ,
164+ "--stdin-filename" ,
165+ os .path .join (workspace .root_path , "__init__.py" ),
161166 "--" ,
162167 "-" ,
163168 ]
164169
165170 diags = ruff_lint .pylsp_lint (workspace , doc )
166171
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+
167200 for diag in diags :
168- assert diag ["code" ] != "F841 "
201+ assert diag ["code" ] != "F401 "
169202
170203 os .unlink (os .path .join (workspace .root_path , "pyproject.toml" ))
0 commit comments