Lintrunner

0.13.0 · active · verified Sat Apr 11

Lintrunner is a command-line tool designed to orchestrate and run various linters across polyglot projects. It centralizes linter configuration, standardizes linter invocation via a common protocol, and aggregates results for user presentation. The current version is 0.13.0, and releases appear to be on an as-needed basis rather than a fixed cadence, reflecting its active development, particularly within the Meta/PyTorch ecosystem.

Warnings

Install

Quickstart

To get started with `lintrunner`, first install the tool. Then, create a `.lintrunner.toml` file in your project's root directory to define the linters and their rules. `lintrunner` primarily operates as a command-line tool, checking files that have changed in your working tree or HEAD commit by default. You can use `lintrunner init` for an initial setup that may install additional linter dependencies. For linters that aren't Python-based, `lintrunner` uses 'adapter' scripts to conform to its standard JSON Lines output protocol.

# 1. Create a .lintrunner.toml configuration file
# Example .lintrunner.toml (save this to your project root)
# merge_base_with = 'main'
#
# [[linter]]
# name = 'EXAMPLE_LINTER'
# include_patterns = ['**/*.py']
# command = ['python3', '-c',
#   'import sys; import json;\n'
#   'for path in sys.stdin.read().splitlines():\n'
#   '    with open(path) as f:\n'
#   '        content = f.read()\n'
#   '        if "TODO" in content:\n'
#   '            print(json.dumps({"path": path, "line": 1, "char": 1, "code": "TODO_FOUND", "severity": "warning", "name": "TODO check", "message": "Found a TODO in the file."}))\n'
# ]

# 2. Create a dummy Python file to lint (e.g., my_file.py)
# print("This is a test file.")
# # TODO: implement this feature

# 3. Run lintrunner from your terminal in the project root:
# pip install lintrunner
# # For basic setup, you might need to run lintrunner init
# # lintrunner init # This can install various linter dependencies
# lintrunner

# Expected output for my_file.py with the EXAMPLE_LINTER:
# Path                   Line Char Code       Severity  Name          Message
# -------------------- ------ ---- ---------- --------- ------------- ------------------------
# my_file.py                1    1 TODO_FOUND warning   TODO check    Found a TODO in the file.

view raw JSON →