CodeNullCheck - VS Code Extension
A powerful VS Code extension that performs thorough code review by detecting:
- Nullptr/null issues: Checks for null pointer dereferences, redundant null checks, and unsafe dereferences
- Redundant database calls: Identifies duplicate queries, N+1 problems, and inefficient database access patterns
Features
Nullptr Detection
- Detects potential nullptr/null dereferences before they cause crashes
- Identifies redundant null checks
- Warns about assignments to null
- Detects double null checks
- Flags unsafe pointer dereferences
Database Call Analysis
- Detects duplicate/identical database queries
- Identifies redundant DB calls within close proximity
- Warns about database calls inside loops (N+1 problem)
- Detects un-cached database results
- Reports inefficient query patterns
Installation
Option 1: From Source
# Navigate to the extension directory
cd C:\Users\om naladkar\Desktop\code-review-extension
# Install dependencies
npm install
# Package the extension
npm install -g vsce
vsce package
# Install the .vsix file
code --install-extension code-review-assistant-1.0.0.vsix
Option 2: Development Mode
cd C:\Users\om naladkar\Desktop\code-review-extension
npm install
code .
# Press F5 to run in debug mode
Usage
Commands
Open Command Palette (Ctrl+Shift+P) and search for "Code Review":
- Code Review: Run Review - Run full code review on current file
- Code Review: Check Nullptr Issues - Check only nullptr/null issues
- Code Review: Check Redundant DB Calls - Check only database call issues
- Code Review: Show Problems - Open the Problems panel
Right-click in the editor and select "Run Code Review" for quick access.
Auto-Review
The extension automatically runs analysis on:
- File save
- File open
- Active editor change
Configuration
Customize the extension in VS Code Settings (File > Preferences > Settings):
{
"codeReview.showNullptrWarnings": true,
"codeReview.showDbCallWarnings": true,
"codeReview.enableOnSave": true,
"codeReview.dbCallPatterns": [
"db.query",
"db.find",
"db.get",
"connection.execute",
"connection.query",
"session.query",
"Entity.objects",
"collection.find",
"repository.",
"DataContext"
],
"codeReview.nullptrPatterns": [
"null",
"nullptr",
"None",
"nil",
"undefined"
]
}
Supported Languages
- C/C++ (.c, .cpp, .h, .hpp)
- JavaScript/TypeScript (.js, .ts, .jsx, .tsx)
- Python (.py)
- Java (.java)
- C# (.cs)
Issue Types
Nullptr Issues (Code: NULLPTR_*)
| Code |
Severity |
Description |
| NULLPTR_001 |
Warning |
Potential nullptr dereference |
| NULLPTR_002 |
Info |
Redundant nullptr check |
| NULLPTR_003 |
Warning |
Assignment to null |
| NULLPTR_004 |
Error |
Double nullptr check |
| NULLPTR_005 |
Warning |
Unsafe dereference |
Database Issues (Code: DB_*)
| Code |
Severity |
Description |
| DB_001 |
Warning |
Redundant database call |
| DB_002 |
Warning |
Duplicate database query |
| DB_003 |
Error |
N+1 query problem (loop) |
| DB_004 |
Warning |
Potential N+1 query |
| DB_005 |
Info |
Uncached DB result |
Example Detections
Nullptr Detection
// BEFORE (will be flagged)
if (ptr->GetData() != nullptr) { // NULLPTR_001
// ...
}
// AFTER (correct)
if (ptr != nullptr) {
ptr->GetData();
}
Redundant DB Call Detection
// BEFORE (will be flagged)
const user = await db.find({ id: 1 });
const sameUser = await db.find({ id: 1 }); // DB_001
// AFTER (correct)
const user = await db.find({ id: 1 });
// Reuse 'user' variable
Troubleshooting
Extension not loading
- Check Output panel (View > Output) for errors
- Run
Developer: Reload Window
- Reinstall the extension
No issues detected
- Ensure file type is supported
- Check that patterns match your code style in settings
- Try running manual review with the command
Contributing
To extend this extension:
- Add new detection patterns to
NullptrDetector or RedundantDBCallDetector
- Update
package.json with new configuration options
- Add tests for new functionality
License
MIT License
Author
Code Review Tools Team