Skip to content

Conversation

@willibrandon
Copy link
Owner

Description

This PR implements comprehensive static analysis diagnostics for the With() method introduced in PR #53. It adds five new diagnostic codes (MTLOG009-MTLOG013) to help developers catch common mistakes when using variadic key-value pairs for structured field logging.

The implementation includes:

  • MTLOG009: Detects odd argument count (missing values)
  • MTLOG010: Warns about non-string keys that will be skipped
  • MTLOG011: Identifies duplicate keys across multiple With() calls using cross-call analysis
  • MTLOG012: Suggests avoiding reserved property names (off by default)
  • MTLOG013: Detects empty string keys that will be ignored

Each diagnostic includes appropriate quick fixes to resolve the issues automatically.

Type of change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation update

Checklist

  • Tests pass (go test ./...)
  • Linter passes (golangci-lint run)
  • Benchmarks checked (if performance-related)
  • Documentation updated (if needed)
  • Zero-allocation promise maintained (if applicable)

Additional notes

  • Cross-call analysis: MTLOG011 implements data flow analysis to track property accumulation across method chains and variable assignments
  • Backward compatibility: Reuses existing MTLOG003 for single-call duplicate detection
  • Configuration: Added new flags for disabling specific With() checks and configuring reserved properties
  • Editor support: Updated VS Code, GoLand, and Neovim plugins to support the new diagnostics
  • Performance: The cross-call duplicate detection can be disabled independently if needed for very large codebases

Key implementation details:

  1. Added checkWithArguments function to analyze With() method calls
  2. Implemented CrossCallAnalyzer for tracking logger variable assignments and property accumulation
  3. All diagnostics respect existing suppression mechanisms (file-level, environment variables, config files)
  4. Comprehensive test coverage including edge cases for nil keys, interface{} types, and method chaining
  5. Quick fixes handle both line/column and pos/end formats for maximum compatibility

Breaking changes:

None. All new diagnostics are additive and respect existing configuration.

Fixes #54

- Implement MTLOG009-013 diagnostics for With() method validation
- Add cross-call duplicate detection (MTLOG011) with data flow analysis
- Support odd arguments, non-string keys, empty keys, and reserved properties
- Include suggested fixes for all With() diagnostics
- Update GoLand plugin to handle both camelCase and snake_case JSON fields
- Add test coverage for all With() validation scenarios
- Add 5 new diagnostic codes for With() method validation:
 - MTLOG009: odd argument count detection
 - MTLOG010: non-string key validation
 - MTLOG011: cross-call duplicate property detection
 - MTLOG012: reserved property name warnings
 - MTLOG013: empty key string detection

- Enhance quick fix parser to support pos/end string format
- Add comprehensive test coverage for all new diagnostics
- Update help system with explanations for new codes
- Improve error handling with validation and user feedback
- Cache namespace lookups for better performance
…OG013)

- Add diagnostic descriptions for new With() method checks
- Update suppression enum to include MTLOG009-MTLOG013
- Document new diagnostics in CHANGELOG.md
- Add cross-call duplicate example to analyzer docs
- Improve toSnakeCase() documentation with detailed transition cases
- Add tests and benchmarks for With() with up to 200 arguments
- Verify optimal performance for ≤64 fields, graceful map fallback for larger sets
- Fix circular dependency between mtlog and analyzer modules by moving reanalyze_all() to analyzer
- Fix incorrect test expectation in diagnostics_spec (should expect false when fix fails)
- Fix async callback scope issue in analyzer_spec by capturing done callback
- Update path resolution in minimal_init.lua to use absolute paths
- Make apply_suggested_fix() properly return false when edits fail

All tests now pass successfully.
…orld testing

