DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

1 2

Linting Jinja Templates using Sparrow plugin jinjalint

Meet new Sparrow plugin jinjalint to lint jinja templates.


Let's get started!

Setup a tom task

$ tom --edit jinja-lint
Enter fullscreen mode Exit fullscreen mode
task-run "lint my code", "jinjalint", %(
  args => [
    "templates/",
    ["verbose"]
  ]
);
Enter fullscreen mode Exit fullscreen mode

Put some templates to check into templates/ directories

$ mkdir templates/
Enter fullscreen mode Exit fullscreen mode

Run check

$ tom jinja-lint
21:03:50 10/17/2020 [repository] index updated from file:///home/ubuntu/repo/api/v1/index
21:03:51 10/17/2020 [lint my code] run [jinjalint templates/ --verbose] ...
21:03:51 10/17/2020 [lint my code] Files being analyzed:
21:03:51 10/17/2020 [lint my code] templates/template.html
21:03:51 10/17/2020 [lint my code]
21:03:51 10/17/2020 [lint my code] templates/template.html:3:5: Parse error: expected one of '[:a-z]', 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'script', 'source', 'style', 'track', 'wbr', '{#', '{%', '{{' at 2:5
21:03:51 10/17/2020 [lint my code] task exit status: 1
21:03:51 10/17/2020 [lint my code] task lint my code FAILED
Enter fullscreen mode Exit fullscreen mode

That is it! You no longer miss errors in your jinja templates.


Check updates on SparrowHub.io - universal automation repository.


Aleksei

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
_garybell profile image
Gary Bell •

Bookmarked. Will look at adding this as a check for my Ansible CI pipeline

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay