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

Support for blue as a formatter #251

Open
guettli opened this issue Jan 11, 2022 · 9 comments · May be fixed by #309
Open

Support for blue as a formatter #251

guettli opened this issue Jan 11, 2022 · 9 comments · May be fixed by #309
Labels
enhancement New feature or request many-formatters Support for multiple code formatters and skipping formatting

Comments

@guettli
Copy link

guettli commented Jan 11, 2022

Is it possible to use blue instead of black?

blue is a somewhat less uncompromising code formatter than black.

See also:

@akaihola
Copy link
Owner

akaihola commented Jan 18, 2022

Thanks for the heads-up @guettli, I've never taken a look at blue before.

Do you know if the internals are at all similar to black's? Darker uses the Python (non-public, see psf/black#779) API of Black instead of calling it as a subprocess.


Design

See also #304 for the idea to allow to disable reformatting.

Alternative 1: Separate --black/--blue configuration options for both formatters

Pros: Similar to the --isort option we already have.
Cons: Somewhat tricky to implement, plus the question about --no-black and --no-blue.

pyproject.toml

In absence of formatter related command line options:

[tool.darker]
black = true  # the default, uses Black as the formatter
[tool.darker]
blue = true  # disables Black and uses Blue as the formatter
[tool.darker]
black = false  # disables reformatting, see also #304
[tool.darker]
blue = false  # no effect, Black still enabled

Command line arguments

Examples in absence of pyproject.toml configuration:

$ darker .  # use Black (the default)
$ darker --black .  # no effect, still use Black
$ darker --blue .  # use Blue, disable Black
$ darker --no-black .  # disable reformatting (do we want this? see also #304)
$ darker --no-blue .  # no effect, still use Black (do we want this?)

Alternative 2: One common --formatter option

Pros: Similar to the --lint option we already have; simple to implement.
Cons: More verbose and maybe not so intuitive for the user.

pyproject.toml

In absence of formatter related command line options:

[tool.darker]
formatter = "black"  # the default, uses Black as the formatter
[tool.darker]
formatter = "blue"  # disables Black and uses Blue as the formatter
[tool.darker]
formatter = ""  # disables reformatting, see also #304
formatter = "none"  # alternative syntax, which one is better? (see #304)

Command line arguments

Examples in absence of pyproject.toml configuration:

$ darker .  # use Black (the default)
$ darker --formatter=black .  # no effect, still use Black
$ darker --formatter=blue .  # use Blue, disable Black
$ darker --formatter= .  # disable reformatting (do we want this? see #304)
$ darker --formatter=none .  # disable reformatting (alternative syntax, see #304)

@guettli
Copy link
Author

guettli commented Jan 20, 2022

@akaihola sorry. I have not looked at the internals of blue. AFAIK it is black with some small modifications.

@akaihola
Copy link
Owner

akaihola commented Jan 21, 2022

Ok, I'll return to possible blue support after I've made the 1.4.0 release.

One tricky problem to solve is the command line option for this. I've already regretted that --black isn't an option, and running black is the default.

@akaihola akaihola added this to the 1.5.0 milestone Jan 21, 2022
@akaihola akaihola added this to To do in Akaihola's Open source work via automation Jan 21, 2022
@akaihola akaihola added the enhancement New feature or request label Jan 21, 2022
@akaihola
Copy link
Owner

akaihola commented Feb 24, 2022

@guettli & @jedie, I'm now returning to this idea since 1.4.0 has been released.

The first thing I had to ponder is the command line interface and configuration options. I added a design section to my first comment above – what's your take on the two alternative configuration syntaxes, or do you have further ideas?

@guettli
Copy link
Author

guettli commented Feb 24, 2022

@akaihola I prefer Alternative2 ("formatter") a bit. Maybe in the long run there is a third formatter (maybe called "green"). I think then Alternative2 makes more sense. But no strong feelings here. A1 is fine, too.

@jedie
Copy link
Contributor

jedie commented Feb 24, 2022

+1 for --formatter

@akaihola akaihola linked a pull request Feb 24, 2022 that will close this issue
@akaihola
Copy link
Owner

#309 is a placeholder pull request to start working on this.

@guettli
Copy link
Author

guettli commented Mar 16, 2022

I thought about this again. Since Django will use black, I think I will do so, too. Sometimes it is easier to drop the own opinion and go with the flow.

@akaihola
Copy link
Owner

Thanks for the note, @guettli. I'll still keep this idea around, but deprioritize it and move it to a future milestone.

@akaihola akaihola changed the title No support for blue instead of black Support for blue as a formatter Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request many-formatters Support for multiple code formatters and skipping formatting
Projects
Development

Successfully merging a pull request may close this issue.

3 participants