Fixit: Advanced Python Linting Framework with Autofixes

2.2.1 · active · verified Thu Apr 16

Fixit is an advanced Python linting framework developed by Meta, providing robust auto-fixing capabilities and hierarchical configuration. Built on LibCST, it allows for precise code modifications and makes it straightforward to write custom, in-repo lint rules. Fixit includes a wide array of built-in lint rules, optimizing for efficiency and ease of customization. The current version is 2.2.1, and it undergoes active development with a consistent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use Fixit from the command line to lint a Python file and then apply available autofixes. It creates a temporary Python file with common linting issues, runs `fixit lint` to identify them, and then `fixit fix` to resolve them automatically.

import os
import subprocess

# Create a dummy Python file
with open('my_module.py', 'w') as f:
    f.write('x =  1\n')
    f.write('def foo():\n')
    f.write('    return 1 +  2 # Bad spacing\n')
    f.write('class MyClass(object): # Inheriting from object is redundant in Python 3\n')
    f.write('    pass\n')

# Run fixit lint to see issues
print('--- Running fixit lint ---')
subprocess.run(['fixit', 'lint', 'my_module.py'])

# Run fixit fix to apply autofixes
print('\n--- Running fixit fix ---')
subprocess.run(['fixit', 'fix', 'my_module.py'])

# Print the fixed file content
print('\n--- Fixed file content ---')
with open('my_module.py', 'r') as f:
    print(f.read())

# Clean up
os.remove('my_module.py')

view raw JSON →