Skip to content

feat: add LogValue() method stub generation to MTLOG005 quick fixes#30

Merged
willibrandon merged 2 commits intomainfrom
feature/enhanced-capturing-hints
Aug 9, 2025
Merged

feat: add LogValue() method stub generation to MTLOG005 quick fixes#30
willibrandon merged 2 commits intomainfrom
feature/enhanced-capturing-hints

Conversation

@willibrandon
Copy link
Owner

Description

Enhanced the MTLOG005 diagnostic to generate LogValue() method stubs for complex types, helping developers implement safe logging practices by automatically detecting and commenting out sensitive fields.

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

  • Generates idiomatic Go code with proper receiver names
  • Works consistently in both VS Code and GoLand IDEs
  • Includes test coverage for analyzer and GoLand plugin
  • Helps prevent accidental logging of sensitive data
  • Closes Add more quick fixes to VS Code and GoLand plugins #18 (completes all planned quick fixes)

Example generated code:

// LogValue provides a custom log representation for User
func (u User) LogValue() any {
    return map[string]any{
        "ID": u.ID,
        "Username": u.Username,
        // "Password": u.Password, // TODO: Review - potentially sensitive field
        // "APIKey": u.APIKey, // TODO: Review - potentially sensitive field
    }
}

Enhanced MTLOG005 diagnostic to provide dual quick fixes:
- Add @ prefix for complex type capturing
- Generate LogValue() method stub with sensitive field detection

The LogValue() stub generator automatically:
- Detects common sensitive fields (password, token, apikey, etc.)
- Comments out sensitive fields with TODO markers
- Generates proper receiver names and method signatures
- Ensures consistent formatting across VS Code and GoLand

Added test coverage for both analyzer and GoLand plugin.
@willibrandon willibrandon self-assigned this Aug 9, 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 labels Aug 9, 2025
@willibrandon willibrandon requested a review from Copilot August 9, 2025 02:39
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 enhances the MTLOG005 diagnostic to automatically generate LogValue() method stubs for complex types, helping developers implement safe logging practices by detecting and commenting out potentially sensitive fields.

  • Adds LogValue() method stub generation to MTLOG005 quick fixes
  • Implements sensitive field detection and automatic commenting
  • Includes comprehensive test coverage for both analyzer and GoLand plugin

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cmd/mtlog-analyzer/analyzer/quickfix.go Implements LogValue() method stub generation with sensitive field detection
cmd/mtlog-analyzer/analyzer/property_checks.go Integrates LogValue() stub generation into MTLOG005 diagnostic
cmd/mtlog-analyzer/analyzer/suggestedfix_test.go Adds test case for MTLOG005 suggested fixes
cmd/mtlog-analyzer/analyzer/testdata/src/suggestedfix/mtlog005/mtlog005.go Test data for LogValue() stub generation
cmd/mtlog-analyzer/analyzer/testdata/src/suggestedfix/mtlog005/mtlog005.go.golden Expected output after applying LogValue() stub generation
goland-plugin/src/test/kotlin/com/mtlog/analyzer/quickfix/LogValueStubQuickFixTest.kt Comprehensive test coverage for GoLand plugin quick fixes

- Rename 'inCurrentFile' to 'typeInCurrentFile' for better clarity
- Remove debug println statements from GoLand plugin tests
- Keep hardcoded newlines and TODO format unchanged (working as intended)
@willibrandon willibrandon merged commit 69f192c into main Aug 9, 2025
23 checks passed
@willibrandon willibrandon deleted the feature/enhanced-capturing-hints branch August 9, 2025 02:57
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 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 more quick fixes to VS Code and GoLand plugins

1 participant