astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.06k stars 53 forks source link

Unable to VSCode Auto-Fix onSave #410

Closed alexbot89 closed 7 months ago

alexbot89 commented 7 months ago

Having issues getting the auto-fix to work when saving, is there something I misconfigured? I see that the editor gives me an option to fix E711, but using ctrl+s does not auto-fix this.

The AutoFix command in command palette refuses to work as well.

In the logs it looks like the no-fix arg is used even though the settings.json is set to "always".

['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--stdin-filename', 'e:\\projects\\sandbox-py\\equality.py']

OS: Win11 23H2 Python: 3.12.2 VSCode: 1.86.2

settings.json

{
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.organizeImports": "always",
            "source.fixAll": "always"
        }
    }
}

equality.py

print(True == None)
print(False == None)
print(None == None)

logs

2024-02-19 10:33:57.239 [info] [Trace - 10:33:57 AM] Sending request 'textDocument/codeAction - (43)'.
2024-02-19 10:33:57.241 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.241 [info] Interpreter executable (c:\Python312\Scripts\ruff.exe) not found
2024-02-19 10:33:57.244 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.244 [info] Falling back to bundled executable: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.244 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.245 [info] Found ruff 0.2.1 at c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.245 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.245 [info] Running Ruff with: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--stdin-filename', 'e:\\projects\\sandbox-py\\equality.py']
2024-02-19 10:33:57.258 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.258 [info] [
  {
    "cell": null,
    "code": "E712",
    "end_location": {
      "column": 11,
      "row": 4
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "True is None",
          "end_location": {
            "column": 19,
            "row": 4
          },
          "location": {
            "column": 7,
            "row": 4
          }
        }
      ],
      "message": "Replace with `cond is True`"
    },
    "location": {
      "column": 7,
      "row": 4
    },
    "message": "Comparison to `True` should be `cond is True` or `if cond:`",
    "noqa_row": 4,
    "url": "https://docs.astral.sh/ruff/rules/true-false-comparison"
  },
  {
    "cell": null,
    "code": "E711",
    "end_location": {
      "column": 19,
      "row": 4
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "True is None",
          "end_location": {
            "column": 19,
            "row": 4
          },
          "location": {
            "column": 7,
            "row": 4
          }
        }
      ],
      "message": "Replace with `cond is None`"
    },
    "location": {
      "column": 15,
      "row": 4
    },
    "message": "Comparison to `None` should be `cond is None`",
    "noqa_row": 4,
    "url": "https://docs.astral.sh/ruff/rules/none-comparison"
  },
  {
    "cell": null,
    "code": "E712",
    "end_location": {
      "column": 12,
      "row": 5
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "False is None",
          "end_location": {
            "column": 20,
            "row": 5
          },
          "location": {
            "column": 7,
            "row": 5
          }
        }
      ],
      "message": "Replace with `cond is False`"
    },
    "location": {
      "column": 7,
      "row": 5
    },
    "message": "Comparison to `False` should be `cond is False` or `if not cond:`",
    "noqa_row": 5,
    "url": "https://docs.astral.sh/ruff/rules/true-false-comparison"
  },
  {
    "cell": null,
    "code": "E711",
    "end_location": {
      "column": 20,
      "row": 5
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "False is None",
          "end_location": {
            "column": 20,
            "row": 5
          },
          "location": {
            "column": 7,
            "row": 5
          }
        }
      ],
      "message": "Replace with `cond is None`"
    },
    "location": {
      "column": 16,
      "row": 5
    },
    "message": "Comparison to `None` should be `cond is None`",
    "noqa_row": 5,
    "url": "https://docs.astral.sh/ruff/rules/none-comparison"
  },
  {
    "cell": null,
    "code": "E711",
    "end_location": {
      "column": 11,
      "row": 6
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "None is None",
          "end_location": {
            "column": 19,
            "row": 6
          },
          "location": {
            "column": 7,
            "row": 6
          }
        }
      ],
      "message": "Replace with `cond is None`"
    },
    "location": {
      "column": 7,
      "row": 6
    },
    "message": "Comparison to `None` should be `cond is None`",
    "noqa_row": 6,
    "url": "https://docs.astral.sh/ruff/rules/none-comparison"
  },
  {
    "cell": null,
    "code": "E711",
    "end_location": {
      "column": 19,
      "row": 6
    },
    "filename": "e:\\projects\\sandbox-py\\equality.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "None is None",
          "end_location": {
            "column": 19,
            "row": 6
          },
          "location": {
            "column": 7,
            "row": 6
          }
        }
      ],
      "message": "Replace with `cond is None`"
    },
    "location": {
      "column": 15,
      "row": 6
    },
    "message": "Comparison to `None` should be `cond is None`",
    "noqa_row": 6,
    "url": "https://docs.astral.sh/ruff/rules/none-comparison"
  }
]
2024-02-19 10:33:57.259 [info] [Trace - 10:33:57 AM] Received response 'textDocument/codeAction - (43)' in 20ms.
2024-02-19 10:33:57.260 [info] [Trace - 10:33:57 AM] Sending request 'textDocument/codeAction - (44)'.
2024-02-19 10:33:57.261 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.261 [info] Interpreter executable (c:\Python312\Scripts\ruff.exe) not found
2024-02-19 10:33:57.265 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.265 [info] Falling back to bundled executable: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.266 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.266 [info] Found ruff 0.2.1 at c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.266 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.266 [info] Running Ruff with: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--select', 'I001', '--select', 'I002', '--stdin-filename', 'e:\\projects\\sandbox-py\\equality.py']
2024-02-19 10:33:57.277 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.277 [info] []
2024-02-19 10:33:57.277 [info] [Trace - 10:33:57 AM] Received response 'textDocument/codeAction - (44)' in 17ms.
2024-02-19 10:33:57.285 [info] [Trace - 10:33:57 AM] Sending request 'textDocument/formatting - (45)'.
2024-02-19 10:33:57.286 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.286 [info] Interpreter executable (c:\Python312\Scripts\ruff.exe) not found
2024-02-19 10:33:57.290 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.290 [info] Falling back to bundled executable: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.290 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.290 [info] Found ruff 0.2.1 at c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.290 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.290 [info] Running Ruff with: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe ['format', '--force-exclude', '--quiet', '--stdin-filename', 'e:\\projects\\sandbox-py\\equality.py']
2024-02-19 10:33:57.302 [info] [Trace - 10:33:57 AM] Received response 'textDocument/formatting - (45)' in 16ms.
2024-02-19 10:33:57.313 [info] [Trace - 10:33:57 AM] Sending notification 'textDocument/didSave'.
2024-02-19 10:33:57.314 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.314 [info] Interpreter executable (c:\Python312\Scripts\ruff.exe) not found
2024-02-19 10:33:57.318 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.318 [info] Falling back to bundled executable: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.319 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.319 [info] Found ruff 0.2.1 at c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe
2024-02-19 10:33:57.319 [info] [Trace - 10:33:57 AM] Received notification 'window/logMessage'.
2024-02-19 10:33:57.319 [info] Running Ruff with: c:\Users\[user]\.vscode\extensions\charliermarsh.ruff-2024.10.0-win32-x64\bundled\libs\bin\ruff.exe ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--stdin-filename', 'e:\\projects\\sandbox-py\\equality.py']
2024-02-19 10:33:57.330 [info] [Trace - 10:33:57 AM] Received notification 'textDocument/publishDiagnostics'.
alexbot89 commented 7 months ago

Had to add a new config file as unsafe wasn't default.

unsafe-fixes = true