Skip to content

Formatting document is inconsistent between ruff and air #892

Description

@juliasilge

Originally posted by @juliasilge in #754 (review):

I'm supportive of us merging this because it gives us an improvement, but I want to highlight a difference in results between very similar formatters, when you use Format Document.

If you have settings like this:

{
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff"
    },
    "[r]": {
        "editor.defaultFormatter": "Posit.air-vscode"
    },
    "[quarto]": {
        "editor.defaultFormatter": "quarto.quarto"
    }
}

And two .qmd files like this:

---
title: "Untitled"
format: html
---

```{python}
1 + 1
```


Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

```{python}
from typing import Iterable

import os


def sum_even_numbers(numbers: Iterable[int]) -> int:
    """Given an iterable of integers, return the sum of all even numbers in the iterable."""
    return sum(
        num for num in numbers
        if num % 2 == 0
    )
```

Second one:

---
title: "Untitled"
format: html
---

```{r}
1 + 1
```


Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

```{r}
list(foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar)
```

  • Put your cursor in the 1 + 1 code cell
  • Run Format Document
  • In the R file, the other code cell will get formatted, which is what I would argue is the correct behavior
  • In the Python file, the other code cell not get formatted, which I think is not right

If you run Format Document from the code cell that needs formatting, the behavior is the same for both; it does format that code cell. The command Quarto: Format Cell also works well for both files.

We can log this problem to follow up on.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions