EagerEye for VS Code
Real-time static analysis for detecting N+1 queries in Rails applications.
Catch N+1 queries before they hit production — right in your editor.
Table of Contents
Features
Real-time Analysis — Automatically analyzes Ruby files on save, highlighting potential N+1 issues instantly.
Problem Highlighting — Squiggly underlines show exactly where N+1 queries may occur in your code.
Quick Fixes — One-click fixes for common issues like replacing .pluck(:id) with .select(:id).
Status Bar Integration — See issue count at a glance in your VS Code status bar.
7 Detector Types — Comprehensive detection covering the most common N+1 patterns in Rails applications.
Installation
Prerequisites
Install the EagerEye gem:
gem install eager_eye
Or add to your Gemfile:
gem "eager_eye", group: :development
Install Extension
Option 1: Search for "EagerEye" in VS Code Extensions (Cmd+Shift+X / Ctrl+Shift+X)
Option 2: Install from VS Code Marketplace
Option 3: Command line:
code --install-extension hamzagedikkaya.eager-eye
Quick Start
- Open a Rails project in VS Code
- Open any Ruby file (controller, model, serializer, etc.)
- Save the file — EagerEye automatically analyzes it
- Issues appear as warnings with squiggly underlines
- Hover over underlined code to see details and suggestions
Detected Issues
EagerEye detects 7 types of N+1 query patterns:
| Detector |
Description |
| Loop Association |
Queries inside iterations (posts.each { \|p\| p.author }) |
| Serializer Nesting |
Association calls in serializer blocks |
| Missing Counter Cache |
.count/.size calls that could use counter cache |
| Custom Method Query |
.where/.find_by on associations inside loops |
| Count in Iteration |
.count inside loops (always executes query) |
| Callback Query |
N+1 patterns inside ActiveRecord callbacks |
| Pluck to Array |
.pluck(:id) used in where instead of subquery |
Quick Fixes
- Auto-fix generic N+1 queries where possible.
- Pluck to Select: Safely converts
.pluck(:id) to .select(:id) inside where clauses.
- Smart Safety: Only fixes safe patterns and ignores small collections (Info severity).
Severity Levels
- Error: Critical N+1 queries (e.g.
.all.pluck).
- Warning: Standard N+1 queries.
- Info: Low impact issues or small collections.
Example Detection
# EagerEye will warn about this:
posts.each do |post|
post.author.name # ⚠️ N+1 query detected
post.comments.count # ⚠️ COUNT query for each post
end
# Suggested fix:
posts.includes(:author, :comments).each do |post|
post.author.name # ✓ No additional query
post.comments.size # ✓ No additional query
end
Commands
Access commands via Command Palette (Cmd+Shift+P / Ctrl+Shift+P):
| Command |
Description |
EagerEye: Analyze Current File |
Manually trigger analysis on active file |
EagerEye: Analyze Workspace |
Analyze all Ruby files in workspace |
EagerEye: Clear Diagnostics |
Clear all EagerEye warnings |
Extension Settings
Configure EagerEye in VS Code settings (Cmd+, / Ctrl+,):
| Setting |
Default |
Description |
eagerEye.enable |
true |
Enable/disable the extension |
eagerEye.analyzeOnSave |
true |
Automatically analyze on file save |
eagerEye.gemPath |
eager_eye |
Path to eager_eye executable |
eagerEye.enabledDetectors |
[] |
Specific detectors to enable (empty = all) |
eagerEye.excludePatterns |
["**/spec/**", "**/test/**", "**/vendor/**"] |
Glob patterns to exclude |
Example Configuration
{
"eagerEye.enable": true,
"eagerEye.analyzeOnSave": true,
"eagerEye.excludePatterns": [
"**/spec/**",
"**/test/**",
"**/vendor/**",
"**/legacy/**"
],
"eagerEye.enabledDetectors": [
"loop_association",
"serializer_nesting"
]
}
How It Works
EagerEye uses static analysis with AST (Abstract Syntax Tree) parsing to detect potential N+1 query patterns without running your code. This means:
- No test suite required — Works on any Ruby file
- No runtime overhead — Analysis happens at parse time
- Instant feedback — See issues as you code
For comprehensive N+1 detection, use EagerEye alongside runtime tools like Bullet.
License
This extension is available as open source under the terms of the MIT License.
Made with ❤️ for the Rails community