- Remove concurrent check guards in analyzer for simpler synchronous operation
- Add high-resolution timing using vim.loop.now() for sub-second cache accuracy
- Fix cache invalidation to properly update LRU order and stats
- Enhance diagnostic edit range validation with proper bounds checking
- Replace test mocks with real mtlog-analyzer integration and file operations
- Add comprehensive test environment setup and verification scripts
- Improve cache TTL handling and cleanup with configurable intervals
- Add With() method diagnostics testing for MTLOG009-MTLOG013 support
Use vim.fn.resolve() for path comparison to handle /var -> /private/var symlink resolution on macOS in workspace_spec.lua test.
Add fix.message to format_item fallback chain to display actual analyzer fix descriptions instead of generic "Fix" labels when multiple fixes available.
@willibrandon willibrandon self-assigned this Aug 18, 2025
@willibrandon willibrandon added enhancement New feature or request tooling Development tools, build systems, and analyzers vscode Visual Studio Code extension and integration goland GoLand plugin and JetBrains IDE integration neovim Neovim plugin and editor integration mtlog-analyzer Static analysis tool for detecting mtlog usage issues labels Aug 18, 2025
Redirect stderr and check for E121 errors in health check validation to prevent "Undefined variable: s:output" when running checkhealth.
Remove fallback to legacy require('health') which causes E121: Undefined variable: s:output in CI environments.
Remove v0.8.0 and v0.9.0 from CI matrix as vim.health API is only fully functional in v0.10.0+.
- Fix health check validation on macOS where checkhealth outputs to buffer instead of stdout
- Write buffer content to file to capture health check results on all platforms
- Initialize plugin in minimal_init.lua to eliminate health check warning
- Update CI to only test Neovim v0.10.0+ where vim.health API is available
…egration test

- Remove buffer write attempt that failed due to scratch buffer restrictions
- Use Lua IO to create real file on disk for mtlog-analyzer to analyze
- Ensures test works in both local and CI environments
- Use test_helpers.create_test_go_file() to place file in Go module directory
- Fixes Ubuntu CI failure where analyzer couldn't resolve mtlog import without go.mod
- Aligns with all other passing tests that use the same approach
- Add suppression checks for MTLOG009-013 in with_checks.go
- Implement isDiagnosticSuppressed helper method
- Add tests for flag and env var suppression
- Update README with suppression documentation
- Fix GoLand plugin: timeouts, JSON parsing, path validation
- Optimize test infrastructure setup
@willibrandon willibrandon requested a review from Copilot August 19, 2025 07:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements comprehensive static analysis diagnostics for the With() method in mtlog, adding five new diagnostic codes (MTLOG009-MTLOG013) to help developers catch common mistakes when using structured field logging. The implementation includes analyzer integration, quick fixes, and comprehensive editor support.

  • Adds five new diagnostic codes for comprehensive With() method validation
  • Implements cross-call analysis to detect duplicate keys across method chains
  • Provides automatic quick fixes for all detected issues including odd argument counts and property name corrections

Reviewed Changes

Copilot reviewed 72 out of 72 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
with_longargs_test.go Performance tests for With() method handling large argument lists and edge cases
vscode-extension/mtlog-analyzer/src/types.ts Updates TypeScript definitions with new diagnostic codes MTLOG009-MTLOG013
vscode-extension/mtlog-analyzer/package.json Extends VS Code configuration to support new diagnostic suppression options
vscode-extension/mtlog-analyzer/CHANGELOG.md Documents new With() diagnostic features for VS Code extension
neovim-plugin/tests/test_helpers.lua Comprehensive test infrastructure for real file operations and analyzer integration
neovim-plugin/tests/spec/*.lua (multiple files) Extensive test coverage for all new diagnostic features, workspace management, and plugin integrations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

- Add clarifying comment for single event emission validation in with_longargs_test.go
- Make mtlog module path configurable via MTLOG_MODULE_PATH env var in test_helpers.lua
- Replace brittle string assertions with flexible pattern matching in with_diagnostics_spec.lua
- Add get_all_diagnostic_codes() function to dynamically generate diagnostic code list
@willibrandon willibrandon merged commit 1109dd6 into main Aug 19, 2025
24 checks passed
@willibrandon willibrandon deleted the feature/analyzer-with-method-diagnostics branch August 19, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request goland GoLand plugin and JetBrains IDE integration mtlog-analyzer Static analysis tool for detecting mtlog usage issues neovim Neovim plugin and editor integration tooling Development tools, build systems, and analyzers vscode Visual Studio Code extension and integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add analyzer diagnostics for With() method variadic arguments

2 participants