AI Code Linter is a desktop Python code quality tool that analyzes source code, highlights issues, and applies conservative quick fixes through a PyQt5 interface.
AI Code Linter is a lightweight desktop application designed to help developers spot bugs, code smells, and risky patterns in Python code before they ship. It combines rule-based static analysis with a simple GUI, making it useful for students, solo developers, and teams that want a fast local code-review helper without relying on a cloud service.
The project focuses on practical code-quality checks such as syntax errors, unused variables, magic numbers, suspicious calls like eval() / exec(), and hard-coded credentials. It also includes conservative auto-fix logic for common patterns, such as off-by-one loops, == None comparisons, bare except: blocks, and missing colons in simple block headers.
The repository is structured as a portfolio-ready desktop software project: it has a working UI, analysis engine, fixer utilities, sample test harnesses, and a placeholder for future CodeBERT integration. That makes it a solid example of combining UI engineering, static analysis, and machine learning architecture planning in one codebase.
- PyQt5 desktop interface with:
- source editor
- corrected-code preview panel
- analysis report pane
- suggestions list
- status bar and progress indicator
- AST-based Python analysis for:
- syntax errors
- unused variables
- magic numbers
- dangerous function usage (
eval,exec,execfile) - suspicious string concatenation patterns
- hard-coded credential heuristics
- Optional auto-formatting via
autopep8 - Conservative quick-fix engine in
fixer.pyfor:range(len(x) + 1)off-by-one corrections- simple index-based loop rewrites
- bare
except:replacement == None/!= Nonenormalization- missing colon repair for basic block headers
- Non-Python input detection to avoid mangling Java/C/C++-style code
- Division-by-zero heuristic that can flag likely runtime errors and insert a basic guard when auto-fix is enabled
- File open/save support for loading source files and exporting corrected code
- Basic syntax highlighting for Python keywords, strings, and comments
- CodeBERT stub prepared for future transformer-based analysis
| Category | Technologies |
|---|---|
| Language | Python |
| Desktop UI | PyQt5 |
| Static analysis | ast, re |
| Auto-formatting | autopep8 |
| ML / NLP integration | transformers, torch |
| Code generation / rewriting | astor |
| Export / reporting | reportlab |
Detected project type: Python desktop application with rule-based analysis and optional ML integration.
The project is intentionally small and modular:
main.pyis the application entry point.ui/main_ui.pybuilds the desktop interface and wires button actions to the analyzer.linter.pyperforms the main code analysis and produces:- human-readable reports
- a fixed-code preview
- line numbers to highlight
- a list of applied fixes
fixer.pycontains conservative text-based transformations used whenauto_fix=True.models/codebert_stub.pyis a lazy-loading placeholder for CodeBERT inference.- Test scripts like
test_linter.pyandrun_fixer_tests.pyact as manual regression checks.
- The user pastes or opens Python code in the editor.
CodeLinterUIcallsanalyze_code()fromlinter.py.linter.pyparses the code withast.parse()and runs heuristic checks.- If
auto_fix=True, the analyzer also callsfixer.apply_fixes()and may apply extra guard logic for obvious zero-divisor cases. - The UI displays:
- the report text
- the corrected preview
- highlighted lines
- fix suggestions in the sidebar
- The analyzer is rule-based first, which keeps the app fast, deterministic, and easy to reason about.
- Fixes are conservative on purpose, reducing the risk of changing code incorrectly.
- The CodeBERT integration is stubbed rather than forced into the runtime, which keeps the current app lightweight while leaving room for future ML upgrades.
- Python 3.9 or newer
- Windows, macOS, or Linux
- A virtual environment is strongly recommended
git clone https://github.com/Abdullahjaved-82/AI-code-Linter.git
cd AI-code-LinterWindows PowerShell
python -m venv .venv
.\.venv\Scripts\Activate.ps1macOS / Linux
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtIf you want the UI to open and run with the fewest missing pieces, install the main desktop dependency explicitly if needed:
pip install PyQt5The repository includes transformers and torch for future CodeBERT support. If you plan to use the model stub, make sure those packages are installed correctly in your environment.
python main.pypython main.py- Paste Python code into the editor.
- Click Analyze to generate a report and preview formatted output.
- Click Quick Fix to apply conservative automated fixes.
- Review the corrected code in the preview panel.
- Use Save to export the cleaned-up file.
The analyzer returns a tuple like:
report_text, fixed_code, highlight_lines, applied_fixesfrom linter import analyze_code
code = """
def broken_divide(a, b)
return a / b
"""
report, fixed, highlights, applied = analyze_code(code, auto_fix=True)
print(report)
print(fixed)
print(highlights)
print(applied)from fixer import apply_fixes
code = """
for i in range(len(arr) + 1):
print(arr[i])
"""
new_code, fixes = apply_fixes(code)
print(new_code)
print(fixes)from models.codebert_stub import predict
result = predict("def add(a, b): return a + b")
print(result)Note:
codebert_stub.pyis currently a placeholder loader. It will return an error field or placeholder score unless the model is available and a classifier head is implemented.
There is no HTTP API in this repository. The project is a desktop application with Python functions that serve as the internal API.
Analyzes Python code and returns:
(report_text: str, fixed_code: str, highlight_lines: list[int], applied_fixes: list[dict]){
"report_text": "Found 1 errors, 2 warnings, 3 info...",
"fixed_code": "...",
"highlight_lines": [3, 8, 12],
"applied_fixes": [
{
"line": 8,
"message": "Replaced bare except with except Exception as e",
"original": "except:\n",
"replacement": "except Exception as e:\n"
}
]
}Applies deterministic quick-fix rules and returns:
(new_code: str, fixes: list[dict])Attempts small syntax repairs such as inserting missing colons:
(new_code: str, fixes: list[dict])Returns a placeholder model response:
{
"label": "unknown",
"score": 0.0,
"error": "..."
}AI-code-Linter/
├── main.py # Application entry point
├── linter.py # AST-based analyzer and reporting logic
├── fixer.py # Safe heuristic quick-fix utilities
├── ui/
│ └── main_ui.py # PyQt5 GUI, actions, highlighting, save/open flow
├── models/
│ └── codebert_stub.py # Lazy-loading CodeBERT placeholder
├── test_linter.py # End-to-end analyzer test harness
├── run_fixer_tests.py # Rule-focused fixer test runner
├── demo_logic_exception_test.py # Sample code for analyzer demo
├── demo_wrong_code_test.py # Sample code for analyzer demo
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── PROJECT_SUMMARY.txt # Concise project summary
main.py— starts the PyQt5 application.ui/main_ui.py— handles the desktop experience and user actions.linter.py— performs AST analysis and generates reports.fixer.py— contains safe code-repair transformations.models/codebert_stub.py— future ML integration point.- demo/test scripts — provide sample inputs and manual verification flows.
One of the main engineering challenges in this project is balancing automation with safety. The fixer logic in fixer.py is intentionally conservative so that automated changes do not introduce new bugs while still resolving common patterns like off-by-one loops and bare exception handling.
Another important learning is how to combine static analysis, formatting, and GUI state management into a single workflow. The UI in ui/main_ui.py has to handle analysis results, fix previews, line highlighting, saving files, and status updates without making the application feel complex to the user.
A third takeaway is designing for future ML integration without blocking the current product. The models/codebert_stub.py module shows how a transformer-based workflow can be introduced later while keeping the current release lightweight and functional.
- Add a real trained classifier head for the CodeBERT pipeline
- Improve fix selection so users can accept or reject individual suggestions
- Add unit tests and CI via GitHub Actions
- Make the analyzer thread-safe for long-running model inference
- Expand support for more Python anti-patterns and runtime risks
- Improve the division-by-zero guard insertion logic
- Add export options for HTML, PDF, or JSON reports
- Package the app with PyInstaller for easier distribution