Skip to content

Conversation

@chavacava
Copy link
Collaborator

This PR proposes a ~full rewriting of the rule struct-tag in an attempt to clean-up the implementation.

This PR introduces the following changes:

  1. Defines a common signature for tag-checker functions
  2. Normalizes failure messages
  3. Reduces the implementation complexity of some checks (protobuf, properties, ...)

@chavacava chavacava requested a review from denisvmedia April 5, 2025 10:17
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit worried by this filename

It relies on build tag
It's OK, but then as soon as Go 1.25 will be out, this file won't be used, and the structtag_test.go will, so it will fail.

Unless I'm misunderstanding the concept of how build tags works

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't get it. The PR doesn't modify the filename and the filename follows the convention of testdata files in revive: <rule_name>(_other_details)?.go

BTW: there is also testdata/struct_tag.go

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is made from multiple considerations

  • go.mod fixes the minimal version to 1.23
  • testdata/go1.24/struct_tag.go is there for the go 1.24 version
  • testdata/struct_tag.go is here for any other versions, so right now for go 1.23 only

But when I commented yesterday I thought the file was something like struct_tag_go124_test.go so using build tag while it doesn't.

So my suggestion was unclear, because I was wrong.

But while my suggestion was wrong, the considerations are still there.

When Go 1.25 will go out, the tests will call testdata/struct_tag.go, right?

And omitzero will still be supported.

You may argue the minimal version would be bumped when Go 1.25 will be out, but I think current code could cause issues.

So here is my suggestion

  • rename testdata/struct_tag.go to testdata/go1.23/struct_tag.go
  • rename testdata/go1.24/struct_tag.go to testdata/struct_tag.go

This way there will be no problem with Go 1.25

I hope it would be clearer, but maybe I'm overthinking

Copy link
Collaborator

@alexandear alexandear Apr 9, 2025

Choose a reason for hiding this comment

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

When Go 1.25 will go out, the tests will call testdata/struct_tag.go, right?

When Go 1.25 will go out, the tests will call all tests from test/struct_tag_test.go:

  • testdata/struct_tag.go
  • testdata/struct_tag_user_options.go
  • testdata/go1.24/struct_tag.go

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is made from multiple considerations

  • go.mod fixes the minimal version to 1.23
  • testdata/go1.24/struct_tag.go is there for the go 1.24 version
  • testdata/struct_tag.go is here for any other versions, so right now for go 1.23 only

But when I commented yesterday I thought the file was something like struct_tag_go124_test.go so using build tag while it doesn't.

So my suggestion was unclear, because I was wrong.

But while my suggestion was wrong, the considerations are still there.

When Go 1.25 will go out, the tests will call testdata/struct_tag.go, right?

And omitzero will still be supported.

You may argue the minimal version would be bumped when Go 1.25 will be out, but I think current code could cause issues.

So here is my suggestion

  • rename testdata/struct_tag.go to testdata/go1.23/struct_tag.go
  • rename testdata/go1.24/struct_tag.go to testdata/struct_tag.go

This way there will be no problem with Go 1.25

I hope it would be clearer, but maybe I'm overthinking

@chavacava chavacava changed the title Refactor/struct tag struct-tag: change reported messages and refactor implementation Apr 9, 2025
@chavacava chavacava merged commit f0eea95 into master Apr 10, 2025
8 checks passed
mfederowicz pushed a commit to mfederowicz/revive that referenced this pull request Apr 18, 2025
@chavacava chavacava deleted the refactor/struct-tag branch April 27, 2025 11:28
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.

3 participants