-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Parser Enhancements Batch 3 - PostgreSQL Features, Security Scanner & Lint Rules #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…TURNING clause This PR adds comprehensive SQL linting rules, integrates the security scanner into the CLI analyzer, and adds RETURNING clause support for DML statements. ## Security Scanner Integration (#154) - Integrated `pkg/sql/security` scanner into CLI's `SQLAnalyzer` - Now detects SQL injection patterns (tautologies, UNION-based, time-based) - Added `convertSecurityFindings()` to map security findings to analysis issues - Security score adjustments based on finding severity ## Phase 1 Lint Rules Complete (#155) Added 7 new lint rules for comprehensive SQL style checking: ### Whitespace Rules - **L003**: Consecutive blank lines detection with auto-fix - **L004**: Indentation depth check (warns on excessive nesting) - **L010**: Redundant whitespace detection (multiple spaces) with auto-fix ### Style Rules - **L006**: SELECT column alignment checking - **L008**: Comma placement consistency (trailing vs leading) - **L009**: Table aliasing consistency detection ### Keyword Rules - **L007**: Keyword case consistency with auto-fix (upper/lowercase) ## RETURNING Clause Support (#159) - Added `TokenTypeReturning` (379) for RETURNING keyword - Parser now supports RETURNING clause for INSERT, UPDATE, DELETE - Added `parseReturningColumns()` for parsing return expressions - Supports: column names, *, qualified names, expressions ## Additional Improvements - Added ALTER TABLE operation keywords (ADD, COLUMN, CONSTRAINT, RENAME, TO) - Extended SQL formatter with `AlterStatement` support - Comprehensive battle tests for all lint rules (50+ test cases) - Fixed L004 bug: depth > 9 now displays correctly in messages ## Test Results - All tests pass with race detection enabled - golangci-lint: 0 issues - 78+ lint-related tests covering edge cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Go 1.24 CI jobs were failing because: 1. setup-go installs Go 1.24 2. Go 1.24 sees `toolchain go1.25.0` in go.mod and auto-downloads it 3. setup-go then tries to restore cache with the same toolchain files 4. Cache extraction fails with "Cannot open: File exists" errors Fix by setting GOTOOLCHAIN=local to prevent auto-download, and fail-fast: false to run all matrix combinations even if one fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add CAST keyword to tokenizer keywordTokenTypes map (#167) - Fix || operator test with correct TokenTypeSingleQuotedString (#168) - Add SetOperation support to SQL formatter for UNION/EXCEPT/INTERSECT - Expand security scanner with UNION injection and stacked query detection (#170) - Add comprehensive linter test coverage (489 tests) (#165) - Verify recursive CTE parsing with UNION/UNION ALL (#166) - Verify MERGE CLI validation (#169) All 6 issues verified and closed: - #165: Linter test coverage - 489 tests, 67-96% coverage - #166: Recursive CTE parsing - 24 tests passing - #167: CAST expressions - tokenizer fix applied - #168: || operator - test fix applied - #169: MERGE CLI - full validation working - #170: Security scanner - 100% detection rate 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Parser Enhancements: - Add PostgreSQL DISTINCT ON clause support with multi-column expressions - Implement SQL:2003 FILTER clause for aggregate functions - Add comprehensive test coverage (8 DISTINCT ON tests, 13 FILTER tests) CLI Formatter: - Add MERGE statement formatter with full clause support - Handle WHEN MATCHED/NOT MATCHED with UPDATE/INSERT/DELETE actions - Add 18 test cases for MERGE formatting scenarios Changes: - pkg/sql/ast/ast.go: Add DistinctOnColumns field to SelectStatement - pkg/sql/parser/select.go: Parse DISTINCT ON (expr, ...) syntax - pkg/sql/parser/window.go: Parse FILTER (WHERE condition) after aggregates - cmd/gosqlx/cmd/sql_formatter.go: Format MERGE statements - pkg/sql/keywords/keywords.go: Add FILTER keyword recognition New Test Files: - pkg/sql/parser/distinct_on_test.go (8 tests) - pkg/sql/parser/filter_clause_test.go (13 tests) - cmd/gosqlx/cmd/merge_formatter_test.go (18 tests) - examples/distinct_on_example.go (usage example) Related GitHub Issues: #171-#175 (PostgreSQL feature roadmap) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @ajitpratap0's task —— View job Comprehensive Code Review Complete ✅I've conducted a thorough analysis of this major release (+7,417 lines across 42 files). Here's my detailed feedback: 🎯 Overall Assessment: EXCELLENT ⭐⭐⭐⭐⭐This is a well-architected, production-ready implementation that follows GoSQLX's established patterns and maintains the project's high quality standards. ✅ Strengths1. Parser Enhancements - Outstanding Implementation
Code Quality: All parser functions follow established patterns with proper error handling and object pooling. 2. Security Scanner - Production-Grade Enhancement
Notable Security Patterns:
3. Linter Rules - Well-Designed Architecture
Rule Quality:
4. Memory Management - Exemplary✅ Perfect Object Pool Usage: Every test file properly uses 5. Test Coverage - Comprehensive
💡 Areas for Minor Improvement1. Error Context EnhancementLocation: // Current - good but could be enhanced
return nil, goerrors.InvalidSyntaxError(
fmt.Sprintf("failed to parse BETWEEN lower bound: %v", err),
models.Location{Line: 0, Column: 0}, // Zero location
"",
)Suggestion: Use actual token locations for better debugging: return nil, goerrors.InvalidSyntaxError(
fmt.Sprintf("failed to parse BETWEEN lower bound: %v", err),
p.currentLocation(), // Actual location
p.currentToken.Literal,
)2. Recursion Depth ConstantsLocation: Consider extracting magic numbers to named constants: const (
MaxExpressionDepth = 1000
DefaultRecursionLimit = 500
)3. Security Scanner Regex OptimizationLocation: The pre-compiled patterns are excellent. Consider adding regex benchmarks to ensure performance under load. 🔍 Code Quality AssessmentArchitecture Compliance: ✅ Perfect
Performance Impact: ✅ Minimal
Thread Safety: ✅ Excellent
Error Handling: ✅ Robust
🚀 CLI & Tooling ImprovementsMERGE Statement Formatter: Excellent implementation with 18 test casesEnhanced Analyzer: Good complexity metrics and table usage trackingImproved Validation: Better error messages with context🧪 Testing AssessmentCoverage: ⭐⭐⭐⭐⭐ Outstanding
Quality: ⭐⭐⭐⭐⭐ Excellent
🛡️ Security Review✅ No security concerns identified 🏆 Final Recommendation: APPROVEThis PR represents exceptional engineering work that:
The implementation quality matches the project's "production-ready" status and is ready for immediate deployment. Minor suggestions above are for future consideration - they don't block this excellent contribution. |
Lint Fixes:
- Remove redundant nil checks in filter_clause_test.go (staticcheck S1009)
- len() for nil slices is defined as zero, so nil check is unnecessary
Error Context Improvements (per review suggestion):
- Use p.currentLocation() instead of empty Location{Line: 0, Column: 0}
- Include p.currentToken.Literal for better debugging context
- Applied to BETWEEN, LIKE, and IN subquery error messages
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @ajitpratap0's task —— View job Comprehensive Code Review Complete ✅I've conducted a thorough analysis of this major release (+7,417 lines across 42 files). Here's my detailed feedback: 🎯 Overall Assessment: EXCELLENT ⭐⭐⭐⭐⭐This is a well-architected, production-ready implementation that follows GoSQLX's established patterns and maintains the project's high quality standards. ✅ Strengths1. Parser Enhancements - Outstanding Implementation
Code Quality: All parser functions follow established patterns with proper error handling and object pooling. 2. Security Scanner - Production-Grade Enhancement
Notable Security Patterns:
3. Linter Rules - Well-Designed Architecture
Rule Quality:
4. Memory Management - Exemplary✅ Perfect Object Pool Usage: Every test file properly uses 5. Test Coverage - Comprehensive
💡 Areas for Minor Improvement1. Error Context EnhancementLocation: // Current - good but could be enhanced
return nil, goerrors.InvalidSyntaxError(
fmt.Sprintf("failed to parse BETWEEN lower bound: %v", err),
models.Location{Line: 0, Column: 0}, // Zero location
"",
)Suggestion: Use actual token locations for better debugging: return nil, goerrors.InvalidSyntaxError(
fmt.Sprintf("failed to parse BETWEEN lower bound: %v", err),
p.currentLocation(), // Actual location
p.currentToken.Literal,
)2. Recursion Depth ConstantsLocation: Consider extracting magic numbers to named constants: const (
MaxExpressionDepth = 1000
DefaultRecursionLimit = 500
)3. Security Scanner Regex OptimizationLocation: The pre-compiled patterns are excellent. Consider adding regex benchmarks to ensure performance under load. 🔍 Code Quality AssessmentArchitecture Compliance: ✅ Perfect
Performance Impact: ✅ Minimal
Thread Safety: ✅ Excellent
Error Handling: ✅ Robust
🚀 CLI & Tooling ImprovementsMERGE Statement Formatter: Excellent implementation with 18 test casesEnhanced Analyzer: Good complexity metrics and table usage trackingImproved Validation: Better error messages with context🧪 Testing AssessmentCoverage: ⭐⭐⭐⭐⭐ Outstanding
Quality: ⭐⭐⭐⭐⭐ Excellent
🛡️ Security Review✅ No security concerns identified 🏆 Final Recommendation: APPROVEThis PR represents exceptional engineering work that:
The implementation quality matches the project's "production-ready" status and is ready for immediate deployment. Minor suggestions above are for future consideration - they don't block this excellent contribution. |
Review Comments Addressed ✅Thank you for the thorough code review! I've addressed the feedback: Lint Fixes (commit
|
Description
Major feature release implementing PostgreSQL-specific SQL features, enhanced security scanning, comprehensive linter rules, and CLI improvements. This batch adds +7,417 lines of production-ready code with extensive test coverage.
Type of Change
Summary
🎯 Parser Enhancements
🔒 Security Scanner Enhancements
📏 New Linter Rules (6 Rules)
🖥️ CLI Improvements
Changes Made
Parser (
pkg/sql/parser/)select.go: PostgreSQL DISTINCT ON clause parsingwindow.go: SQL:2003 FILTER clause for aggregatesexpressions.go: CAST expression handling, operator fixescte.go: Recursive CTE improvementsdml.go: RETURNING clause supportAST (
pkg/sql/ast/)DistinctOnColumnsfield to SelectStatementSecurity (
pkg/sql/security/)scanner.go: Enhanced injection detection patternsLinter (
pkg/linter/rules/)keywords/keyword_case.go: SQL keyword case enforcementstyle/aliasing_consistency.go: AS keyword usage rulesstyle/column_alignment.go: Multi-line alignment checksstyle/comma_placement.go: Comma position ruleswhitespace/: Indentation and whitespace rulesCLI (
cmd/gosqlx/cmd/)sql_formatter.go: MERGE statement formatting (+262 lines)sql_analyzer.go: Enhanced complexity analysisvalidator.go: Improved error contextNew Test Files (15 files, +4,800 lines)
pkg/sql/parser/distinct_on_test.go(469 lines)pkg/sql/parser/filter_clause_test.go(417 lines)pkg/sql/parser/cast_test.go(319 lines)pkg/sql/parser/operators_test.go(160 lines)pkg/sql/security/scanner_test.go(295 lines)pkg/linter/rules/battle_test.go(652 lines)pkg/linter/rules/keywords/keyword_case_test.go(472 lines)pkg/linter/rules/style/aliasing_consistency_test.go(379 lines)pkg/linter/rules/style/column_alignment_test.go(364 lines)pkg/linter/rules/style/comma_placement_test.go(458 lines)pkg/linter/rules/whitespace/redundant_whitespace_test.go(442 lines)cmd/gosqlx/cmd/merge_formatter_test.go(494 lines)cmd/gosqlx/cmd/sql_analyzer_test.go(120 lines)Testing
go test ./...)go test -race ./...)go test -bench=. ./...)Test Coverage
Performance Impact
Benchmark Results
Checklist
Related Issues
This PR addresses the following issues and roadmap items:
Closed Issues:
Related Roadmap Issues:
Example Usage
DISTINCT ON (PostgreSQL)
FILTER Clause (SQL:2003)
MERGE Statement Formatting
Additional Notes
🤖 Generated with Claude Code