Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Linter] #826

Open
3 tasks done
athoag-sony opened this issue Apr 2, 2024 · 0 comments
Open
3 tasks done

[BUG] [Linter] #826

athoag-sony opened this issue Apr 2, 2024 · 0 comments
Labels
🔍 linter 🦠 bug Something isn't working

Comments

@athoag-sony
Copy link

System Info

  • OS: e.g. ubuntu 22.04
  • Python Version (3.11)
  • djLint Version (v1.34.1 )
  • template language: e.g. jinja2

Issue

I'm not sure if this a bug or me not understanding how djlint parses relative paths, but I can't get djlint to recognize jinja2 templates that are included via {% include 'relative_path/other_template.jinja2' %}.

How To Reproduce

I'm using djlint as a pre-commit hook. Here is my pre-commit-config.yaml:

repos:
  - repo: https://github.com/djlint/djLint
    rev: v1.34.1
    hooks:
      - id: djlint-jinja
        name: Run Jinja2 linter

Let's say we have a project structure like this:

app
├── pre-commit-config.yaml
├── templates
│   ├── base
│   │   ├── dummy_head.jinja2
│   ├── dummy.jinja2

I am linting app/templates/dummy.jinja2 whose contents are:

<!DOCTYPE html>
<html lang="en">
    {% include "base/dummy_head.jinja2" %}
</html>

And the file app/templates/base/dummy_head.jinja2 has these contents:

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>My GUI Project</title>
</head>

The key here is that there is a <title> tag in this included template, and I have verified that it renders in the browser. We will see that djlint does not see this <title> tag when it is contained in the included template.

From the root directory if I run my pre-commit hook like this:

poetry run pre-commit run djlint-jinja --files app/templates/dummy.jinja2

I get this set of errors back from djlint:

app/templates/dummy.jinja2
───────────────────────────────────────────────────────────────────────────────
H016 2:0 Missing title tag in html. <html lang="en"> 
H030 2:0 Consider adding a meta description. <html lang="en"> 
H031 2:0 Consider adding meta keywords. <html lang="en"> 

Linted 1 file, found 3 errors.

This is unexpected since I have a <title> tag in "base/dummy_head.jinja2", the template I included in dummy.jinja2.

However, if I simply replace the line: {% include "base/dummy_head.jinja2" %} with the contents of that file in app/templates/dummy.jinja2 I see the H016 error go away.

I have tried replacing the relative path "base/dummy_head.jinja2" with the full path from the root directory of the project, but I get the same djlint errors.

Contents of .djlintrc/pyproject.toml [tool.djlint]

Not relevant since I am running djlint as a pre-commit hook.

@athoag-sony athoag-sony added 🔍 linter 🦠 bug Something isn't working labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 linter 🦠 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant