thibaudcolas / curlylint

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

Ability to do simple checks on template tag content #131

Open lb- opened 2 years ago

lb- commented 2 years ago

Is your proposal related to a problem?

Describe the solution you’d like

Describe alternatives you’ve considered

Additional context

thibaudcolas commented 2 years ago

Hi @lb- :) I’ve been working on such a blocktrans trimmed rule, but with a JS version of curlylint, not the Python one currently available here.

Technically what you’re describing is already possible – Curlylint creates an AST from templates with nodes for DTL/Jinja syntax, as well as HTML. The node you’re looking for here is JinjaTag, specifically its content property.

The main issue to implementing this is that Curlylint currently provides the raw AST to each and every linting rules – most linters implement the visitor design pattern, which makes implementations much simpler.

lb- commented 2 years ago

Hmmmm interesting - a JS version - I guess it's just html so doesn't really matter what is used.

Now I see why you were not a fan of the make lint rule server / client separation.

However, it does add another ecosystem for template linting that some projects may not be keen on adopting.

Nonetheless - I might try to understand what you mean by visitor pattern and see what is possible with this library instead

thibaudcolas commented 2 years ago

@lb- it’s definitely possible with this library, visitor pattern or otherwise. The visitor pattern is just one of the most common ways to structure code working on tree structures, ASTs in particular. Here’s an example Python implementation. The consequence of not having it is "just" that every linting rule currently needs to reimplement its own variant of AST parsing :)

The main reasons I’m keen on trying out a JS version of curlylint is that: