🧹 Code Janitor - VSCode Extension

Code Janitor is a VSCode extension that automatically analyzes, fixes, and formats code for multiple programming languages, including Python, C/C++/Arduino, Java, and JavaScript. It ensures your code is clean, consistent, and follows proper syntax conventions.
🔹 Features
1. Multi-language Support
- Python (
.py files)
- Fixes indentation, missing colons, and common syntax issues.
- Formats code using
black.
- C / C++ / Arduino (
.c, .cpp, .h, .ino files)
- Fixes semicolons, braces, function structure, and MCU-specific syntax.
- Formats code using
uncrustify.
- Java (
.java files)
- Fixes indentation, missing semicolons, and common Java syntax issues.
- JavaScript (
.js, .jsx files)
- Fixes semicolons, braces, and common JS syntax issues.
- Formats using standard JS conventions.
- HTML (
.html files)
- Fixes indentation issues.
- Fixes syntax issues like missing closing tags.
2. Automatic Fixing
- Runs before saving a file.
- Detects language automatically.
- Applies fixes without manual intervention.
3. Manual Command
- Run the Code Janitor command from the Command Palette:
Installation (via npm)
npm install -g code-janitor
Or clone & install locally:
git clone https://github.com/Debanshu2005/code-janitor.git
cd code-janitor
npm install
Usage
Run CLI
code-janitor
- Instantly analyzes and fixes the active file.
Fallback Fixing
- If primary formatters fail (
black or uncrustify), the extension applies basic syntax and formatting fixes to keep your code functional.
🔹 Installation (via VS Code)
- Clone the repository:
git clone https://github.com/Debanshu2005/code-janitor.git
cd code-janitor
Open the project in VSCode.
Press F5 to launch the extension in a new VSCode window (Extension Development Host).
Install required formatters:
Python:
pip install black
C/C++: Install uncrustify and ensure the path is correctly set in formatter-paths.js.
Usage
Manual Fix
Open a supported file in VSCode.
Press Ctrl+Shift+P → Code Janitor: Fix Code or press alt+D.
The file will be analyzed and automatically fixed.
Auto-fix on Save.
Open any supported file.
Save (Ctrl+S) and watch Code Janitor auto-correct issues before the save completes.
npm run format:js # JavaScript
npm run format:java # Java
npm run format:py # Python
npm run format:c # C/C++
Example
Before:
#include <stdio.h>
int main() {
printf("Hello world")
return 0
}
After Code Janitor:
#include <stdio.h>
int main() {
printf("Hello world");
return 0;
}
Before:
def greet()
print("Hello World")
if True
print("Yes")
After Code Janitor:
def greet():
print("Hello World")
if True:
print("Yes")
Before:
function greet()
console.log("Hello World")
After Code Janitor:
function greet() {
console.log("Hello World");
}
🔹 Supported File Types
| Language |
Extensions / VSCode languageId |
| Python |
.py / python |
| C / C++ / Arduino |
.c, .cpp, .h, .ino / c, cpp |
| Java |
.java / java |
| JavaScript |
.js, .jsx / javascript, javascriptreact |
| HTML |
.html |
🔹 Advanced Features
MCU-specific C fixes for STM32, AVR, and ESP32.
Consecutive block-level indentation fixes for Python.
Fallback formatting ensures code never breaks even if external formatters fail.
Detailed logs for applied fixes, warnings, and errors in the console.
Contributing
Fork → create branch → commit → push → PR
Ensure formatters & syntax fixes are consistent
Fork the repository.
Create a branch: git checkout -b feature/my-fix.
Make your changes.
Commit your work: git commit -m "Added feature / fixed bug".
Push to your branch: git push origin feature/my-fix.
Create a Pull Request.
🔹 Acknowledgements
https://github.com/psf/black --> Python Code Formatter
https://github.com/uncrustify/uncrustify --> C/C++ code formatter
VSCode API & Extension Documentation
License
MIT License © Debanshu2005