Browse Source

Add jinjalint linter for Django templates, allowing errors for now

Thibaud Colas 6 years ago
parent
commit
a51631c306
5 changed files with 22 additions and 0 deletions
  1. 1 0
      .circleci/config.yml
  2. 1 0
      Makefile
  3. 16 0
      docs/contributing/html_guidelines.rst
  4. 1 0
      docs/contributing/index.rst
  5. 3 0
      setup.py

+ 1 - 0
.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:

+ 1 - 0
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
 

+ 16 - 0
docs/contributing/html_guidelines.rst

@@ -0,0 +1,16 @@
+HTML coding guidelines
+======================
+
+We use `Django templates <https://docs.djangoproject.com/en/stable/ref/templates/language/>`_ to author HTML.
+
+Linting HTML
+~~~~~~~~~~~~
+
+We use `jinjalint <https://github.com/motet-a/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 <https://validator.w3.org/nu/>`_. 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.

+ 1 - 0
docs/contributing/index.rst

@@ -60,6 +60,7 @@ More information
     styleguide
     general_guidelines
     python_guidelines
+    html_guidelines
     css_guidelines
     javascript_guidelines
     release_process

+ 3 - 0
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