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

Organize imports on save with custom config file location #411

Open
toinbis opened this issue Feb 20, 2024 · 1 comment
Open

Organize imports on save with custom config file location #411

toinbis opened this issue Feb 20, 2024 · 1 comment
Labels
needs-mre Needs more information for reproduction

Comments

@toinbis
Copy link

toinbis commented Feb 20, 2024

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:

  • ruff.lint.args & ruff format.args; VSCode highlights errors based on the config file;
  • The suggested fix dropdown:
    Screenshot 2024-02-20 at 14 41 12
    It also fixes according to my config file.
  • The same command run from CLI also behaves identically.

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
Copy link
Member

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?

@charliermarsh charliermarsh added the needs-mre Needs more information for reproduction label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-mre Needs more information for reproduction
Projects
None yet
Development

No branches or pull requests

3 participants