vscode-flake8 icon indicating copy to clipboard operation
vscode-flake8 copied to clipboard

Flake8 does not applied arguments set in settings.json

Open xarpy opened this issue 8 months ago • 4 comments

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): Python 3.10.16
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): Pyenv
  • Operating system (and version): Ubuntu 22.04.5
  • Version of tool extension you are using: ms-python.flake8 2025.2.0

Behaviour

Expected Behavior

Flake8 recognizes the settings applied in the .args scope.

Actual Behavior

Flake8 does not recognize or apply the settings created settings.json

Reproduction Steps:

I apply the settings to settings.json and try to format and apply them to an existing codebase and save the file, but it doesn't work!

Image

Logs:

Click here for detailed logs 2025-03-06 09:13:32.102 [info] SUPPORTED flake8>=5.0.0 FOUND flake8==7.1.1

2025-03-06 09:13:32.107 [info] [Trace - 09:13:32] Sending request 'textDocument/codeAction - (1)'. 2025-03-06 09:13:32.111 [info] [Trace - 09:13:32] Received notification 'window/logMessage'. 2025-03-06 09:13:32.111 [info] /home/user/WorkSpace/project/personal/.venv/bin/python -m flake8 --format='%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s' /home/user/WorkSpace/project/personal/init.py 2025-03-06 09:13:32.111 [info] [Trace - 09:13:32] Received notification 'window/logMessage'. 2025-03-06 09:13:32.111 [info] CWD Linter: /home/user/WorkSpace/project/personal/ 2025-03-06 09:13:32.195 [info] [Trace - 09:13:32] Received notification 'window/logMessage'. 2025-03-06 09:13:32.195 [info] project/personal/init.py : '13,80,E,E501:line too long (91 > 79 characters)' '59,80,E,E501:line too long (98 > 79 characters)' '63,80,E,E501:line too long (83 > 79 characters)' '76,13,F,F541:f-string is missing placeholders' '85,13,F,F541:f-string is missing placeholders' '89,80,E,E501:line too long (89 > 79 characters)' '95,80,E,E501:line too long (82 > 79 characters)' '96,80,E,E501:line too long (94 > 79 characters)' '100,80,E,E501:line too long (83 > 79 characters)' '113,80,E,E501:line too long (82 > 79 characters)' '120,80,E,E501:line too long (86 > 79 characters)' '127,80,E,E501:line too long (82 > 79 characters)' '134,80,E,E501:line too long (81 > 79 characters)' '140,80,E,E501:line too long (82 > 79 characters)' '141,80,E,E501:line too long (88 > 79 characters)' '149,80,E,E501:line too long (95 > 79 characters)' '156,80,E,E501:line too long (82 > 79 characters)' '157,80,E,E501:line too long (104 > 79 characters)' '166,80,E,E501:line too long (89 > 79 characters)' '174,80,E,E501:line too long (82 > 79 characters)' '175,80,E,E501:line too long (84 > 79 characters)' '177,80,E,E501:line too long (83 > 79 characters)' '178,80,E,E501:line too long (83 > 79 characters)' '179,80,E,E501:line too long (89 > 79 characters)' '180,80,E,E501:line too long (96 > 79 characters)' '188,80,E,E501:line too long (82 > 79 characters)' '195,80,E,E501:line too long (91 > 79 characters)' '199,80,E,E501:line too long (97 > 79 characters)' '201,80,E,E501:line too long (82 > 79 characters)' '202,80,E,E501:line too long (86 > 79 characters)' '204,80,E,E501:line too long (83 > 79 characters)' '205,80,E,E501:line too long (90 > 79 characters)' '210,80,E,E501:line too long (81 > 79 characters)' '231,80,E,E501:line too long (92 > 79 characters)' '233,80,E,E501:line too long (82 > 79 characters)' '257,80,E,E501:line too long (98 > 79 characters)' '267,80,E,E501:line too long (82 > 79 characters)' '303,80,E,E501:line too long (81 > 79 characters)' '306,80,E,E501:line too long (100 > 79 characters)' '312,80,E,E501:line too long (85 > 79 characters)' '317,80,E,E501:line too long (87 > 79 characters)' '322,80,E,E501:line too long (84 > 79 characters)' '337,80,E,E501:line too long (87 > 79 characters)' '344,80,E,E501:line too long (91 > 79 characters)' '347,80,E,E501:line too long (82 > 79 characters)' '352,80,E,E501:line too long (87 > 79 characters)' '356,80,E,E501:line too long (89 > 79 characters)' '360,80,E,E501:line too long (90 > 79 characters)' '365,80,E,E501:line too long (82 > 79 characters)' '366,80,E,E501:line too long (89 > 79 characters)' '368,80,E,E501:line too long (83 > 79 characters)' '369,80,E,E501:line too long (83 > 79 characters)' '370,80,E,E501:line too long (89 > 79 characters)' '371,80,E,E501:line too long (96 > 79 characters)' '374,80,E,E501:line too long (87 > 79 characters)' '382,80,E,E501:line too long (91 > 79 characters)' '402,80,E,E501:line too long (82 > 79 characters)' '403,80,E,E501:line too long (81 > 79 characters)' '405,80,E,E501:line too long (83 > 79 characters)' '407,80,E,E501:line too long (89 > 79 characters)' '408,80,E,E501:line too long (96 > 79 characters)' '418,80,E,E501:line too long (85 > 79 characters)' '420,80,E,E501:line too long (91 > 79 characters)' '424,80,E,E501:line too long (94 > 79 characters)' '429,80,E,E501:line too long (82 > 79 characters)' '430,80,E,E501:line too long (83 > 79 characters)' '432,80,E,E501:line too long (83 > 79 characters)' '433,80,E,E501:line too long (83 > 79 characters)' '434,80,E,E501:line too long (89 > 79 characters)' '435,80,E,E501:line too long (96 > 79 characters)' '439,80,E,E501:line too long (87 > 79 characters)' '447,80,E,E501:line too long (88 > 79 characters)' '449,80,E,E501:line too long (100 > 79 characters)' '454,80,E,E501:line too long (85 > 79 characters)' '463,80,E,E501:line too long (82 > 79 characters)' '464,80,E,E501:line too long (93 > 79 characters)' '466,80,E,E501:line too long (83 > 79 characters)' '467,80,E,E501:line too long (83 > 79 characters)' '468,80,E,E501:line too long (96 > 79 characters)' '469,80,E,E501:line too long (87 > 79 characters)' '477,80,E,E501:line too long (103 > 79 characters)' '479,80,E,E501:line too long (83 > 79 characters)' '488,80,E,E501:line too long (94 > 79 characters)' '512,80,E,E501:line too long (84 > 79 characters)' '530,80,E,E501:line too long (99 > 79 characters)' '549,80,E,E501:line too long (85 > 79 characters)' '553,80,E,E501:line too long (83 > 79 characters)' '566,80,E,E501:line too long (83 > 79 characters)' '572,80,E,E501:line too long (85 > 79 characters)' '604,80,E,E501:line too long (88 > 79 characters)' '623,80,E,E501:line too long (86 > 79 characters)' '627,80,E,E501:line too long (87 > 79 characters)' '638,80,E,E501:line too long (92 > 79 characters)' '639,80,E,E501:line too long (89 > 79 characters)' '640,80,E,E501:line too long (87 > 79 characters)' '641,80,E,E501:line too long (98 > 79 characters)' '651,80,E,E501:line too long (96 > 79 characters)'

