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

fix duplicated findings for string-format when there is more than one… #1085

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

chavacava
Copy link
Collaborator

Closes #1063 + minor code refactoring

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.

Please run gofmt -w rule/string-format.go to fix comments that I left.

@@ -216,7 +216,7 @@ func (w lintStringFormatRule) Visit(node ast.Node) ast.Visitor {
for _, rule := range w.rules {
for _, scope := range rule.scopes {
if scope.funcName == callName {
rule.Apply(call)
rule.apply(call,scope)
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
rule.apply(call,scope)
rule.apply(call, scope)

}

Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant TAB, can be removed:

Suggested change

Copy link
Contributor

@alexandear alexandear Oct 29, 2024

Choose a reason for hiding this comment

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

I'm suggesting adding the test to verify that the issue is really fixed.

test/string-format_test.go:

func TestStringFormatDuplicatedStrings(t *testing.T) {
	testRule(t, "string-format-issue-1063", &rule.StringFormatRule{}, &lint.RuleConfig{
		Arguments: lint.Arguments{[]any{
			"fmt.Errorf[0],errors.New[0]",
			"/^([^A-Z]|$)/",
			"must not start with a capital letter",
		}},
	})
}

testdata/string-format-issue-1063.go:

package fixtures

import (
	"errors"
)

func ReturnError() error {
	return errors.New("This is an error.") // MATCH /must not start with a capital letter/
}

@chavacava chavacava merged commit 7c068a7 into master Nov 4, 2024
4 checks passed
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.

Duplicated findings for string-format when there is more than one scope provided for single argument
2 participants