{"id":8991,"library":"fixit","title":"Fixit: Advanced Python Linting Framework with Autofixes","description":"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.","status":"active","version":"2.2.1","language":"en","source_language":"en","source_url":"https://github.com/Instagram/Fixit","tags":["linting","autofix","static analysis","code quality","refactoring","libcst"],"install":[{"cmd":"pip install fixit","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Fixit is built on LibCST for parsing Python code and applying accurate code modifications.","package":"libcst","optional":false}],"imports":[{"symbol":"LintRule","correct":"from fixit import LintRule"},{"note":"Used for defining invalid code examples in custom lint rule tests. Also 'Invalid' is an alias.","symbol":"InvalidTestCase","correct":"from fixit import InvalidTestCase"},{"note":"Used for defining valid code examples in custom lint rule tests. Also 'Valid' is an alias.","symbol":"ValidTestCase","correct":"from fixit import ValidTestCase"},{"note":"Configuration types and utilities have moved to `fixit.ftypes`.","wrong":"from fixit.configuration import Configuration","symbol":"Configuration","correct":"from fixit.ftypes import Configuration"}],"quickstart":{"code":"import os\nimport subprocess\n\n# Create a dummy Python file\nwith open('my_module.py', 'w') as f:\n    f.write('x =  1\\n')\n    f.write('def foo():\\n')\n    f.write('    return 1 +  2 # Bad spacing\\n')\n    f.write('class MyClass(object): # Inheriting from object is redundant in Python 3\\n')\n    f.write('    pass\\n')\n\n# Run fixit lint to see issues\nprint('--- Running fixit lint ---')\nsubprocess.run(['fixit', 'lint', 'my_module.py'])\n\n# Run fixit fix to apply autofixes\nprint('\\n--- Running fixit fix ---')\nsubprocess.run(['fixit', 'fix', 'my_module.py'])\n\n# Print the fixed file content\nprint('\\n--- Fixed file content ---')\nwith open('my_module.py', 'r') as f:\n    print(f.read())\n\n# Clean up\nos.remove('my_module.py')","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the 'Upgrading' guide in the official documentation. Migrate `.fixit.config.yaml` to `pyproject.toml` or `fixit.toml` using the new TOML format. Update custom lint rules to align with the Fixit 2.x API.","message":"Fixit 2.0 (and newer) introduced a foundational rewrite from Fixit 1.x. Configuration files changed from YAML to TOML (e.g., `pyproject.toml` or `fixit.toml`), rule referencing syntax was updated, and the internal API for custom rules changed significantly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace all instances of `# noqa` with `# lint-ignore` or `# lint-fixme` in your codebase. You can optionally specify rule names after the directive for granular suppression.","message":"Flake8-style suppression comments (`# noqa`) are no longer supported in Fixit 2.x. They have been replaced by `# lint-ignore` or `# lint-fixme` directives.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"This is a known issue (GitHub issue #427). A workaround might involve running `fixit fix` separately from formatter runs, or inspecting `fixit`'s output carefully when an external formatter is also in use.","message":"Fixit's autofix functionality might not work as expected when integrated with external formatters like 'Black' if Black makes no changes to the file. This can lead to a state where `fixit fix` reports no changes, even if lint issues are present that Fixit *could* fix.","severity":"gotcha","affected_versions":"All 2.x versions"},{"fix":"If interactive fixes are desired, set `parallel=False` when calling relevant API functions. For fully automated fixes, set `autofix=True`.","message":"When using `fixit_file()` or similar functions with `parallel=True` (for multiprocessing), Fixit currently does not support applying individual fixes interactively. Automated autofix (`autofix=True`) will still apply changes, but interactive selection is disabled.","severity":"gotcha","affected_versions":"All 2.x versions"},{"fix":"Monitor Fixit's performance on your codebase. Consider implementing caching mechanisms if not already integrated. The Fixit team has plans for future performance improvements, including caching.","message":"While Fixit offers per-file multiprocessing for performance, it may still be slow on very large codebases without caching or further optimizations.","severity":"gotcha","affected_versions":"All 2.x versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Migrate your `.fixit.config.yaml` to `pyproject.toml` or `fixit.toml`. Rules are now enabled using `enable = [\"mypackage.rules:CustomLintRule\", \"another_package.rules\"]` in the `[tool.fixit]` section.","cause":"The configuration format for Fixit 2.x changed from YAML to TOML, and the way rules are enabled/disabled also changed. Older configuration files are no longer valid.","error":"KeyError: 'rules' or similar when running fixit with custom rules after upgrade."},{"fix":"Update your custom lint rule definitions. The primary base class for new rules is now `fixit.LintRule`. Review the 'Upgrading' guide and API reference for specific class name changes.","cause":"The base class for custom lint rules and other core API types were renamed or refactored in Fixit 2.x for conciseness.","error":"AttributeError: 'module' object has no attribute 'LegacyRule' or 'BaseLintRule'"},{"fix":"Ensure both `fixit` and `libcst` are updated to their latest versions compatible with your Python interpreter (`pip install --upgrade fixit libcst`). Fixit requires Python >=3.9.","cause":"Fixit relies on LibCST for parsing. If your Python environment's LibCST version is outdated, it might not support the latest Python syntax features.","error":"SyntaxError: invalid syntax (on newer Python features) or similar parsing errors."}]}