Skip to main content

mlinter

A standalone linter for Hugging Face Transformers model integration files. It enforces structural conventions on every modeling_*.py, modular_*.py, configuration_*.py, image_processing_*.py, video_processing_*.py, and processing_*.py file under src/transformers/models.

Installation

pip install git+https://github.com/huggingface/transformers-mlinter@main

When working on the transformers repo, mlinter is included in the quality extras:

pip install -e ".[quality]"

How rule registration works

  • Rule metadata lives in mlinter/rules.toml.
  • The TOML schema is versioned with a top-level version = 1. Custom files passed with --rules-toml must use the same schema version.
  • Executable TRF rules are auto-discovered from trf*.py modules in the mlinter/ package.
  • Each module must define a check(tree, file_path, source_lines) -> list[Violation] function.
  • The module name determines the rule id: trf003.pyTRF003.
  • A RULE_ID module-level constant is set automatically by the discovery mechanism.
  • Every discovered rule must have a matching entry in the TOML file, and every TOML rule must have a matching module. Import-time validation fails if either side is missing.
  • Suppressions use # trf-ignore: TRFXXX on the same line or the line immediately above the flagged construct.

How to add a new TRF rule

The repo ships an add-mlinter-rule skill under .ai/skills/ that walks an agent through duplicate detection, numbering, module creation, running against all models, and test scaffolding. Enable it for your agent of choice:

make claude   # symlinks .claude/skills -> .ai/skills (for Claude Code)
make codex    # symlinks .agents/skills -> .ai/skills (for Codex)

After that, invoke it as /add-mlinter-rule in a new session. To add a rule manually:

  1. Add a [rules.TRFXXX] entry to mlinter/rules.toml.
  2. Fill in description, default_enabled, explanation.what_it_does, explanation.why_bad, and explanation.diff. Optional model-level exceptions go in allowlist_models.
  3. Create a new module mlinter/trfXXX.py with a check(tree, file_path, source_lines) -> list[Violation] function.
  4. Use the RULE_ID module constant instead of hardcoding "TRFXXX" inside the check.
  5. Add or update focused tests in tests/.

CLI usage

Run from the root of a transformers checkout:

# Check all model integration files
mlinter

# Only check files changed against a git base ref
mlinter --changed-only --base-ref origin/main

# List all available TRF rules and their default state
mlinter --list-rules

# Use a custom rules TOML instead of the bundled mlinter/rules.toml
mlinter --rules-toml /path/to/custom-rules.toml

# Show the installed mlinter version
mlinter --version

# Show detailed documentation for one rule
mlinter --rule TRF001

# Enable additional rules on top of the defaults
mlinter --enable-rules TRF003

# Enable every TRF rule, including ones disabled by default
mlinter --enable-all-trf-rules

# Emit GitHub Actions error annotations
mlinter --github-annotations

When installed from a git checkout or a git+https://... URL, mlinter --version includes a short commit hash suffix such as 1.2.3+g1a2b3c4.

You can also invoke it as a Python module:

python -m mlinter

The lint cache is stored in the user cache directory instead of next to the installed package: $XDG_CACHE_HOME/mlinter/.mlinter_cache.json on Linux, ~/Library/Caches/mlinter/.mlinter_cache.json on macOS, and %LOCALAPPDATA%\mlinter\.mlinter_cache.json on Windows.

Python API

Import the supported Python API from the package root:

from mlinter import TRF001, analyze_file, model_dir_name, render_rules_reference

mlinter.mlinter and mlinter._helpers are implementation modules and may change without a compatibility promise.

Development

git clone https://github.com/huggingface/transformers-mlinter
cd transformers-mlinter
pip install -e ".[dev]"

Run the tests:

pytest tests/

Releasing

See docs/release.md for the current release process.

Download files

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

Source Distribution

transformers_mlinter-0.1.2.tar.gz (44.0 kB view details)

Uploaded Source

Built Distribution

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

transformers_mlinter-0.1.2-py3-none-any.whl (52.2 kB view details)

Uploaded Python 3

File details

Details for the file transformers_mlinter-0.1.2.tar.gz.

File metadata

  • Download URL: transformers_mlinter-0.1.2.tar.gz
  • Upload date:
  • Size: 44.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for transformers_mlinter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1ab44ecc5ba3bd6832369df9a78c7b9b0b6eca003a7f85bdf014b70a714e6101
MD5 3a8c96dafb9750ba06db3309314b8706
BLAKE2b-256 610faeedc4aeecf5a909cc6b817c962fd58c8017cd4d59765c3cd7e8cc8dd41a

See more details on using hashes here.

Provenance

The following attestation bundles were made for transformers_mlinter-0.1.2.tar.gz:

Publisher: release.yml on huggingface/transformers-mlinter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transformers_mlinter-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for transformers_mlinter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 43ffa157b2ebf4d490bac1f87b48cffb4b1027eae5af7ea67fb3ea09ba7a2ded
MD5 ee49b81c4770a90619bba3069e611ece
BLAKE2b-256 a0f7bf8fb5d2be4fbc946b01a4d4441fdc467f1e75c74d6b0c042bc91417bc71

See more details on using hashes here.

Provenance

The following attestation bundles were made for transformers_mlinter-0.1.2-py3-none-any.whl:

Publisher: release.yml on huggingface/transformers-mlinter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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