File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,20 @@ def pylsp_lint(workspace, document):
31
31
per_file_ignores = settings .get ("perFileIgnores" )
32
32
33
33
if per_file_ignores :
34
+ prev_file_pat = None
34
35
for path in per_file_ignores :
35
- file_pat , errors = path .split (":" )
36
+ try :
37
+ file_pat , errors = path .split (":" )
38
+ prev_file_pat = file_pat
39
+ except ValueError :
40
+ # It's legal to just specify another error type for the same
41
+ # file pattern:
42
+ if prev_file_pat is None :
43
+ log .warning (
44
+ "skipping a Per-file-ignore with no file pattern" )
45
+ continue
46
+ file_pat = prev_file_pat
47
+ errors = path
36
48
if PurePath (document .path ).match (file_pat ):
37
49
ignores .extend (errors .split ("," ))
38
50
Original file line number Diff line number Diff line change @@ -158,3 +158,25 @@ def test_flake8_per_file_ignores(workspace):
158
158
assert not res
159
159
160
160
os .unlink (os .path .join (workspace .root_path , "setup.cfg" ))
161
+
162
+
163
+ def test_per_file_ignores_alternative_syntax (workspace ):
164
+ config_str = r"""[flake8]
165
+ per-file-ignores = **/__init__.py:F401,E402
166
+ """
167
+
168
+ doc_str = "print('hi')\n import os\n "
169
+
170
+ doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
171
+ workspace .put_document (doc_uri , doc_str )
172
+
173
+ flake8_settings = get_flake8_cfg_settings (workspace , config_str )
174
+
175
+ assert "perFileIgnores" in flake8_settings
176
+ assert len (flake8_settings ["perFileIgnores" ]) == 2
177
+
178
+ doc = workspace .get_document (doc_uri )
179
+ res = flake8_lint .pylsp_lint (workspace , doc )
180
+ assert not res
181
+
182
+ os .unlink (os .path .join (workspace .root_path , "setup.cfg" ))
You can’t perform that action at this time.
0 commit comments