Add a new TRF rule to the mlinter. Checks for duplicates, creates the rule module and TOML entry, runs against all models, and handles violations (fix or allowlist).
npx skills add https://github.com/huggingface/transformers-mlinter --skill add-mlinter-rule
<description>: Natural-language description of what the rule should detect.ast module. NEVER import runtime libraries like torch or tensorflow.check(tree, file_path, source_lines) -> list[Violation] interface.RULE_ID constant instead of hardcoding the rule ID string.mlinter/rules.toml.mlinter/trf*.py files and find the highest number.mlinter/rules.toml.[rules.TRFXXX] section at the end of the file with:descriptiondefault_enabled = trueallowlist_models = [][rules.TRFXXX.explanation] with what_it_does, why_bad, and diffmlinter/trfXXX.py.trf*.py file."""TRFXXX: <short description>."""ast, Path, and any needed helpers from ._helpers.RULE_ID = "" # Set by discovery.def check(tree: ast.Module, file_path: Path, source_lines: list[str]) -> list[Violation]:.mlinter/trf*.py for patterns and helpers. python -m mlinter --enable-rules TRFXXX
allowlist_models in mlinter/rules.toml.allowlist_models.tests/test_mlinter.py.mlinter.analyze_file(), and assert on violations.tempfile.TemporaryDirectory to create real file structures. pytest tests/test_mlinter.py -x -v -k "trfXXX"
## [Unreleased] section of CHANGELOG.md (create that section above the latest released version if it does not yet exist) describing the new rule. Mention any incidental changes shipped with it (e.g. expanding MODELING_PATTERNS to cover new file types), since those affect every rule.README.md, update the README accordingly. make lint
make test
The mlinter processes files one at a time via analyze_file(file_path, text, enabled_rules). When a rule needs cross-file information, the rule module must read the other file from disk. Watch for these patterns:
Some model directories contain multiple configuration files. Match by suffix first:
modeling_foo_text.py -> configuration_foo_text.py.
Only fall back to a generic configuration_*.py pick when there is no exact suffix match.
A single configuration_*.py file can define multiple config classes. If the rule is checking a property that belongs to one specific config class, do not accept the first matching class in the file. Resolve the modeling class's target config class first:
config_class from the model class, following local modeling inheritance if a parent *PreTrainedModel declares it.config_class, infer the best match from class names, usually by longest shared prefix.Then validate only that config class.
Some config classes inherit from another model config rather than directly from PreTrainedConfig. If the base class is not PreTrainedConfig or PretrainedConfig and still ends with Config, assume the field may be inherited and skip the violation unless the rule specifically needs stricter handling.
tie_word_embeddings is not in PreTrainedConfigThe base PreTrainedConfig does not define tie_word_embeddings. When a rule needs it, the model config must declare it explicitly, either as a class attribute or through self.tie_word_embeddings = ... in initialization code.
mlinter/trf*.pymlinter/rules.tomlmlinter/_helpers.pytests/test_mlinter.pyREADME.mdTake huggingface/add-mlinter-rule from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.