mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-27 00:14:44 +00:00
added start of golang config
This commit is contained in:
parent
0ca4168dd4
commit
bbb0ed6f92
8 changed files with 40 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Find common formatting issues and *reformat* HTML templates.
|
||||
|
||||
***[Django](https://django.readthedocs.io/en/stable/ref/templates/language.html) · [Jinja](https://jinja2docs.readthedocs.io/en/stable/) · [Nunjucks](https://mozilla.github.io/nunjucks/) · [Handlebars](https://handlebarsjs.com)***
|
||||
***[Django](https://django.readthedocs.io/en/stable/ref/templates/language.html) · [Jinja](https://jinja2docs.readthedocs.io/en/stable/) · [Nunjucks](https://mozilla.github.io/nunjucks/) · [Handlebars](https://handlebarsjs.com) · [Mustache](http://mustache.github.io/mustache.5.html) · [GoLang](https://golang.org/doc/)***
|
||||
|
||||
Ps, ``--check`` it out on other templates as well!
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Next Release
|
|||
------------
|
||||
- Split ``alt`` requirement from H006 to H013
|
||||
- Added optional custom rules file
|
||||
- Added ``golang`` as profile option
|
||||
|
||||
0.5.1
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ Options:
|
|||
- django
|
||||
- jinja
|
||||
- nunjucks
|
||||
- handlebars
|
||||
- handlebars (for handlebars and mustache)
|
||||
- golang
|
||||
|
||||
Usage:
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ HTML Template Linter and Formatter
|
|||
|
||||
Find common formatting issues and *reformat* HTML templates.
|
||||
|
||||
*Django · Jinja · Nunjucks · Handlebars*
|
||||
*Django · Jinja · Nunjucks · Handlebars · Mustache · GoLang*
|
||||
|
||||
Ps, ``--check`` it out on other templates as well!
|
||||
|
||||
|
|
|
|||
|
|
@ -119,11 +119,12 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
||||
# we can try to fix template tags. ignore handlebars
|
||||
if config.profile != "handlebars":
|
||||
if config.profile not in ["handlebars", "golang"]:
|
||||
tmp = re.sub(r"({[{|%]\-?)(\w[^}].+?)([}|%]})", r"\1 \2\3", tmp)
|
||||
tmp = re.sub(r"({[{|%])([^}].+?[^(?:\ |\-)])([}|%]})", r"\1\2 \3", tmp)
|
||||
tmp = re.sub(r"({[{|%])([^}].+?[^ ])(\-[}|%]})", r"\1\2 \3", tmp)
|
||||
else:
|
||||
|
||||
elif config.profile == "handlebars":
|
||||
# handlebars templates
|
||||
tmp = re.sub(r"({{#(?:each|if).+?[^ ])(}})", r"\1 \2", tmp)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
flags: re.DOTALL
|
||||
exclude:
|
||||
- handlebars
|
||||
- golang
|
||||
patterns:
|
||||
# open
|
||||
- '{{[^\s#/@^]+'
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ class Config:
|
|||
"jinja": ["D", "N", "M"],
|
||||
"nunjucks": ["D", "J", "M"],
|
||||
"handlebars": ["D", "J", "N"],
|
||||
"golang": ["D", "J", "N", "M"],
|
||||
}
|
||||
|
||||
self.profile_code: List[str] = profile_dict.get(
|
||||
|
|
|
|||
30
tests/test_golang.py
Normal file
30
tests/test_golang.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""Djlint tests specific to go-lang.
|
||||
|
||||
run::
|
||||
|
||||
pytest tests/test_golang.py --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
for a single test, run::
|
||||
|
||||
pytest tests/test_golang.py::test_inline_comment --cov=src/djlint \
|
||||
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from .conftest import reformat
|
||||
|
||||
|
||||
def test_if(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(tmp_file, runner, b"{{ if .condition }} {{ else }} {{ end }}")
|
||||
assert output["exit_code"] == 0
|
||||
|
||||
|
||||
def test_range(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(tmp_file, runner, b"{{ range .Items }} {{ end }}")
|
||||
assert output["exit_code"] == 0
|
||||
Loading…
Reference in a new issue