thibaudcolas / curlylint

Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid
https://www.curlylint.org/
MIT License
239 stars 25 forks source link

Would auto-formatting / auto-indentation make sense for this project? #19

Open simonw opened 4 years ago

simonw commented 4 years ago

I've been hoping to find a templating equivalent of Black for quite a while. Could automatic formatting fit this project?

simonw commented 4 years ago

Whether or not this feature makes sense, this project is excellent - thank you so much! It just found a couple of bugs in Datasette. https://github.com/simonw/datasette/commit/d0c752d50c9ddd1d094a26837347c970a9b34872

thibaudcolas commented 4 years ago

Hey @simonw, well I’m glad you’re finding it helpful! 🙂 99% of the credit for those two issues should go to https://github.com/motet-a/jinjalint, from which most of Curlylint’s parser comes from (I’ve only changed the parser for a few bug fixes so far).


For auto-formatting – this is something I’m personally very interested in as well, as a heavy user of both Prettier and black. I’ve been keen to work on this for a while, but need to be realistic with the time commitment something like this would take, so the short answer is "not for now", I think.

The long answer is that there is some interest in making this happen in the Prettier world, and to me it feels like a good ecosystem for this to be done within, since there is so much similarity between all the curly template languages. So far the most promising attempt there is https://github.com/trivago/prettier-plugin-twig-melody, and I’m hoping this will be something we can leverage for Jinja / Django templates.

For Curlylint, I can see a few ways for this project to help make auto-formatting happen:


If you or anyone else wants to help with this, I can see a few options:

yaegassy commented 3 years ago

I'm also interested in the jinja2, django template formatter.

It seems that there is a package called "vsot", but unfortunately it is not maintained.

PRE-APLHA, mostly unmaintained

(Something, if it would be helpful.)

Of course, if there is a dedicated plugin for prettier, I'm sure that's fine.

panosl commented 3 years ago

I'm also interested in the jinja2, django template formatter.

It seems that there is a package called "vsot", but unfortunately it is not maintained.

PRE-APLHA, mostly unmaintained

* https://pypi.org/project/vsot/

* https://github.com/benhowes/vsot

(Something, if it would be helpful.)

Of course, if there is a dedicated plugin for prettier, I'm sure that's fine.

Now that looks promising!

thibaudcolas commented 3 years ago

Ah that’s really interesting, thank you for sharing it here. There aren’t that many parsers out there for HTML + template syntax, particularly with enough information for pretty-printing, so it’s always interesting to compare options at the very least.

yaegassy commented 3 years ago

@thibaudcolas I recently discovered a tool called djhtml. It appears to be actively being developed now.

DjHTML is an indenter and not a formatter

Currently, the feature seems to be only for indent adjustment, but we can expect more in the future.

thibaudcolas commented 3 years ago

@yaegassy 🤘 that seems pretty promising, thank you for sharing. I’ll have to try that out myself.