black_out icon indicating copy to clipboard operation
black_out copied to clipboard

[idea] Integrate with pre-commit

Open sloria opened this issue 7 years ago • 7 comments

Nice work on this project! I've been looking for something like it for some time.

I'm wondering if the bot could be configured to run pre-commit. That way, it could do more than just format with black.

pre-commit + a GitHub bot would ensure that unformatted code never gets merged, and would take the burden off maintainers and contributors.

In an ideal world, unformatted code never gets committed because pre-commit prevents it. In a realistic world, contributors may forget to install the pre-commit hooks. The black_out bot would be the last resort, making the formatting commit for you.

sloria avatar Sep 22 '18 12:09 sloria

@sloria pre-commit's hooks (I assume you're talking about pre-commit.com tool) don't always do changes, that's why I guess it's hard to use it for such a thing.

webknjaz avatar Oct 13 '18 09:10 webknjaz

@webknjaz Yes, I was referring to pre-commit.com. I'm not sure what you mean--running pre-commit run --all-files will modify files in place.

sloria avatar Oct 13 '18 20:10 sloria

Err.. not exactly. It will run hooks and those hooks may modify files if they are programmed to do so. Most of "hooks" there are linters, not autoformatters. Which conflicts with your statement a bit.

webknjaz avatar Oct 14 '18 01:10 webknjaz

I don't see that as a blocker to implementing this feature, though.

It is common to run black through pre-commit, but not all projects use the black coding style. marshmallow, for example, currently uses pre-commit for formatting but does not use black: https://github.com/marshmallow-code/marshmallow/blob/dev/.pre-commit-config.yaml

sloria avatar Oct 14 '18 18:10 sloria

Okay, I see where you're going with this. Makes sense.

webknjaz avatar Oct 14 '18 18:10 webknjaz

Sorry for the late in responding. I've been out of open source for the past two months, and just saw this now.

So I've created this bot because I don't want to bother with pre-commit and all that, but I think there was another suggestion in the past for integrating additional services other than black. I will think more about this.

Mariatta avatar Nov 02 '18 01:11 Mariatta

No worries!

Yeah, it makes sense why you'd want to use a bot for formatting. Integrating with pre-commit would generalize the tool a beyond black (and even beyond Python).

sloria avatar Nov 02 '18 02:11 sloria