Skip to main content

t-linter ๐Ÿโœจ

Intelligent syntax highlighting, validation, and formatting for Python template strings (PEP 750).

License: MIT PyPI VSCode Marketplace

๐Ÿ“ฃ ๐Ÿ’ผ Maintainer update: Open to opportunities. ๐Ÿ”— koxudaxi.dev

๐Ÿ“– Documentation

๐Ÿ‘‰ t-linter.koxudaxi.dev

  • ๐Ÿ“ฆ Installation - PyPI, VSCode Extension, Build from source
  • ๐Ÿ” Check Command - CLI validation & output formats
  • ๐Ÿงน Format Command - Canonical formatting for supported templates
  • ๐Ÿ–ฅ๏ธ LSP Server - Editor integration (VSCode, Claude Code, Codex, Neovim, etc.)
  • โš™๏ธ Configuration - pyproject.toml & ignore files
  • ๐ŸŒ Supported Languages - HTML, T-HTML, TDOM, SQL, JS, CSS, JSON, YAML, TOML

Overview

t-linter validates and formats embedded languages inside Python template strings (PEP 750). Built with Rust and Tree-sitter for speed, it ships as a single binary that works as both a CLI tool and an LSP server.

  • t-linter check โ€” validate template string syntax
  • t-linter format โ€” canonically reformat supported template literals
  • t-linter lsp โ€” start the Language Server Protocol server for editor integration

Features

  • ๐Ÿ” Linting - Detect syntax errors in embedded HTML, JSON, YAML, TOML, CSS, JavaScript, SQL
  • ๐Ÿงน Formatting - Canonical formatting for HTML, T-HTML, TDOM, JSON, YAML, TOML templates
  • ๐ŸŽจ Syntax Highlighting - Smart highlighting via LSP semantic tokens
  • ๐Ÿ”ง Type-based Detection - Understands Annotated[Template, "html"] and type aliases
  • ๐Ÿงช Interpolation Type Checking - Optional LSP diagnostics for JSON, YAML, TOML interpolation values and TDOM component prop interpolations through Ty, Pyright, or Pyrefly
  • ๐Ÿงฉ Callee Inference - Detects backend languages from helpers such as tdom.html(...)
  • ๐Ÿš€ Fast - Single Rust binary with Tree-sitter parsers

Supported Languages

Language Annotation Check Format Highlight
HTML "html" โœ… โœ… โœ…
T-HTML "thtml" โœ… โœ… โœ…
TDOM "tdom" โœ… โœ… โœ…
JSON "json" โœ… โœ… โœ…
YAML "yaml", "yml" โœ… โœ… โœ…
TOML "toml" โœ… โœ… โœ…
CSS "css" โœ… โ€” โœ…
JavaScript "javascript", "js" โœ… โ€” โœ…
SQL "sql" โœ… โ€” โœ…

For HTML, T-HTML, TDOM, JSON, YAML, and TOML, t-linter uses dedicated Rust backends (tstring-* crates) for strict validation and canonical formatting. CSS, JavaScript, and SQL use Tree-sitter for syntax validation and highlighting.

Installation

PyPI (Recommended)

pip install t-linter

Or add to your project's dependencies:

# Using uv (recommended)
uv add t-linter

# Or using pip with requirements.txt
echo "t-linter" >> requirements.txt
pip install -r requirements.txt

This provides the t-linter CLI tool and LSP server.

โ†’ View on PyPI

VSCode Extension

If you use VSCode, install the extension for seamless editor integration:

  1. Open VSCode โ†’ Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  2. Search for "t-linter" โ†’ Install "T-Linter" by koxudaxi
  3. On Linux x64, macOS x64/arm64, and Windows x64, the extension bundles the t-linter binary, so no separate PyPI install is required.
  4. On unsupported platforms, or if you want to override the bundled binary, install t-linter via PyPI (see above) and set t-linter.serverPath to the full executable path.
  5. Choose one save-time formatting mode:
    • Ruff coexistence mode keeps Ruff as the Python formatter and runs t-linter through source.fixAll.t-linter:
      {
        "[python]": {
          "editor.defaultFormatter": "charliermarsh.ruff",
          "editor.formatOnSave": true,
          "editor.codeActionsOnSave": {
            "source.fixAll.t-linter": "explicit"
          }
        }
      }
      
    • t-linter formatter mode keeps the existing formatter-only workflow:
      {
        "[python]": {
          "editor.defaultFormatter": "koxudaxi.t-linter",
          "editor.formatOnSave": true
        }
      }
      
      Set "t-linter.format.runRuffPipeline": true if you want this formatter mode to run Ruff fixAll, import organization, Ruff formatting, and then t-linter in one composed formatting transaction. VSCode only allows one default formatter per language, which is why t-linter also exposes a save-time code action lane for template-string formatting.
  6. If semantic highlighting conflicts with another Python extension, set the Python language server to "None" in your workspace settings:
    {
        "python.languageServer": "None"
    }
    
    If you need those features, you can keep the Python language server enabled. t-linter will still provide template-string diagnostics, code actions, and formatting, though semantic highlighting may conflict.

If you use an external t-linter binary and it is not in your PATH, set t-linter.serverPath in VSCode settings to the full path of the executable.

โ†’ Install from VSCode Marketplace

Build from Source

git clone https://github.com/koxudaxi/t-linter
cd t-linter
cargo install --path crates/t-linter

Usage

Check

Validate template strings for syntax errors:

# Check a single file
t-linter check file.py

# Check a directory
t-linter check src/

# Output formats: human (default), json, github
t-linter check file.py --format json
t-linter check file.py --format github  # GitHub Actions annotations

# Exit with error code if issues found (useful for CI)
t-linter check file.py --error-on-issues

Example output:

example.py:4:47: error[embedded-parse-error] Expected a JSON value. (language=json)
1 files scanned, 1 templates scanned, 1 diagnostics, 0 failed files

Exit codes:

Code Meaning
0 Run completed successfully
1 Issues were found and --error-on-issues was set
2 Operational failure such as an unreadable file

Format

Rewrite supported template literals (HTML, T-HTML, TDOM, JSON, YAML, TOML) in place:

# Format a single file
t-linter format file.py

# Format a directory
t-linter format src/

# Check whether formatting would change any files (for CI)
t-linter format --check file.py

# Override the formatter line length
t-linter format --line-length 100 file.py

# Format stdin
cat file.py | t-linter format --stdin-filename file.py -

Templates in unsupported languages (CSS, JavaScript, SQL) are left unchanged.

For CI pipelines that also use Ruff, run the tools explicitly in sequence:

ruff check --fix . && ruff format . && t-linter format .
ruff check . && ruff format --check . && t-linter format --check .

LSP Server

Start the Language Server Protocol server for editor integration:

t-linter lsp

# Start the LSP server with the composed Ruff pipeline -> t-linter document formatting
t-linter lsp --ruff-pipeline

The LSP server provides:

  • Semantic Tokens โ€” syntax highlighting for embedded languages
  • Diagnostics โ€” real-time validation with 250ms debouncing
  • Interpolation Type Checking โ€” optional JSON, YAML, TOML interpolation value diagnostics and TDOM component prop interpolation diagnostics through Ty, Pyright, or Pyrefly
  • Document Formatting โ€” full document and range formatting
  • Code Actions โ€” source.fixAll.t-linter for document-level rewrites and refactor.rewrite.t-linter for single-template selection rewrites

Interpolation value type checking is opt-in and applies to JSON, YAML, TOML templates and TDOM component props. Enable it from an LSP client with initialization options:

{
  "typeChecking": {
    "enabled": true,
    "checker": "pyright",
    "command": "/path/to/pyright-langserver",
    "args": ["--stdio"]
  }
}

When command and args are omitted, t-linter uses the selected checker defaults: ty server, pyright-langserver --stdio, or pyrefly lsp. It searches active virtual environments, workspace .venv/venv, uv projects, and then the checker on PATH.

See Interpolation Type Checking for the architecture, behavior, and implementation details.

Claude Code

Add t-linter as an LSP server in your project's .claude/settings.json:

{
  "lsp": {
    "t-linter": {
      "command": "t-linter",
      "args": ["lsp"],
      "languages": ["python"]
    }
  }
}

Claude Code will then use t-linter's diagnostics when editing Python files containing template strings.

Codex

Add the LSP configuration to your project's codex.json or start t-linter's LSP server as part of your development environment. The t-linter check and t-linter format commands can also be used directly in Codex's sandbox:

t-linter check src/
t-linter format --check src/

Neovim

vim.lsp.start({
  name = "t-linter",
  cmd = { "t-linter", "lsp" },
  filetypes = { "python" },
})

Other Editors

Any editor with LSP support can use t-linter. Configure the LSP client to start t-linter lsp as the server command for Python files.

Configuration

Configuration via pyproject.toml:

[tool.t-linter]
line-length = 80
extend-exclude = ["generated", "vendor"]
ignore-file = ".t-linterignore"
Key Description
line-length Formatter print width (applies to HTML, T-HTML, and TDOM only; JSON, YAML, and TOML use fixed formatting rules)
exclude Override the built-in default excludes
extend-exclude Add more exclude patterns on top of the defaults
ignore-file Path to a gitignore-style ignore file, relative to the project root

By default, t-linter also reads .t-linterignore from the project root if it exists.

Quick Start Example

from typing import Annotated
from string.templatelib import Template

def render_html(template: Annotated[Template, "html"]) -> None:
    pass


def run_sql(template: Annotated[Template, "sql"]) -> None:
    pass


