Lintrunner Adapters

0.13.0 · active · verified Sun Apr 12

Lintrunner Adapters provides a collection of wrappers and tools that integrate various linters (like Black, Ruff, Pylint, Bandit, etc.) with the `lintrunner` framework. It enables unified linting across a project using a single configuration. The current version is 0.13.0, and releases are frequent, primarily adding new linter adapters or fixing issues with existing ones.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `lintrunner` to use adapters from `lintrunner-adapters`. You define linters in a `lintrunner.toml` file, specifying the `linter_class` as a string path to the adapter. You must install `lintrunner` and the underlying linters (e.g., `ruff`, `black`) separately. The example creates a `test_file.py` and `lintrunner.toml` locally, and then provides instructions on how to execute `lintrunner` to apply the configured linters.

import os

# 1. Create a sample Python file to lint
python_code = """def foo ( x ):\n  return x+1\n"""
with open("test_file.py", "w") as f:
    f.write(python_code)

# 2. Create a lintrunner.toml configuration (simulating user setup)
# In a real project, this would be a file named `lintrunner.toml`
lintrunner_toml_content = """
[linter.ruff]
linter_class = "lintrunner_adapters.ruff_linter:RuffLinter"

[linter.black]
linter_class = "lintrunner_adapters.black_linter:BlackLinter"
args = ["--check", "--diff"]
"""
with open("lintrunner.toml", "w") as f:
    f.write(lintrunner_toml_content)

# 3. Ensure lintrunner and the linters are installed for this example to run
# In a real setup, `pip install lintrunner ruff black` would be done.
# We can't actually run lintrunner directly in this snippet, but demonstrate setup.
print("Created test_file.py and lintrunner.toml. To run, execute:")
print("pip install lintrunner ruff black")
print("lintrunner --config lintrunner.toml test_file.py")

# Clean up (optional, for standalone execution)
# os.remove("test_file.py")
# os.remove("lintrunner.toml")

view raw JSON →