peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
166 stars 10 forks source link

Detect stubs file and switch black accordingly #24

Closed Holt59 closed 4 years ago

Holt59 commented 4 years ago

Problem: Black has specific handling for stubs file (.pyi) which does not seem to be considered in flake8-black. This lead to situation where:

$ flake8 file.pyi
fily.pyi:24.1: BLK100 Black would make changes.
$ black file.pyi
All done! ✨ 🍰 ✨
1 file left unchanged.

Solution: Detect that the input file is a .pyi and pass the appropriate option to black.

peterjc commented 4 years ago

Presumably we'd set FileMode with is_pyi=True as per https://github.com/psf/black/blob/19.10b0/black.py#L411 when the extension is .pyi as per https://github.com/psf/black/blob/19.10b0/black.py#L631

peterjc commented 4 years ago

And here's the example in the black test suite:

https://github.com/psf/black/blob/master/tests/data/stub.pyi

peterjc commented 4 years ago

Plus an example where you'd use black --psi since the extension is not .psi:

https://github.com/psf/black/blob/master/tests/data/force_pyi.py

peterjc commented 4 years ago

@Holt59 are you able to install and test my proposed fix from the branch on pull request #25? Thanks!

Holt59 commented 4 years ago

@Holt59 are you able to install and test my proposed fix from the branch on pull request #25? Thanks!

This seems to fix it yes, thank you!

peterjc commented 4 years ago

Excellent, thank you. Expect the v0.2.1 release on PyPI shortly...