Skip to content
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

improve diagnostics by adding the checker name to the diagnostic message #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ccoVeille
Copy link
Contributor

@ccoVeille ccoVeille commented Feb 12, 2025

  • feat: add checker name in the diagnostic message

This will help people to understand where the diagnostic is coming from.

But also, to easily understand what checker could be deactivated if they want to.

This is the implementation of what has been planned with #31

Fixes #43

This will help people to understand where the diagnostic is coming from.

But also, to easily understand what checker could be deactivated if they want to.

The change is fully compatible with the current tests.
It explains why the tests are not updated in this commit.
@ccoVeille
Copy link
Contributor Author

@mmorel-35 @alexandear @catenacyber please review

FYI: I introduced type aliases in order to virtually create a type, that can be easily understood.

Please let me know it you think it's overkill or OK

Copy link
Contributor

@mmorel-35 mmorel-35 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -54,6 +54,48 @@ func newPerfSprint() *perfSprint {
}
}

// checker is a type of check that can be performed by the analyzer.
// A checker can activate or deactivate specific rules.
type checker = string
Copy link
Owner

Choose a reason for hiding this comment

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

Why a type alias ?

Copy link
Contributor Author

@ccoVeille ccoVeille Feb 17, 2025

Choose a reason for hiding this comment

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

You mean versus:

  • a string
  • or versus type checker string (without the =)

I wanted a type, but I wanted something that didn't require type juggling when passing constants as flags

As I said in my first comment, I can remove everything and use string directly.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's use a string then.

(Or ok for type checker string and I do not think you need type juggling, just defining the constants with the right type and using them...)

checkerOptionSprintf1 checkerOption = "sprintf1"
// checkerOptionStrConcat optimizes string concatenation
// This option is only available when [CheckerStringFormat] is activated.
checkerOptionStrConcat checkerOption = "strconcat"
Copy link
Owner

Choose a reason for hiding this comment

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

This looks unnecessary to define a string to use it only once...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I iterated, I was using them at some point. In the diagnostic, but then I left them like this.

But I agree, now the logic of type and even constants for the suboption seems overkill.

Copy link
Contributor

@alexandear alexandear left a comment

Choose a reason for hiding this comment

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

LGTM.

Left a few minor comments.

checkerHexFormat checker = "hex-format"
)

// checkerOption is a type a specific [checker] that can be activated or deactivated for a [checker].
Copy link
Contributor

Choose a reason for hiding this comment

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

[] are redundant, because pkgsite ignores documentation for unexported types:

Suggested change
// checkerOption is a type a specific [checker] that can be activated or deactivated for a [checker].
// checkerOption is a type a specific checker that can be activated or deactivated for a checker.

type checkerOption = checker

const (
// checkerOptionIntConversion optimizes even if it requires an int or uint type cast
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
// checkerOptionIntConversion optimizes even if it requires an int or uint type cast
// checkerOptionIntConversion optimizes even if it requires an int or uint type cast.

// checkerOptionIntConversion optimizes even if it requires an int or uint type cast
// This option is only available when [CheckerIntegerFormat] is activated.
checkerOptionIntConversion checkerOption = "int-conversion"
// checkerOptionErrError optimizes into err.Error() even if it is only equivalent for non-nil errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checkerOptionErrError optimizes into err.Error() even if it is only equivalent for non-nil errors
// checkerOptionErrError optimizes into err.Error() even if it is only equivalent for non-nil errors.

// checkerOptionErrError optimizes into err.Error() even if it is only equivalent for non-nil errors
// This option is only available when [CheckerErrorFormat] is activated.
checkerOptionErrError checkerOption = "err-error"
// checkerOptionErrorf optimizes fmt.Errorf
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checkerOptionErrorf optimizes fmt.Errorf
// checkerOptionErrorf optimizes fmt.Errorf.

// checkerOptionErrorf optimizes fmt.Errorf
// This option is only available when [CheckerErrorFormat] is activated.
checkerOptionErrorf checkerOption = "errorf"
// checkerOptionSprintf1 optimizes fmt.Sprintf with only one argument
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checkerOptionSprintf1 optimizes fmt.Sprintf with only one argument
// checkerOptionSprintf1 optimizes fmt.Sprintf with only one argument.

// checkerOptionSprintf1 optimizes fmt.Sprintf with only one argument
// This option is only available when [CheckerStringFormat] is activated.
checkerOptionSprintf1 checkerOption = "sprintf1"
// checkerOptionStrConcat optimizes string concatenation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checkerOptionStrConcat optimizes string concatenation
// checkerOptionStrConcat optimizes string concatenation.

// This option is only available when [CheckerStringFormat] is activated.
checkerOptionStrConcat checkerOption = "strconcat"

// checkerFixImports fix needed imports from other fixes
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// checkerFixImports fix needed imports from other fixes
// checkerFixImports fix needed imports from other fixes.

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Feb 21, 2025

I'm AFAIK AFK for a few days. Strong cough, and and sneeze. Please expect some delay before I come back to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add checker name to analysis.Diagnostic
4 participants