From a51631c3064370545318800c2554dc8040a02364 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Tue, 23 Apr 2019 12:58:58 +0100 Subject: [PATCH] Add jinjalint linter for Django templates, allowing errors for now --- .circleci/config.yml | 1 + Makefile | 1 + docs/contributing/html_guidelines.rst | 16 ++++++++++++++++ docs/contributing/index.rst | 1 + setup.py | 3 +++ 5 files changed, 22 insertions(+) create mode 100644 docs/contributing/html_guidelines.rst diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f2ed2b266..e4317cd5ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,7 @@ jobs: key: pip-package-v1-{{ .Branch }} - run: pipenv run flake8 wagtail - run: pipenv run isort --check-only --diff --recursive wagtail + - run: pipenv run jinjalint --parse-only wagtail || true - run: DATABASE_NAME=wagtail.db pipenv run python -u runtests.py frontend: diff --git a/Makefile b/Makefile index 4ffa2dfb85..baf49884a2 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ develop: clean-pyc lint: flake8 wagtail isort --check-only --diff --recursive wagtail + jinjalint --parse-only wagtail || true npm run lint:css --silent npm run lint:js --silent diff --git a/docs/contributing/html_guidelines.rst b/docs/contributing/html_guidelines.rst new file mode 100644 index 0000000000..c6640b75f2 --- /dev/null +++ b/docs/contributing/html_guidelines.rst @@ -0,0 +1,16 @@ +HTML coding guidelines +====================== + +We use `Django templates `_ to author HTML. + +Linting HTML +~~~~~~~~~~~~ + +We use `jinjalint `_ to lint templates. If you have installed Wagtail's testing dependencies (``pip install -e .[testing]``), you can check your code by running ``make lint``. + +Principles +~~~~~~~~~~ + +* Write `valid HTML `_. We target the HTML5 doctype. +* Attach JavaScript behavior with ``data-`` attributes, rather than classes or IDs. +* For comments, use Django templates syntax instead of HTML. diff --git a/docs/contributing/index.rst b/docs/contributing/index.rst index 26af9ac2f3..8ad4bf1fb6 100644 --- a/docs/contributing/index.rst +++ b/docs/contributing/index.rst @@ -60,6 +60,7 @@ More information styleguide general_guidelines python_guidelines + html_guidelines css_guidelines javascript_guidelines release_process diff --git a/setup.py b/setup.py index 843bca4294..3a4113c2c2 100755 --- a/setup.py +++ b/setup.py @@ -53,6 +53,9 @@ testing_extras = [ 'isort==4.2.5', 'flake8-blind-except==0.1.1', 'flake8-print==2.0.2', + + # For templates linting + 'jinjalint>=0.5', ] # Documentation dependencies