فهرست منبع

Djhtml install and configure with pre-commit (#7940)

Steve Stein 3 سال پیش
والد
کامیت
72886c0a62
5فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 1 0
      .circleci/config.yml
  2. 4 0
      .pre-commit-config.yaml
  3. 2 1
      Makefile
  4. 1 1
      docs/contributing/html_guidelines.rst
  5. 3 0
      setup.py

+ 1 - 0
.circleci/config.yml

@@ -24,6 +24,7 @@ jobs:
       # Filter out known false positives, while preserving normal output and error codes.
       # See https://github.com/motet-a/jinjalint/issues/18.
       # And https://circleci.com/docs/2.0/configuration-reference/#default-shell-options.
+      - run: git ls-files '*.html' | xargs pipenv run djhtml --check || true
       - run:
           shell: /bin/bash -e
           command: pipenv run jinjalint --parse-only wagtail | grep -v 'welcome_page.html:6:70' | tee /dev/tty | wc -l | grep -q '0'

+ 4 - 0
.pre-commit-config.yaml

@@ -38,3 +38,7 @@ repos:
         additional_dependencies:
           - stylelint@14.2.0
           - '@wagtail/stylelint-config-wagtail@0.3.2'
+  - repo: https://github.com/rtts/djhtml
+    rev: v1.4.13
+    hooks:
+      - id: djhtml

+ 2 - 1
Makefile

@@ -3,7 +3,7 @@
 help:
 	@echo "clean-pyc - remove Python file artifacts"
 	@echo "develop - install development dependencies"
-	@echo "lint - check style with flake8"
+	@echo "lint - check style with flake8, sort python with isort, indent html, and lint frontend css/js"
 	@echo "test - run tests"
 	@echo "coverage - check code coverage"
 
@@ -22,6 +22,7 @@ lint:
 	# Filter out known false positives, while preserving normal output and error codes.
 	# See https://github.com/motet-a/jinjalint/issues/18.
 	jinjalint --parse-only wagtail | grep -v 'welcome_page.html:6:70' | tee /dev/tty | wc -l | grep -q '0'
+	git ls-files '*.html' | xargs djhtml --check
 	npm run lint:css --silent
 	npm run lint:js --silent
 	npm run lint:format --silent

+ 1 - 1
docs/contributing/html_guidelines.rst

@@ -6,7 +6,7 @@ We use `Django templates <https://docs.djangoproject.com/en/stable/ref/templates
 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``.
+We use `jinjalint <https://github.com/motet-a/jinjalint>`_ to lint templates and `djhtml <https://github.com/rtts/djhtml>`_ to format them. If you have installed Wagtail's testing dependencies (``pip install -e .[testing]``), you can check your code by running ``make lint``.
 
 Principles
 ~~~~~~~~~~

+ 3 - 0
setup.py

@@ -66,6 +66,9 @@ testing_extras = [
     # For templates linting
     'jinjalint>=0.5',
 
+    # For template indenting
+    'djhtml==1.4.13',
+
     # Pipenv hack to fix broken dependency causing CircleCI failures
     'docutils==0.15',