Code Monkey home page Code Monkey logo

riverside-healthcare / djlint Goto Github PK

View Code? Open in Web Editor NEW
608.0 13.0 72.0 31.53 MB

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang

Home Page: https://djLint.com

License: GNU General Public License v3.0

Python 99.53% HTML 0.27% Shell 0.11% JavaScript 0.08%
html linter python jinja2-templates django-templates html-templates html-linter nunjucks-templates handlebars-templates golang-template django jinja2 golang nunjucks handlebars-js mustache-js twig twig-templates

djlint's Introduction


djLint Logo

🏗️ Maintainers needed, please reach out on discord or email!

The missing formatter and linter for HTML templates.

tweet Discord Chat

Codecov Status Codacy Status Downloads npm Pypi Download

What lang are you using?

DjangoJinjaNunjucksTwigHandlebarsMustacheGoLangAngular

demo

🤔 For What?

Once upon a time all the other programming languages had a formatter and linter. Css, javascript, python, the c suite, typescript, ruby, php, go, swift, and you know the others. The cool kids on the block.

HTML templates were left out there on their own, in the cold, unformatted and unlinted :( The dirty corner in your repository. Something had to change.

djLint is a community build project to and add consistency to html templates.

✨ How?

Grab it with pip

pip install djlint

Or with the npm experimental install - Note, this requires python and pip to be on your system path.

npm i djlint

Lint your project

djlint . --extension=html.j2 --lint

Check your format

djlint . --extension=html.j2 --check

Fix my format!

djlint . --extension=html.j2 --reformat

💙 Like it?

Add a badge to your projects readme.md:

[![Code style: djlint](https://img.shields.io/badge/html%20style-djlint-blue.svg)](https://www.djlint.com)

Add a badge to your readme.rst:

.. image:: https://img.shields.io/badge/html%20style-djlint-blue.svg
   :target: https://www.djlint.com

Looks like this:

djLint

🛠️ Can I help?

Yes!

Would you like to add a rule to the linter? Take a look at the linter docs and source code

Are you a regex pro? Benchmark and submit a pr with improved regex for the linter rules

⚠️ Help Needed! ⚠️ Good with python? djLint was an experimental project and is catching on with other devs. Help out with a rewrite of the formatter to improve speed and html style for edge cases. Contribute on the 2.0 branch

🏃 Other Tools Of Note

  • DjHTML A pure-Python Django/Jinja template indenter without dependencies.
  • HTMLHint Static code analysis tool you need for your HTML
  • curlylint Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid

djlint's People

Contributors

adamchainz avatar ahmetelgun avatar andersk avatar cclauss avatar cherart avatar christopherpickering avatar dependabot[bot] avatar doubleforte avatar foarsitter avatar hrjakobsen avatar jayvdb avatar kageurufu avatar luxcem avatar matthiask avatar monosans avatar mouarius avatar mrkgrgsn avatar nvuillam avatar renjisann avatar renovate-bot avatar renovate[bot] avatar ruanmed avatar sean-pickering avatar semantic-release-bot avatar shaileshaanand avatar shuuji3 avatar timobrembeck avatar tonyrippy avatar valjed avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djlint's Issues

[BUG] Ignored tag regex is too inclusive

System Info

  • OS: e.g. ubuntu 20.04
  • Python Version (python --version)
  • djLint Version (djlint --version)

Issue

{% block body %}

    <!-- tab control -->
    <div class="tabs">
        <ul>
            <li class="is-active"><a title="data source"
   class="tab-lnk"
   href="details"><span class="icon is-small"><i class="fas fa-info-circle"
   aria-hidden="true"></i></span><span>Details</span></a></li>
            <li> <a title="task logs"
    class="tab-lnk"
    href="tasklog"><span class="icon is-small"><i class="fas fa-terminal"
   aria-hidden="true"></i></span><span>Logs</span></a></li>
            <li> <a title="task files"
    class="tab-lnk"
    href="taskfile"><span class="icon is-small"><i class="fas fa-file-download"
   aria-hidden="true"></i></span><span>Files</span></a></li></ul>
        </div>
        <!-- tab body -->
        <div class="tab-cnt">
            <div class="tab-dta active" id="details">
                <div class="em-grid">{% include "pages/task/details_source.html.j2" %}
</div>
                <div class="tab-dta" id="tasklog">
                    <div class="em-ajaxTable" data-src="/table/task/{{ t.id }}/log">
                        <div class="loader-typing"></div>
                    </div>
                </div>
                <div class="tab-dta" id="taskfile">
                    <div class="em-ajaxTable" data-src="/table/task/{{ t.id }}/files">
                        <div class="loader-typing"></div>
                    </div>
                </div>
            </div>
        {% endblock body %}

is not being reformatted. The are treated as a comment, not the individual comment lines. The ignored block regex is too inclusive.

[BUG] javascript: href triggers D018

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

The following html triggers D018 "Internal links should use the {% url ... %} pattern." These are not internal links.

It would be helpful to have a separate rule to prevent using <a href="javascript:.."> which typically should be replaced with onclick and a real href for javascript disabled browsers. Then I can disable only that rule (until I can fix the source code), while getting the benefit of D018.

How To Reproduce

<a href="javascript:abc()">{% trans "def" %}</a>

attributes w/ filter arg are loosing closing brackets

<img data-src="{% if report.imgs.exists %}{{ report.imgs.first.get_absolute_url|size:"96x96"}}
                         {% else %}{% static '/img/report_thumb_placeholder_400x300.png' %}
                         {% endif %}" src="{% static '/img/loader.gif' %}
                         alt="report image"/>

the data-src is loosing "}} after 96x96, and 96x96 is being moved down a line.

Allow user configuration

  • option to exclude directories from cli and pyproject.toml
  • option to ignore lint rules from pyproject.toml
  • option to ignore lint rules from files

[BUG] H012 false positive in JS

System Info

  • OS: Windows
  • Python Version: 3.9
  • djLint Version: 0.4.9

Issue

<= in JS is causing H012

How To Reproduce

<script>
        $(document).ready(function () {
            // Parts
            for (i = 1; i <= 3; i++) {
            }

    </script>

[BUG] --help should show --indent default of 4

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

djlint --help displays "--indent INTEGER Indent spacing. ex: 3" .

It would be better to display the default (4) like --extension is supposed to do (c.f. #50 )

That should be sufficient to help users see how to change it to 3 or other value if required.

[FEATURE] Lint indent

Feature Request

The reformatter performs indenting, however there isnt a lint error for incorrect indentation.

[FEATURE] Report error for Unmatched HTML closing tags

Feature Request

This might be beyond scope of this tool ... but ... when the input has non-matching closing tags, a html error would be nice.

Here the reformatter is nicely reformatting the <td>...</td> but on the next line is a dangling </td> which doesnt have an opening tag.

@@ -40,14 +42,17 @@
                             <td>
                                 <strong>{{ foo }}</strong>
                             </td>
-                    <td>
-                        {{ bar }}                    </td>
+                            <td>{{ bar }}</td>
                         </td>
                         <td>
...

Another

                 <tr>
-            <th data-field="processed">{% trans 'Processed' %}</i></th>
+                    <th data-field="processed">
+                        {% trans 'Processed' %}
+                        </i>
+                    </th>
                     <th data-field="uri">{% trans 'Uri' %}</th>

Note I think https://github.com/thibaudcolas/curlylint does report parse error for some of these, but it doesnt have clear error messages. They look like:

163:22 Parse error: expected 'p' at 163:22 parse_error

The p in ^ often has nothing to do with the problem, but hints that it went off-course due to a parser problem.

I am also going to try https://pypi.org/project/zpretty/ to see if it is any better / is able to find its way around the django templatism.

Add option / configuration to ignore paths

The ignored_paths setting cannot be extended currently:
https://github.com/Riverside-Healthcare/djLint/blob/678e50088cdfa29f0f525b035f6207327d0c7e04/src/djlint/settings.py#L64-L83

I'd want to exclude e.g. templates/registration/password_reset_email.html from reformatting because the template contains text for an email (despite the incorrect .txt extension) but currently there's no way to do that (if I understand the code correctly).

By the way, flake8 uses ignore for error codes and exclude for paths, and extend-exclude to add additional patterns to exclude. https://flake8.pycqa.org/en/3.9.2/user/options.html?highlight=exclude#cmdoption-flake8-exclude I think that's an excellent naming. I'm willing to do the work if you agree but didn't want to drop a big pull request without checking first.

[BUG] Output seems off

System Info

  • OS: 5.14.8-arch1-1
  • Python: 3.9
  • djLint: 0.4.9

Issue

The output of djlint seems a bit off. The line number is off by -1, and the supposed problematic part is stripped of some characters.

% djlint src/mkdocstrings/templates 

Linting 20/20 files ━━━━━━━━━━━━━━━━━━━━ 00:00    


src/mkdocstrings/templates/python/material/attribute.html
─────────────────────────
H011 20:50 Attribute values should be quoted. ,
          id=html
H011 39:52 Attribute values should be quoted. ,
            id=htm

src/mkdocstrings/templates/python/material/class.html
────────────────────────
H011 20:22 Attribute values should be quoted. ,
          id=html
H011 43:24 Attribute values should be quoted. ,
            id=htm

src/mkdocstrings/templates/python/material/function.html
─────────────────────────
H011 20:25 Attribute values should be quoted. ,
          id=html
H011 39:27 Attribute values should be quoted. ,
            id=htm

How To Reproduce

The template triggering these warnings looks like the following:

        {% filter heading(heading_level,
            role="data" if obj == module else "attr",
            id=html_id,
            toc_label=attribute.path,
            hidden=True) %}
        {% endfilter %}

The id=html_id, line is actually the 21st, 40th, or 44th instead of the 20th, 39th or 43rd respectively.
As you can see the output starts with the ending comma of the previous line.
Then some content is stripped, like _id, or even l_id,.

(By the way the H011 warning is a false positive here, as its a function call, not plain HTML, but that belongs in another issue)

Here's a whole template if you want to try it:

{{ log.debug() }}
{% if config.show_if_no_docstring or attribute.has_contents %}

  <div class="doc doc-object doc-attribute">
  {% with html_id = attribute.path %}

    {% if not root or config.show_root_heading %}

      {% if root %}
        {% set show_full_path = config.show_root_full_path %}
        {% set root_members = True %}
      {% elif root_members %}
        {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
        {% set root_members = False %}
      {% else %}
        {% set show_full_path = config.show_object_full_path %}
      {% endif %}

      {% filter heading(heading_level,
          role="data" if obj == module else "attr",
          id=html_id,
          class="doc doc-heading",
          toc_label=attribute.name) %}

        {% filter highlight(language="python", inline=True) %}
          {% if show_full_path %}{{ attribute.path }}{% else %}{{ attribute.name }}{% endif %}
          {% if attribute.type %}: {{ attribute.type }}{% endif %}
        {% endfilter %}

        {% with properties = attribute.properties %}
          {% include "properties.html" with context %}
        {% endwith %}

      {% endfilter %}

    {% else %}
      {% if config.show_root_toc_entry %}
        {% filter heading(heading_level,
            role="data" if obj == module else "attr",
            id=html_id,
            toc_label=attribute.path,
            hidden=True) %}
        {% endfilter %}
      {% endif %}
      {% set heading_level = heading_level - 1 %}
    {% endif %}

    <div class="doc doc-contents {% if root %}first{% endif %}">
      {% with docstring_sections = attribute.docstring_sections %}
        {% include "docstring.html" with context %}
      {% endwith %}
    </div>

  {% endwith %}
  </div>

{% endif %}

Django: djLint changes {% blocktranslate %} if not using trimmed strings

This may or may not be a problem. I think I like the fact that {% blocktranslate %} tags are formatted as well, but without trimmed the original string changes each time the template is reindented and that's a bit bad.

Maybe this is something to add, for example in a new recommendations section.

[BUG] Breaking reformat in in-line conditional in class attribute

System Info

  • OS: Debian 11 — python:3.9 docker container
  • Python Version: 3.9 (python --version)
  • djLint Version: 0.4.2

Issue + How To Reproduce

Hi there,

Using inline conditionals in the class="..." attribute of a tag we have the following.

<div class="class1{% if condition %} class2{% endif %}">content</div>
                                    ^ single space significant

Running djlint --reformat on the file, we get,

<div class="class1{% if condition %}class2{% endif %}">content</div>
                                    ^ single space removed

A workaround would be to put the space before the conditional, ie,

<div class="class1 {% if condition %}class2{% endif %}">content</div>
                  ^ space refactored to be here

Is this intended? Should I apply this workaround throughout my codebase before reformatting?

In any event, thanks for the great tool!

Cheers,

David

allow some tags to be inline

How can "tag_pos_inline" be honored, and still allow newlines before closing lines if there is a multi line statement?

for example, both of these are ok:

<h1>hi</h1>

and

<h1>
hi
<button>click</button>
</h1>

Allow nunjk tag -%}

Currently this is transforming from -%} to - %} in njk templates. It should be preserved.

[BUG] H011 false-positive

System Info

  • OS: 5.14.8-arch1-1
  • Python: 3.9
  • djLint: 0.4.9

Issue

As seen in #37, H011 is triggered for id parameters of function calls (or, I guess, any other HTML-like parameters such as href, etc.) when the call is split on multiline.

How To Reproduce

{{ func(
    id=html_id,
) }}

W017 false positive

test.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>title</title>
        <meta charset="utf-8">
        <meta name="description" content="test page" />
    </head>
    <body>
        <br>
        <br/>
        <img alt="img1" src="/test1.png">
        <img alt="img2" src="/test2.png"/>
    </body>
</html>
djlint test.html

Linting 1/1 files 
test.html
 W017 5:8 Tag should be self closing. <meta charset="utf-8
 W006 11:8 Img tag should have alt, height and width attributes. <img alt="img1" src=
 W017 11:8 Tag should be self closing. <img alt="img1" src=

Linted 1 file, found 3 errors.

In HTML5 empty elements like meta and img do not need to end with />. The above html document passes W3C html validator without any warning.

Expected output: 1 warning.

I guess I could disable the W017 rule. But wouldn't it make sense to be disabled by default? Another thing I don't understand is why djlint reports a warning for img and not br?

djlint 0.3.4

[FEATURE] Custom rules

Feature Request

( fyi, you have fixed all of the false positives I can find in my rather large project. )

IMO it would be helpful if I could configure djlint to load an additional rules.yaml. Specifically I would be quite interested in re-creating https://github.com/amandasaurus/django-template-i18n-lint using custom djlint rules if that were possible. The project looks to be unmaintained and unlikely to change given some comments on the PRs.

I am using c.f. appannie/eslint-plugin-gettext#22 and https://github.com/gramener/eslint-plugin-template to ensure my .po has all annotated l10n strings, but I need a tool to detect un-annotated l10n strings.

I would be keen to submit the rules here once they are polished, but it will be easier to develop them solely for my own project first.

Also django projects often have their own do's and don'ts and djlint seems like a great framework to help projects bake them into CI.

[BUG] H015 triggered by HTML in JS strings

System Info

  • OS: Windows
  • Python Version: 3.7
  • djLint Version: 0.4.9

Issue

The snippet below cause H015 Follow h tags with a line break. This could be OK, if it is intentional that HTML within JS strings are processed, but it seems this is a strange and problematic windy path to go down.

How To Reproduce

<script>
    var template = '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>';
</script>

[BUG] blank_line_after_tag not working inside blocks

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

I have config blank_line_after_tag = "load,extends,include,csrf_token,endblock,endwith" , and I do see blank lines added after load and include when they are at the top level.

However when inside a {% block %}...{% endblock %} , the existing blank lines are being removed.

How To Reproduce

@@ -1,25 +1,23 @@
 {% extends "administration/basemodal.html" %}
+
 {% load static %}

 {% block content %}
     {% load i18n %}
-
     {% trans 'Are you sure you want to delete' %} '{{ object }}'?
-    <br/><br/>
-
+    <br/>
+    <br/>
     <form action="" method="POST">
         {% include "administration/form.html" %}
-
         <div class="row">
         ...

If the above isnt reproducible, I need to dig into my administration/templates/administration/delete.html a bit more to isolate the problem.

[FEATURE] Add linter option for jinja {{ url_for

Feature Request

Add a linter option for jinja {{ url_for() vs the django {% url.

It might be a good idea to add linter "profiles" of rules that are disabled/ enabled depending on what template language is being used.

contents of textarea should not be reformated

<div>
<textarea>
stuff
</textarea>
</div>

should not become

<div>
    <textarea>
         stuff
    </textarea>
</div>

it should be

<div>
    <textarea>
stuff
</textarea>
</div>
as extra space is literal in output..

[BUG] div tags following long attributes are not indented correctly

System Info

  • OS: e.g. ubuntu 20.04
  • Python Version (python --version)
  • djLint Version (djlint --version)

Issue

{% block body %}
    <div class="em-ajaxTable"
         data-theme="Exec"
         data-src="/table/project/{% if user_id %}{{ user_id }}{% elif mine %}mine{% else %}all{% endif %}">
        <div class="loader"></div></div>
    {% endblock body %}

shows as correct html, but the </div> tags should be on newlines.

[FEATURE] Splitting H006

Feature Request

H006 combining width/height with alt is not ideal.

alt is a different type of problem, and users may have different priority for fixing it vs missing w/h.

w/h is fairly simple to fix, being mostly technical, and normally wouldnt need QA, however creating new alt values could involve non-technical project members/clients, and may even require translators (my project has a firm 'must have translations for every bit of English, except in /admin' rule), and would need QA.

Splitting that could be a bit tricky, simply altering it would mean existing ignore of H006 wouldn't work.

[FEATURE] H019 href="#"

Feature Request

I think href="#" should also be H019. I cant think of any reason it might be better as a separate linter rule.

I can probably do this one myself easily enough, and this would be a good one to cut my teeth on, provided you agree on it.

[BUG] H012 false positive with equal inside element

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

The following html triggers "There should be no spaces around attribute =".
Also I guess "attribute =" should be "symbol =" or "attribute equals sign (=)"

<script id="errorTemplate" type="text/x-kendo-template">
        <div class="errorNotification">
            <h3>#= title #</h3>
            <p>#= message #</p>
        </div>
    </script>

How To Reproduce

See above

[BUG] --reformat causes UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 4350: invalid continuation byte

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

After running reformat, running it again causes an exception without informing me which file was the cause.

$ djlint --reformat .

concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\concurrent\futures\process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\djlint\reformat.py", line 17, in reformat_file
    rawcode = this_file.read_text(encoding="utf8")
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\pathlib.py", line 1217, in read_text
    return f.read()
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 4350: invalid continuation byte
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\Scripts\djlint.exe\__main__.py", line 7, in <module>
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\click\core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\click\core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\site-packages\djlint\__init__.py", line 298, in main
    file_errors.append(future.result())
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\concurrent\futures\_base.py", line 428, in result
    return self.__get_result()
  File "C:\Users\vandjohn\Downloads\WPy64-3771\python-3.7.7.amd64\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 4350: invalid continuation byte

How To Reproduce

No idea, as the filename isnt given in the stderr.

[BUG] Is colgroup really a "self-closing" tag?

Hello! I'm trying out djlint on some templates of mine, thank you for creating and maintaining this project!

System Info

  • OS: 5.14.8-arch1-1
  • Python: 3.9
  • djLint: 0.4.9

Issue

I'm getting these warnings: H017 3:2 Tag should be self closing. <colgroup>.
But if I look at w3schools, it does not seem to me like colgroup is a self-closing tag, like br, hr or img.

But maybe I misunderstand what "self-closing tag" means?

How To Reproduce

Run djlint on a template like the following:

{{ log.debug() }}
<table class="field-list">
  <colgroup>
    <col class="field-name" />
    <col class="field-body" />
  </colgroup>
  <tbody valign="top">
    <tr class="field">
    <th class="field-name">Returns:</th>
    <td class="field-body">
        <ul class="first simple">
          <li>{{ ((("`" + return.annotation + "` – ") if return.annotation else "") + return.description)|convert_markdown(heading_level, html_id) }}</li>
        </ul>
    </td>
    </tr>
  </tbody>
</table>

[BUG] Using the config option --blank_line_after_tag should only affect lines that begin with the tag

Issue

For example, with a pyproject of:

[tool.djlint]
blank_line_after_tag="include"

his

 <div class="tab-cnt">
     <div class="tab-dta active" id="details">
         <!-- this passes -->
         <div class="em-grid">{% include "pages/task/details_source.html.j2" %}
</div>
        <!-- but should be left as this -->
         <div class="em-grid">{% include "pages/task/details_source.html.j2" %}</div>
     </div>
 </div>

Error in click.get_terminal_size().columns

Hello,

I tried using the linter but I get an error immediately.
I use python 3.8 and I'm on a Mac. The error seems to be related to my terminal.

    Linting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00
    
    Traceback (most recent call last):
      File "/Users/martin/.virtualenvs/gwoscweb/bin/djlint", line 8, in <module>
        sys.exit(main())
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/click/core.py", line 829, in __call__
        return self.main(*args, **kwargs)
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/click/core.py", line 782, in main
        rv = self.invoke(ctx)
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/click/core.py", line 610, in invoke
        return callback(*args, **kwargs)
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/djlint/__init__.py", line 298, in main
        error_count += build_output(error)
      File "/Users/martin/.virtualenvs/gwoscweb/lib/python3.8/site-packages/djlint/__init__.py", line 61, in build_output
        width = click.get_terminal_size().columns
    AttributeError: 'tuple' object has no attribute 'columns'

[BUG] H012 false positive

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

Split from #39 (comment) , this specific case still exists. (All the others I had are now gone, thx!)

How To Reproduce

<p>
        {% if activity.reporting_groups|length <= 0 %}<h3>{% trans 'General' %}</h3>{% endif %}
</p>

Invalid formatting of some user defined 'enclosing' tags

test.html

{% load my_tags %}
{% block main %}
    {% fragmentation %}
        {% toc %}
            {% include "cms/includes/streamfield.html" with blocks=self.body %}
        {% endtoc %}
    {% endfragmentation %}
{% endblock main %}

djlint test.html --reformat

test.html

{% load my_tags %}
{% block main %}
    {% fragmentation %}
    {% toc %}
    {% include "cms/includes/streamfield.html" with blocks=self.body %}
{% endtoc %}
{% endfragmentation %}
{% endblock main %}

I would expect test.html format to remain unchanged. It looks like djlint doesn't recognise the custom tags (fragmentation, endfragmentation, toc, endtoc) and treats 'endtoc' as closing the 'block main'.

Discussion

While it is true that it is impossible without looking at the code definition of the user-defined tags that toc and endtoc are paired, djlint might rely on the widespread naming convention in django where the name of the closing tag starts with 'end'. Obviously it's a heuristic that would require pre-processing and if {% endtoc %} was accidentally missing from the template, there's no way djlint would be able to tell. On the other hand it could be a very handy feature for larger projects where user-defined tags or third-party tags are more common.

Maybe as an alternative these pair of tags (toc - endtoc) could be declared somewhere in a config file to let djlint lint and format them as expected.

What do you think about the issue and the suggestions?

Javascript events inside links should be ignored

<a href="/admin/emptyScheduler" title="empty scheduler" onclick="return confirm('Are you sure? Go to Dash > Error > Reschedule all to restart.')">Empty Scheduler
        </a>

formatting this breaks the html. The "onclick" should be ignored.

[BUG] text in <style> indented too much

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.4.9

Issue

I am encountering this unacceptable reformatting within <style>.

 {% block headinclude %}
     <style>
         {# override to fix text all over the place in media upload box #}
-        .k-dropzone .k-upload-status {
-            color: #a1a1a1;
-        }
+                                                        .k-dropzone .k-upload-status {
+                                                            color: #a1a1a1;
+                                                        }
     </style>
 {% endblock %}

How To Reproduce

If the above isnt reproducible, I need to dig into my element_quick_entry.html a bit more to isolate the problem.

[BUG]test

System Info

  • OS: e.g. ubuntu 20.04
  • Python Version (python --version)
  • djLint Version (djlint --version)

Issue

How To Reproduce

[BUG] Reformatter mangling templatetag quotes within html attribute quotes

System Info

  • OS: Windows
  • Python Version: 3,7
  • djLint Version: 0.5.2

Issue

I am pretty sure I can work-around this by changing one of the single quotes to double quotes.

-                            <li>{{ i.id }}: {{ i.name }}(
-                                <a href='{% url 'builder:activity-version-detail' i.id %}' target='_blank' rel='noopener' style="color:#09c;">
+                            <li>
+                                {{ i.id }}: {{ i.name }}(
+                                <a href='{% url '
+                                   builder
+                                   activity-version-detail
+                                   i
+                                   id
+                                   target='_blank'
+                                   rel='noopener'
+                                   style="color:#09c;">
                                     {% trans 'View' %}
-                                </a><i class="fa fa-external-link" style="color:#09c;"></i> )
+                                </a>
+                                <i class="fa fa-external-link" style="color:#09c;"></i>
+                                )

How To Reproduce

See above

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.