From e24f651c86a5168da8181f2c75f5f99b56561224 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 14 Jun 2023 20:17:58 +0200 Subject: Add template linting via djlint (#25212) So I found this [linter](https://github.com/Riverside-Healthcare/djlint) which features a mode for go templates, so I gave it a try and it did find a number of valid issue, like unbalanced tags etc. It also has a number of bugs, I had to disable/workaround many issues. Given that this linter is written in python, this does add a dependency on `python` >= 3.8 and `poetry` to the development environment to be able to run this linter locally. - `e.g.` prefixes on placeholders are removed because the linter had a false-positive on `placeholder="e.g. cn=Search"` for the `attr=value` syntax and it's not ideal anyways to write `e.g.` into a placeholder because a placeholder is meant to hold a sample value. - In `templates/repo/settings/options.tmpl` I simplified the logic to not conditionally create opening tags without closing tags because this stuff confuses the linter (and possibly the reader as well). --- .github/workflows/files-changed.yml | 9 ++++++++- .github/workflows/pull-compliance.yml | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to '.github') diff --git a/.github/workflows/files-changed.yml b/.github/workflows/files-changed.yml index 9a9c54720b..f0c34df86d 100644 --- a/.github/workflows/files-changed.yml +++ b/.github/workflows/files-changed.yml @@ -15,6 +15,9 @@ on: actions: description: "whether actions files changed" value: ${{ jobs.detect.outputs.actions }} + templates: + description: "whether templates files changed" + value: ${{ jobs.detect.outputs.templates }} jobs: detect: @@ -27,6 +30,7 @@ jobs: frontend: ${{ steps.changes.outputs.frontend }} docs: ${{ steps.changes.outputs.docs }} actions: ${{ steps.changes.outputs.actions }} + templates: ${{ steps.changes.outputs.templates }} steps: - uses: actions/checkout@v3 - uses: dorny/paths-filter@v2 @@ -35,7 +39,7 @@ jobs: filters: | backend: - "**/*.go" - - "**/*.tmpl" + - "templates/**/*.tmpl" - "go.mod" - "go.sum" @@ -51,3 +55,6 @@ jobs: actions: - ".github/workflows/*" + + templates: + - "templates/**/*.tmpl" diff --git a/.github/workflows/pull-compliance.yml b/.github/workflows/pull-compliance.yml index daee522c27..5e094f02c1 100644 --- a/.github/workflows/pull-compliance.yml +++ b/.github/workflows/pull-compliance.yml @@ -26,6 +26,19 @@ jobs: env: TAGS: bindata sqlite sqlite_unlock_notify + lint-templates: + if: needs.files-changed.outputs.templates == 'true' + needs: files-changed + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - run: pip install poetry + - run: make deps-py + - run: make lint-templates + lint-go-windows: if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed -- cgit v1.2.3