microsoft / vscode-flake8

Linting support for python using the flake8 library.
https://marketplace.visualstudio.com/items?itemName=ms-python.flake8
MIT License
40 stars 30 forks source link

`ignorePatterns` setting not considered for non-workspace files #326

Closed taesungh closed 1 month ago

taesungh commented 1 month ago

The values in the ignorePatterns setting is not considered for files not in the current workspace.

Diagnostic Data

Behaviour

The patterns work for files in the workspace but not those outside.

Expected Behavior

A pattern specified in the flake8.ignorePatterns setting for the user (or remote) should be considered for any open file, either part of the workspace or not.

Actual Behavior

The patterns are not considered for files outside of the current workspace.

Reproduction Steps:

  1. Open a new Code window without opening a folder or workspace
  2. Add a pattern to the user settings for flake8.ignorePatterns, e.g. "*.py"
  3. Open a Python file that is not in the workspace but matches the pattern to be ignored
  4. Add some code that violates a lint rule, e.g. an unused import
  5. Observe that linting still runs on the file even though it should be ignored
  6. Open the folder containing the file in the Code window
  7. Observe that the pattern causes linting to be skipped ("Skipping file due to flake8.ignorePatterns match")
VS Code window showing a problem reported by Flake8 even though the file matches an ignore pattern in the user settings

Extra Details

My use case for this is related to a separate problem with detecting libraries in site-packages for which I'll submit a separate issue.

The culprit here seems to be lsp_server._get_global_defaults which does not check GLOBAL_SETTINGS for a default value unlike all other extension settings. This function is called by _get_settings_by_document when a file not in the workspace does not have a document key. Assuming this is just an oversight and not intentional, the fix should be fairly simple.

https://github.com/microsoft/vscode-flake8/blob/815cd6865364dba6cfd23aa05201d5423781d9fb/bundled/tool/lsp_server.py#L466-L468