Skip to content

ignorePatterns setting not considered for non-workspace files #326

@taesungh

Description

@taesungh

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

Diagnostic Data

  • Python version: 3.12.4
  • Type of virtual environment used: none
  • Operating system: macOS 12.6.9
  • Version of tool extension you are using: Flake8 v2023.10.0

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.

"ignorePatterns": [],
"importStrategy": GLOBAL_SETTINGS.get("importStrategy", "useBundled"),
"showNotifications": GLOBAL_SETTINGS.get("showNotifications", "off"),

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bugtriage-needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions