Skip to main content

The AI Linter - Enterprise-grade linting and governance for AI-generated code across multiple languages

Project description

thai-lint

License: MIT Python 3.11+ PyPI Tests Coverage Documentation

The AI Linter - Catch the mistakes AI coding assistants keep making.

thailint detects anti-patterns that AI tools frequently introduce: duplicate code, excessive nesting, magic numbers, SRP violations, and more. It works across Python, TypeScript, JavaScript, and Rust with unified rules - filling gaps that existing linters miss.

Installation

pip install thailint

Or run instantly with uvx (no install required):

uvx thailint dry src/

Or with Docker:

docker run --rm -v $(pwd):/data washad/thailint:latest --help

Quick Start

# Generate a config file (optional)
thailint init-config

# Run any linter
thailint dry src/

That's it. See violations, fix them, ship better code.

Available Linters

Linter What It Catches Command Docs
DRY Duplicate code across files thailint dry src/ Guide
Nesting Deeply nested if/for/while blocks thailint nesting src/ Guide
Magic Numbers Unnamed numeric literals thailint magic-numbers src/ Guide
Performance O(n²) patterns: string += in loops, regex in loops thailint perf src/ Guide
SRP Classes doing too much thailint srp src/ Guide
File Header Missing documentation headers thailint file-header src/ Guide
Stateless Class Classes that should be functions thailint stateless-class src/ Guide
Collection Pipeline Loops with embedded filtering thailint pipeline src/ Guide
Method Property Methods that should be @property thailint method-property src/ Guide
File Placement Files in wrong directories thailint file-placement src/ Guide
Lazy Ignores Unjustified linting suppressions thailint lazy-ignores src/ Guide
Improper Logging Print statements and conditional verbose patterns thailint improper-logging src/ Guide
Stringly Typed Strings that should be enums thailint stringly-typed src/ Guide
LBYL Look Before You Leap anti-patterns thailint lbyl src/ Guide
Law of Demeter Deep object chain access (reaching through objects) thailint law-of-demeter src/ Guide
Version Freshness EOL/outdated runtime versions in infra files thailint version-freshness . Guide
Unwrap Abuse .unwrap()/.expect() that panic at runtime (Rust) thailint unwrap-abuse src/ Guide
Clone Abuse .clone() abuse: loops, chains, unnecessary (Rust) thailint clone-abuse src/ Guide
Blocking Async Blocking std:: calls in async functions (Rust) thailint blocking-async src/ Guide

Configuration

Create .thailint.yaml in your project root:

dry:
  enabled: true
  min_duplicate_lines: 4

nesting:
  enabled: true
  max_nesting_depth: 3

magic-numbers:
  enabled: true
  allowed_numbers: [-1, 0, 1, 2, 10, 100]

Or add a [tool.thailint] section to your pyproject.toml:

[tool.thailint]
dry = {enabled = true, min_duplicate_lines = 4}
nesting = {enabled = true, max_nesting_depth = 3}
magic-numbers = {enabled = true, allowed_numbers = [-1, 0, 1, 2, 10, 100]}

Config precedence: .thailint.yaml > .thailint.json > pyproject.toml.

Or generate one automatically:

thailint init-config --preset lenient  # or: strict, standard

See Configuration Reference for all options.

Output Formats

# Human-readable (default)
thailint dry src/

# JSON for CI/CD
thailint dry --format json src/

# SARIF for GitHub Code Scanning
thailint dry --format sarif src/ > results.sarif

Ignoring Violations

# Line-level
timeout = 3600  # thailint: ignore[magic-numbers]

# File-level
# thailint: ignore-file[dry]

Or in config:

dry:
  ignore:
    - "tests/"
    - "**/generated/**"

See How to Ignore Violations for all 5 ignore levels.

CI/CD Integration

# GitHub Actions
- name: Run thailint
  run: |
    pip install thailint
    thailint --parallel dry src/
    thailint --parallel nesting src/

Use --parallel for faster linting on large codebases (2-4x speedup on multi-core systems).

Exit codes: 0 = success, 1 = violations found, 2 = error.

Documentation

Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

git clone https://github.com/be-wise-be-kind/thai-lint.git
cd thai-lint
poetry install
just test

License

MIT License - see LICENSE for details.

Support

Project details


Download files

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

Source Distribution

thailint-0.19.2.tar.gz (317.3 kB view details)

Uploaded Source

Built Distribution

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

thailint-0.19.2-py3-none-any.whl (468.9 kB view details)

Uploaded Python 3

File details

Details for the file thailint-0.19.2.tar.gz.

File metadata

  • Download URL: thailint-0.19.2.tar.gz
  • Upload date:
  • Size: 317.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1013-azure

File hashes

Hashes for thailint-0.19.2.tar.gz
Algorithm Hash digest
SHA256 963e17509f93cd90aa4778919cba930e47beee9cca662a93bacf1b597b3f1672
MD5 cb0ba83d946f7802670bac32da56ed90
BLAKE2b-256 0f6ad56953575f077ea71ff770fbb7152a7c30e8e0d772e634e0708d420f845c

See more details on using hashes here.

File details

Details for the file thailint-0.19.2-py3-none-any.whl.

File metadata

  • Download URL: thailint-0.19.2-py3-none-any.whl
  • Upload date:
  • Size: 468.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1013-azure

File hashes

Hashes for thailint-0.19.2-py3-none-any.whl
Algorithm Hash digest
SHA256 350001d033174aec0e9cb194763e47b52e02885a0a3f938687bc8b4e1053df91
MD5 b68e1e7879017e4689f2f62b748fdd35
BLAKE2b-256 e6ef9c87aefe23d012e89c74b23df6411fb11e28475e7ab93ccbb58c3bcc2795

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 Pingdom Monitoring Sentry Error logging StatusPage Status page