2025-03-06 09:13:32.199 [info] [Trace - 09:13:32] Received notification 'textDocument/publishDiagnostics'. 2025-03-06 09:13:32.203 [info] [Trace - 09:13:32] Received response 'textDocument/codeAction - (1)' in 96ms. 2025-03-06 09:13:32.453 [info] [Trace - 09:13:32] Sending request 'textDocument/codeAction - (2)'. 2025-03-06 09:13:32.458 [info] [Trace - 09:13:32] Received response 'textDocument/codeAction - (2)' in 5ms. 2025-03-06 09:13:50.900 [info] [Trace - 09:13:50] Sending request 'textDocument/codeAction - (3)'. 2025-03-06 09:13:50.904 [info] [Trace - 09:13:50] Received response 'textDocument/codeAction - (3)' in 4ms. 2025-03-06 09:13:51.712 [info] [Trace - 09:13:51] Sending request 'textDocument/codeAction - (4)'. 2025-03-06 09:13:51.719 [info] [Trace - 09:13:51] Received response 'textDocument/codeAction - (4)' in 7ms. 2025-03-06 09:13:52.830 [info] [Trace - 09:13:52] Sending request 'textDocument/codeAction - (5)'. 2025-03-06 09:13:52.834 [info] [Trace - 09:13:52] Received response 'textDocument/codeAction - (5)' in 4ms.

