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

chore: refactor Diagnostic declaration #31

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

mmorel-35
Copy link
Contributor

@mmorel-35 mmorel-35 commented Nov 18, 2024

Description

This provide a function to mutualise Diagnostic declaration

@mmorel-35 mmorel-35 changed the title chore: refactor Diagnostic instantiation chore: refactor Diagnostic declaration Nov 18, 2024
@catenacyber
Copy link
Owner

Why do you want this change ? It is only cosmetic style, right ?

@mmorel-35
Copy link
Contributor Author

mmorel-35 commented Nov 19, 2024

It might seems yet but this will help bringing other changes like display the name of the rule that is causing an error
See https://github.com/Antonboom/testifylint/blob/master/internal/checkers/helpers_diagnostic.go#L89-L105 to get an idea of what I mean.

For the moment I'm not able to identify clearly a "checker" for each diagnostic.

This will help users identify which rule is causing errors.

@mmorel-35 mmorel-35 force-pushed the diagnostics branch 2 times, most recently from 103df5d to 244e106 Compare November 20, 2024 07:34
@mmorel-35 mmorel-35 force-pushed the diagnostics branch 2 times, most recently from d2d83bb to fbbb189 Compare November 20, 2024 08:15
Message: fn + " can be replaced with faster strconv.FormatBool",
SuggestedFixes: []analysis.SuggestedFix{
d = newAnalysisDiagnostic(
"", // TODO: precise checker

Choose a reason for hiding this comment

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

Thanks for working on this

You help me to think further about my code suggestion here

#32 (comment)

Yes, these linters not only needs a name, reported as a prefix in the error message, but also they need an option to deactivate each option

Copy link
Owner

Choose a reason for hiding this comment

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

I guess a way to link the checker name with a CLI option to enable/disable it would be nice indeed.

analyzer/diagnostics.go Outdated Show resolved Hide resolved
analyzer/diagnostics.go Outdated Show resolved Hide resolved
analyzer/diagnostics.go Outdated Show resolved Hide resolved
Comment on lines 20 to 25
intConversionChecker string = "int-conversion"
errErrorChecker string = "err-error"
errorfChecker string = "errorf"
sprintf1Checker string = "sprintf1"
fiximportsChecker string = "fiximports"
strconcatChecker string = "strconcat"

Choose a reason for hiding this comment

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

Please give them a common prefix, not suffix

For code completion plus clarity

Choose a reason for hiding this comment

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

Thanks @mmorel-35 for doing the changes.

@alexandear do you know any linters about this?

Maybe it could be part of revive. I find this pattern so frequently in code.

Of course, this linter would be opinionated and might cause problem for exported constants

What do you think ?

We could move the discussion to revive repository maybe, but I would like to get feedbacks from you guys, before going further.

analyzer/analyzer.go Show resolved Hide resolved
@catenacyber
Copy link
Owner

It might seems yet but this will help bringing other changes like display the name of the rule that is causing an error See https://github.com/Antonboom/testifylint/blob/master/internal/checkers/helpers_diagnostic.go#L89-L105 to get an idea of what I mean.

For the moment I'm not able to identify clearly a "checker" for each diagnostic.

This will help users identify which rule is causing errors.

Ok, so can you add this change in a new commit ?

analyzer/analyzer.go Outdated Show resolved Hide resolved
@ccoVeille
Copy link

Based on the changes made on this PR, I'll wait for this one to be merged before working on

@mmorel-35 mmorel-35 force-pushed the diagnostics branch 2 times, most recently from 07192e5 to ac50141 Compare November 20, 2024 22:28
@mmorel-35
Copy link
Contributor Author

Let's narrow this PR with new method only used with empty checker name.

You first need to list and distinguish checkers options to proceed with the next changes.

@catenacyber catenacyber merged commit a34cbe3 into catenacyber:main Nov 21, 2024
1 check passed
@catenacyber
Copy link
Owner

Thanks, waiting for the next step then

@mmorel-35 mmorel-35 deleted the diagnostics branch November 21, 2024 17:27
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.

4 participants