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

Productionization #1

Merged
merged 9 commits into from
Oct 18, 2023
Merged

Productionization #1

merged 9 commits into from
Oct 18, 2023

Conversation

Antonboom
Copy link
Contributor

Hello!

I made this work as exception, because found your linter useful and hope to see it in the closest release of golangci-lint.

Please, in the next time be more respectful to your code and neighbour contributors. You contribute into the large open source project, but ignores the basic practises of software development.

TLDR:

  1. More simpler project structure.
  2. Fixed installation path (in your version binary will be have name main).
  3. Much more tests.
  4. Much simpler code with much better readability.
  5. Covered some forgotten cases.
  6. Benchmarking for proof of performance improvement.
  7. Makefile, CI, README, etc.

Feel free to review and discuss. Thanks

@catenacyber
Copy link
Owner

Thank you so much, this looks really good :-)
I will post some questions in the code

analyzer/analyzer.go Outdated Show resolved Hide resolved
// need ro run goimports to fix use of fmt/strconv afterwards
}

case isBasicType(valueType, types.Uint8, types.Uint16, types.Uint32, types.Uint) && oneOf(verb, "%v", "%d"):
Copy link
Owner

Choose a reason for hiding this comment

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

This is not just refactoring, but behavioral change.
Now the linter also suggests the change for uint32 and not just uint64, right ?

I know it is faster, but Golang team did not want this for code readability cf discussion in https://go-review.googlesource.com/c/go/+/477675

Could it be optional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the linter also suggests the change for uint32 and not just uint64, right ?

For any uints, yep

	strconv.FormatUint(uint64(ui), 10)    
	strconv.FormatUint(uint64(ui8), 10)  
	strconv.FormatUint(uint64(ui16), 10)  
	strconv.FormatUint(uint64(ui32), 10)
	strconv.FormatUint(ui64, 10)    

Could you please attach link to specific discussion?

Because I see only discussion about invalid conversions (like int to int64), but analyzer do it carefully.

Copy link
Owner

Choose a reason for hiding this comment

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

https://go-review.googlesource.com/c/go/+/477675/1..6/src/cmd/go/internal/modfetch/codehost/svn.go#36 comment from Bryan Mills

strconv.FormatInt is ok, although for non-performance-critical code (and particularly for values of types other than exactly int64) I tend to prefer fmt.Sprint instead — the base argument to strconv.FormatInt and the type-conversion (when needed) both somewhat distract from the intent of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

and the type-conversion (when needed) both somewhat distract from the intent of the code

I think if your linter pursues performance goals, then there is no places for such cosmetic and questionable exceptions.

Because, for example, fmt.Sprint(flag) is more simpler than strconv.FormatBool(flag), IMHO.

Could it be optional?

I propose to configure linter behaviour.
E.g.

perfsprint:
  enabled:
    - string    # Just using string
    - error     # Just using Error()
    - bool      # strconv.FormatBool
    - hex       # hex.EncodeToString
    - int       # strconv.Itoa or strconv.FormatInt
    - uint      # strconv.FormatUint
  int:
      # Enable int and int64 only mode
      no-type-conversions: true
  uint:
      # Enable uint64 only mode
      no-type-conversions: true

But anyway better if you do it in a separate PR 👌

Copy link
Owner

Choose a reason for hiding this comment

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

Do you have some documentation pointers on how to add this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Owner

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

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

Thanks for your work

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.

None yet

2 participants