Skip to content

Commit a13dfb9

Browse files
authored
Merge pull request #1260 from appwrite/feat-djlint-twig-formatter
2 parents ee434aa + 64369d3 commit a13dfb9

File tree

32 files changed

+92
-39
lines changed

32 files changed

+92
-39
lines changed

.github/workflows/djlint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Twig Linting
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.twig'
7+
- '.github/workflows/djlint.yml'
8+
- 'pyproject.toml'
9+
push:
10+
branches:
11+
- master
12+
paths:
13+
- '**.twig'
14+
- '.github/workflows/djlint.yml'
15+
- 'pyproject.toml'
16+
17+
jobs:
18+
djlint:
19+
name: djLint - Twig Linter
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v4
28+
29+
- name: Run djLint linter
30+
run: |
31+
uvx djlint templates/ --lint

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ docker run --rm -v $(pwd):/app -w /app php:8.3-cli php example.php
122122
123123
Check your output files at: /examples/new-lang and make sure the SDK works. When possible, add some unit tests.
124124

125+
## Linting Twig Templates
126+
127+
We use [djLint](https://djlint.com/) to lint Twig template files for syntax errors and common issues. The linter runs automatically on pull requests.
128+
129+
**To lint templates locally:**
130+
```bash
131+
composer lint-twig
132+
```
133+
134+
**Requirements:**
135+
- [uv](https://github.com/astral-sh/uv) must be installed (for running `uvx` commands)
136+
137+
**Configuration:**
138+
- Located in `pyproject.toml`
139+
- Only linting is enabled (formatting is disabled to avoid breaking code generation)
140+
- Several rules are ignored as they produce false positives for code generation templates
141+
142+
**What the linter catches:**
143+
- Template syntax errors
144+
- Missing closing tags
145+
- Extra blank lines
146+
- Basic HTML structure issues
147+
148+
**Note:** If you encounter linting errors that seem incorrect for code generation templates, please discuss in your PR rather than disabling the linter.
149+
125150
## SDK Checklist
126151

127152
It is very important for us to create a consistent structure and architecture, as well as a language-native feel for the SDKs we generate.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
7070

7171
```
7272

73+
## Linting Twig Templates
74+
75+
This project uses [djLint](https://djlint.com/) to lint Twig template files for syntax and common issues.
76+
77+
**Note:** Formatting is disabled as it breaks code generation syntax. Only linting is used.
78+
79+
**Available command:**
80+
```bash
81+
composer lint-twig # Check for linting errors
82+
```
83+
84+
Requires [uv](https://github.com/astral-sh/uv) to be installed. Configuration is in `pyproject.toml`. The linter runs automatically on pull requests via GitHub Actions.
85+
7386
## Supported Specs
7487

7588
* [Swagger 2](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"scripts": {
1515
"test": "vendor/bin/phpunit",
1616
"lint": "vendor/bin/phpcs",
17-
"format": "vendor/bin/phpcbf"
17+
"format": "vendor/bin/phpcbf",
18+
"lint-twig": "uvx djlint templates/ --lint"
1819
},
1920
"autoload": {
2021
"psr-4": {

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool.djlint]
2+
3+
profile="jinja"
4+
extension="twig"
5+
6+
ignore="H012,H025,H030,H031,T001,T002,T027,T032"
7+
# H012: spaces around = - false positive for TypeScript generics like <T = Models.Document>
8+
# H025: orphan tags - false positive for code generics like <T>, <String>, <Exception>
9+
# H030/H031: meta description/keywords (not applicable to SDK code templates)
10+
# T001: whitespace in tags - {%~ is intentional Twig whitespace control
11+
# T002: double quotes - templates need flexibility with quote styles
12+
# T027: unclosed strings - false positive for ${{ secrets.X }} in GitHub Actions
13+
# T032: extra whitespace in tags - often intentional for formatting/line continuation
14+
15+
exclude=".git,vendor,tests/sdks,node_modules,examples"
16+
17+
use_gitignore=true
18+
max_line_length=1200

templates/android/build.gradle.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ task clean(type: Delete) {
2929
delete rootProject.buildDir
3030
}
3131

32-
3332
apply from: "${rootDir}/scripts/publish-config.gradle"
3433

templates/android/example/src/main/java/io/package/android/ui/accounts/AccountsFragment.kt.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import androidx.fragment.app.viewModels
1313
import {{ sdk.namespace | caseDot }}.android.R
1414
import {{ sdk.namespace | caseDot }}.android.databinding.FragmentAccountBinding
1515

16-
1716
class AccountsFragment : Fragment() {
1817

1918
private lateinit var binding: FragmentAccountBinding

templates/apple/Sources/Client.swift.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ open class Client {
3838

3939
internal var http: HTTPClient
4040

41-
4241
private static let boundaryChars = "abcdefghijklmnopqrstuvwxyz1234567890"
4342

4443
private static let boundary = randomBoundary()
@@ -266,7 +265,6 @@ open class Client {
266265
var request = HTTPClientRequest(url: endPoint + path + queryParameters)
267266
request.method = .RAW(value: method)
268267

269-
270268
for (key, value) in self.headers.merging(headers, uniquingKeysWith: { $1 }) {
271269
request.headers.add(name: key, value: value)
272270
}

templates/cli/install.ps1.twig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function Greeting {
3535
Write-Host "Welcome to the {{ spec.title | caseUcfirst }} CLI install shield."
3636
}
3737

38-
3938
function CheckSystemInfo {
4039
Write-Host "[1/4] Getting System Info ..."
4140
if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') {
@@ -60,7 +59,6 @@ function DownloadBinary {
6059
Move-Item ${{ spec.title | upper }}_DOWNLOAD_DIR ${{ spec.title | upper }}_INSTALL_PATH
6160
}
6261

63-
6462
function Install {
6563
Write-Host "[3/4] Starting installation ..."
6664

@@ -83,7 +81,6 @@ function InstallCompleted {
8381
Write-Host "As first step, you can login to your {{ spec.title | caseUcfirst }} account using 'appwrite login'"
8482
}
8583

86-
8784
Greeting
8885
CheckSystemInfo
8986
DownloadBinary

templates/cli/install.sh.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RED='\033[0;31m'
3939
GREEN='\033[0;32m'
4040
NC='\033[0m' # No Color
4141

42-
4342
greeting() {
4443
echo -e "${RED}"
4544
cat << "EOF"

0 commit comments

Comments
 (0)