domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.
https://domluna.github.io/JuliaFormatter.jl/dev/
MIT License
571 stars 65 forks source link

Formatting other languages within .jl file #502

Open gdalle opened 2 years ago

gdalle commented 2 years ago

Hi! First of all, thanks for this amazing formatter, which brings me daily joy. I recently started working with PyCall.jl to embed Python routines inside Julia files. When I format these files, only the Julia parts are modified, as expected. However, given the popularity of Python and the good compatibility between both languages, I wondered if this could change. I think it might make sense to add an option calling external Python formatters (such as black) on the parts of the code that look like

py"do_stuff_in_python()"

or

py"""
do_stuff_in_python()
"""

What are your thoughts on this?

domluna commented 2 years ago

It's possible I guess you would detect a python string and then shell out to black or whatever formatter. There's a bunch of other things that are a higher priority than something like this though so I wouldn't hold my breath this is implemented anytime soon. I would be open to a PR if it made sense. It would probably work similarly to how docstrings are formatted.