DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

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

Latest comments (1)

Collapse
 
_garybell profile image
Gary Bell

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