Outcome When Attempting Debugging Steps:

 flake8  /home/user/WorkSpace/project/personal/__init__.py --max-line-length=100 --indent-size=4 --ignore=E24,W504,W503,E203,E501,F405 --select=C,E,F,W,B,B9 --exclude=.git,.venv,__pycache__,.mypy_cache,.pytest_cache --verbose
flake8.checker            MainProcess     66 INFO     Making checkers
flake8.main.application   MainProcess    136 INFO     Finished running
flake8.main.application   MainProcess    136 INFO     Reporting errors
flake8.main.application   MainProcess    137 INFO     Found a total of 5 violations and reported 2
 /home/user/WorkSpace/project/personal/__init__.py:76:13: F541 f-string is missing placeholders
 /home/user/WorkSpace/project/personal/__init__.py:85:13: F541 f-string is missing placeholders

Did running it from the command line work? Yes

Extra Details

  • Follow my settings.json on vscode:
{
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "python.languageServer": "Pylance",
    "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
    "python.analysis.typeCheckingMode": "basic",
    "flake8.args": [
      "--max-line-length=100",
      "--indent-size=4",
      "--ignore=E24,W504,W503,E203,E501,F405",
      "--select=C,E,F,W,B,B9",
      "--exclude=.git,.venv,__pycache__,.mypy_cache,.pytest_cache",
      "--verbose",
    ],
    "black-formatter.args": [
       "--line-length",
       "100",
       "--exclude=.git,.venv,__pycache__,.mypy_cache,.pytest_cache",
    ],
    "isort.args": [
      "--atomic",
      "--profile=black",
      "--multi-line=3"
    ],
    "mypy-type-checker.severity":{"Warning": "Warning", "error": "Error", "note": "Information"},
    "mypy-type-checker.args": [
      "--strict",
      "--ignore-missing-imports",
      "--follow-imports=silent",
      "--show-column-numbers",
      "--disallow-untyped-defs",
      "--disallow-untyped-calls",
      "--allow-redefinition",
      "--exclude ^([a-zA-Z]*/tests/(.)*|tests)"
    ],
    "[python]": {
      "editor.rulers": [80, 100],
      "editor.formatOnSave": true,
      "editor.formatOnPaste": false,
      "editor.formatOnSaveMode": "file",
      "editor.defaultFormatter": "ms-python.black-formatter",
      "editor.codeActionsOnSave": {
        "source.organizeImports": "explicit"
      },
    },
    "yaml.format.enable": true,
    "python.testing.pytestArgs": [
      "tests"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
  }

And my vscode version:

Version: 1.97.2 Commit: e54c774e0add60467559eb0d1e229c6452cf8447 Date: 2025-02-12T23:20:35.343Z Electron: 32.2.7 ElectronBuildId: 10982180 Chromium: 128.0.6613.186 Node.js: 20.18.1 V8: 12.8.374.38-electron.0 OS: Linux x64 6.8.0-52-generic

This issue continues to exist, both for docstring and code level.

xarpy avatar Mar 06 '25 12:03 xarpy

I am not able to reproduce this locally with the latest version of the extension:

Image

In the logs, we send the args when the server starts. You should be able to find something like this:

Image

karthiknadig avatar Mar 12 '25 23:03 karthiknadig

I'm also affected by this issue.

I want to configure flake8 entirely through .vscode/settings.json without using .flake8, pyproject.toml, or other external config files. The main goal is to keep all project-specific linter settings inside the workspace settings file for better portability and IDE consistency.

However, flake8 in the current VSCode extension ignores my local flake8.args in .vscode/settings.json and uses global settings instead.

Here is my local workspace config (.vscode/settings.json):

{
  "[python]": {
    "editor.rulers": [88]
  },
  "ruff.lineLength": 88,
  "flake8.args": [
    "--max-line-length=22"
  ]
}

My global config (settings.json at the user level) looks like this:

{
  "flake8.args": [
    "--max-line-length=120",
    "--ignore=E203,E701,E704,F401,F405,W503,W605,SC100,SC200"
  ],
  "flake8.ignorePatterns": [
    "**/.venv/**",
    "**/__pycache__/**",
    "**/.mypy_cache/**",
    "**/.pytest_cache/**",
    "**/.ruff_cache/**"
  ]
}

Despite having --max-line-length=22 set locally, the extension continues to apply the global config (--max-line-length=120), as you can see from flake8 the logs below.

--- LOGS (personal paths redacted) ---

2025-07-10 12:45:34.195 [info] No interpreter found from setting flake8.interpreter
2025-07-10 12:45:34.195 [info] Getting interpreter from ms-python.python extension for workspace .../python-project
2025-07-10 12:45:34.196 [info] Interpreter from ms-python.python extension: .../python-project/.venv/bin/python
2025-07-10 12:45:34.221 [info] Server run command: .../python-project/.venv/bin/python .../ms-python.flake8-2025.2.0/bundled/tool/lsp_server.py
2025-07-10 12:45:34.528 [info] Settings used to run Server:
{
"cwd": ".../python-project",
"enabled": true,
"args": [
"--max-line-length=22"
],
...
}

2025-07-10 12:45:34.528 [info] Global settings:
{
"cwd": "${workspaceFolder}",
"enabled": true,
"args": [
"--max-line-length=120",
"--ignore=E203,E701,E704,F401,F405,W503,W605,SC100,SC200"
],
...
}

2025-07-10 12:45:34.616 [info] Executing command:
.../python-project/.venv/bin/python -m flake8 --format='%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s' --max-line-length=120 --ignore=E203,E701,E704,F401,F405,W503,W605,SC100,SC200 file.py

As you can see, even though the local workspace args are listed correctly in the Settings used to run Server, the command actually runs with the global args.

Expected behavior: The project-specific flake8.args in .vscode/settings.json should override any global settings.

About my VSCode:

Version: 1.101.2 (Universal)
Commit: 2901c5ac6db8a986a5666c3af51ff804d05af0d4
Date: 2025-06-24T20:27:15.391Z (2 wks ago)
Electron: 35.5.1
ElectronBuildId: 11727614
Chromium: 134.0.6998.205
Node.js: 22.15.1
V8: 13.4.114.21-electron.0
OS: Darwin arm64 24.5.0

RoTorEx avatar Jul 10 '25 10:07 RoTorEx

@RoTorEx This can happen if and when we try to see if the file belongs to a particular folder, in this case (python-project), and we see that it sits outside of the folder, then we use global settings. From the way the logs are presented, I cant see file.py belongs to python-project folder or not.

Different question: I see that you have ruff, you could just enable flake8 rules with ruff, so you don't have to use multiple extensions.

karthiknadig avatar Jul 10 '25 15:07 karthiknadig

I just want to add that I have the same issue. Arguments are not passed when using

    "flake8.enabled": true,
    "flake8.importStrategy": "useBundled",
    "flake8.args": [
        "--max-line-length=120"
    ],

Still flags problems at 80 characters.

BlueNoise avatar Oct 13 '25 19:10 BlueNoise