Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff format/fix on save not working in devcontainer until after window reload #501

Open
eschnitzler opened this issue Jun 24, 2024 · 5 comments
Labels
devcontainer Related to VS Code dev container (https://code.visualstudio.com/docs/devcontainers/containers)

Comments

@eschnitzler
Copy link

eschnitzler commented Jun 24, 2024

I am encountering an issue with the Ruff VSCode extension where the autofix on save feature does not work initially when using a devcontainer. The feature only starts working after I reload the VSCode window.

Steps to Reproduce:

  1. Open a project in a VSCode devcontainer.
  2. Ensure that the recommended settings are configured in devcontainer.json:
    "[python]": {
                     "editor.formatOnSave": true,
                     "editor.codeActionsOnSave": {
                         "source.fixAll": "explicit",
                         "source.organizeImports": "explicit"
                     },
                     "editor.defaultFormatter": "charliermarsh.ruff"
                 }
  3. Make an auto-fixable linting error in a python file and try to save it.

Expected Behavior:
The Ruff extension should automatically format and fix issues on save without needing to reload the VSCode window first.

Additional Information:

VSCode Version: 1.90.2
Ruff Extension Version: v2024.28.0
Operating System: Pop_Os 22.04

@PerMildner
Copy link

I see the same thing happening (settings specified via [python] ... in devcontainer.json not taking effect until after detach+reattach to dev container) for editor.rulers. So, my guess would be a bug in the VSCode dev-container plugin, not in ruff-vscode.

(I think I also saw this happening for editor.formatOnSave, like this issue reports)

@dhruvmanila
Copy link
Member

Can you provide some additional information?

  1. Any ruff.* scoped settings if set
  2. Content of the Ruff configuration is it's being used (pyproject.toml, ruff.toml, etc.)

Do you face this issue when using VS Code locally (not inside devcontainer)?

@PerMildner
Copy link

I am not sure whether "you" is referring to me or the original poster @eschnitzler but I will leave the keyboard for several weeks within minutes, so I will not be able to investigate this.

@dhruvmanila
Copy link
Member

Sorry for the confusion. I'm referring to the issue author @eschnitzler

@eschnitzler
Copy link
Author

eschnitzler commented Jul 5, 2024

@dhruvmanila Here are my ruff configured settings in my pyproject.toml file:

[tool.ruff]
exclude = [
    ".git",
    ".pytest_cache",
    ".ruff_cache",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]
line-length = 105
indent-width = 4

[tool.ruff.lint]
select = [
    "B",  # flake8-bugbear
    "C4", # flake8-comprehensions
    "E",  # Error (pycodesyle)
    "W",  # Warning (pycodesyle)
    "F",  # pyflakes
    "I",  # isort
    "ISC", # flake8-implicit-str-concat
    "PGH",  # pygrep-hooks
    "Q",  # flake8-quotes
    "DJ", # flake8-django
    "SIM",  # flake8-simplify
    "UP",  # pyupgrade
    "C4", # flake8-comprehensions
    "T10", # flake8-debugger
    "PT", # flake8-ptest-style
    "C90", # flake8-mccabe
]
ignore = [
    "W191",  # Indentation contains tabs
    "E111",  # Indentation is not a multiple of four
    "E114",  # Indentation is not a multiple of four (comment)
    "E117",  # Over-indented
    "E501",  # Line too long
    "Q000",  # Remove bad quotes (inline)
    "Q001",  # Remove bad quotes (multiline)
    "Q002",  # Remove bad quotes (docstring)
    "Q003",  # Remove avoidable escaped quote
    "ISC001",  # Implicit string concatenation (single-line)
    "ISC002",  # Implicit string concatenation (multi-line)
    "B026", # Star-arg unpacking after a keyword argument is strongly discouraged
    "B904", # 'assertRaises' should be used as a context manager
    "DJ001" # Avoid using null=True on string-based fields such as CharField and TextField
]

[tool.ruff.lint.per-file-ignores]
"**/tests/**" = ["C90"]


[tool.ruff.format]
docstring-code-format = true
exclude = [
    "app/migrations/**",
]

[tool.ruff.lint.mccabe]
max-complexity = 15

The issue only occurs when inside a devcontainer.

@dhruvmanila dhruvmanila added the devcontainer Related to VS Code dev container (https://code.visualstudio.com/docs/devcontainers/containers) label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devcontainer Related to VS Code dev container (https://code.visualstudio.com/docs/devcontainers/containers)
Projects
None yet
Development

No branches or pull requests

3 participants