astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
956 stars 45 forks source link

Organize imports on save with custom config file location #411

Open toinbis opened 4 months ago

toinbis commented 4 months ago

I have issues with import formats on save not respect the ruff config file.

    "ruff.lint.args": [
        "--config=${workspaceFolder}/src/shared_core/static_configs/ruff.toml",
        "check",
        "--unsafe-fixes",
        "--fix"
    ],

    "ruff.format.args": [
        "--config=${workspaceFolder}/src/shared_core/static_configs/ruff.toml",
        "--preview"
    ],

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

This is my vscode settings.json. I get consistent behaviour (=reading and using custom config file location) for:

I.e. All as expected!

Until I want to do organize imports automatically on save. So these settings come into effect:

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

And they seem to just use default ruff without any custom config. And it just formats differentely!

"ruff.lint.run": "onType|onSave", seemed like a setting which could help, but this settings, as shown by VSCode, is invalid.

How do I sort imports on save when using custom ruff config file location?

Thanks

dhruvmanila commented 3 months ago

Thank you for opening the issue! Can you provide the content in your config file? And can you expand on how "it formats differently"? Like, what is the expected behavior and what are you actually getting?