type css = Annotated[Template, "css"]
type yaml_config = Annotated[Template, "yaml"]
type toml_config = Annotated[Template, "toml"]


def load_styles(template: css) -> None:
    pass


def load_yaml(template: yaml_config) -> None:
    pass


def load_toml(template: toml_config) -> None:
    pass


title = "t-linter"
heading = "Template strings with syntax highlighting"
content = "Interpolations stay as normal Python expressions."

render_html(t"""
<!DOCTYPE html>
<html>
    <head>
        <title>{title}</title>
    </head>
    <body>
        <h1 style="color: #007acc">{heading}</h1>
        <p>{content}</p>
    </body>
</html>
""")

start_date = "2026-01-01"

run_sql(t"""
SELECT u.name, u.email, p.title
FROM users u
JOIN posts p ON u.id = p.author_id
WHERE u.created_at > {start_date}
ORDER BY u.name
""")

padding = 24

load_styles(t"""
.container {{
    max-width: 1200px;
    margin: 0 auto;
    padding: {padding}px;
}}
""")

app_name = "demo-app"

load_yaml(t"""
app:
  name: {app_name}
  debug: true
""")

project_name = "demo-project"
version = "0.1.0"

load_toml(t"""
[project]
name = "{project_name}"
version = "{version}"
""")

Use {{ and }} when the embedded language needs literal braces, such as CSS or JSON objects.

For html, <title>{value}</title> is allowed and treated as escaped text. <script>, <style>, and <textarea> still reject interpolations for safety.

Roadmap

Planned Features

  • โœ… Language Server Protocol (LSP) - Fully implemented
  • โœ… Syntax Highlighting - Supports HTML, T-HTML, TDOM, SQL, JavaScript, CSS, JSON, YAML, TOML
  • โœ… Type Alias Support - Recognizes type html = Annotated[Template, "html"]
  • โœ… Linting (check command) - Validate template strings for syntax errors
  • โœ… Formatting (format command) - Canonical formatting for HTML, T-HTML, TDOM, JSON, YAML, TOML
  • ๐Ÿšง Statistics (stats command) - Analyze template string usage across codebases
  • ๐Ÿ“‹ Cross-file Type Resolution - Track type aliases across module boundaries

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

t_linter-0.9.1.tar.gz (168.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

t_linter-0.9.1-py3-none-win_amd64.whl (4.8 MB view details)

Uploaded Python 3Windows x86-64

t_linter-0.9.1-py3-none-manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

t_linter-0.9.1-py3-none-manylinux_2_28_aarch64.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

t_linter-0.9.1-py3-none-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file t_linter-0.9.1.tar.gz.

File metadata

  • Download URL: t_linter-0.9.1.tar.gz
  • Upload date:
  • Size: 168.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for t_linter-0.9.1.tar.gz
Algorithm Hash digest
SHA256 f04805885a7fde08d539e1dd2f336b5744bfb72a53b9f54da9fa90ab7a8357e2
MD5 25fe9e1ba382c6a06e90bf8bf940165e
BLAKE2b-256 dbb4ad54f87b9a85dc29ff3743c5c4b9ac254199503a8e88dedf8fa373709d40

See more details on using hashes here.

File details

Details for the file t_linter-0.9.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: t_linter-0.9.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for t_linter-0.9.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1c44bcb3f710ede3e82891bb1fee870a153a5feb99f462a943c6cb4b6994a45f
MD5 b0fa024f22d385456ff38e179983a6e0
BLAKE2b-256 b9a6366bcc0231528bfd8b9410a2c31c2626cc5a8a7375930c2fa9bf511f8d06

See more details on using hashes here.

File details

Details for the file t_linter-0.9.1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for t_linter-0.9.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9e77a065fef31deac12ebfd95b8fefc2c7a22d566d88c1e6301aa4280f1242c5
MD5 0df2f3987b2e649dec889a05238eb34c
BLAKE2b-256 6413747f8409115dd3bf4b8f54b63215492ce7f7ea96bfa14cecfd24a25c7129

See more details on using hashes here.

File details

Details for the file t_linter-0.9.1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for t_linter-0.9.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9af0e400381a9e3c401ee88d1bf2d711349eb466e1947223a46819f61dbea138
MD5 dc6a20e3c84fe59fc3d571f2244e17de
BLAKE2b-256 18c684d6b05e1fb8fba8a67a0c6416480ae721c5a0fe1122d5df63da80df9562

See more details on using hashes here.

File details

Details for the file t_linter-0.9.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for t_linter-0.9.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b4526c016a0a94272307963d65ca037b70cf7b67e1e0f484c5b97d647d06af8
MD5 b5bf27d973e496263b6253289ae09bb2
BLAKE2b-256 bf5f0169fc8d6b818cbb60d27dd803876142e313cf42a7e41f37ae15e39f1ffb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page