golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

feat: add interfacebloat

Open sashamelentyev opened this issue 2 years ago • 7 comments

A linter that checks the number of methods on an interface. https://github.com/sashamelentyev/interfacebloat

sashamelentyev avatar Jul 30 '22 11:07 sashamelentyev

In order for a pull request adding a linter to be reviewed, the linter and the PR must follow some requirements.

Pull Request Description

  • [x] It must have a link to the linter repository.
  • [x] It must provide a short description about the linter.

Linter

  • [x] It must not be a duplicate of another linter or a rule of a linter. (the team will help to verify that)
  • [x] It must have a valid license and the file must contain the required information by the license, ex: author, year, etc.
  • [x] The linter repository must have a CI and tests.
  • [x] It must use go/analysis.
  • [x] It must have a valid tag, ex: v1.0.0, v0.1.0.
  • [x] It must not contain init().
  • [x] It must not contain panic(), log.fatal(), os.exit(), or similar.
  • [x] It must not have false positives/negatives. (the team will help to verify that)
  • [x] It must have tests inside golangci-lint.

The Linter Tests Inside Golangci-lint

  • [x] They must have at least one std lib import.
  • [x] They must work with T=<name of the linter test file>.go make test_linters. (the team will help to verify that)

.golangci.reference.yml

  • [x] The linter must be added to the list of available linters (alphabetical case-insensitive order).
    • enable and disable options
  • [x] If the linter has a configuration, the exhaustive configuration of the linter must be added (alphabetical case-insensitive order)
    • The values must be different from the default ones.
    • The default values must be defined in a comment.
    • The option must have a short description.

Others Requirements

  • [x] The files (tests and linter) inside golangci-lint must have the same name as the linter.
  • [x] The .golangci.yml of golangci-lint itself must not be edited and the linter must not be added to this file.
  • [x] The linters must be sorted in the alphabetical order (case-insensitive) in the Manager.GetAllSupportedLinterConfigs(...) and .golangci.example.yml.
  • [x] The load mode (WithLoadMode(...)):
    • if the linter doesn't use types: goanalysis.LoadModeSyntax
    • goanalysis.LoadModeTypesInfo required WithLoadForGoAnalysis() in the Manager.GetAllSupportedLinterConfigs(...)
  • [x] The version in WithSince(...) must be the next minor version (v1.X.0) of golangci-lint.

Recommendations

  • [x] The linter should not use SSA. (currently, SSA does not support generics)
  • [ ] The linter repository should have a readme and linting.
  • [ ] The linter should be published as a binary. (useful to diagnose bug origins)

The golangci-lint team will edit this comment to check the boxes before and during the review.

This checklist does not imply that we will accept the linter.

ldez avatar Jul 30 '22 12:07 ldez

What do you call the length of an interface? :thinking:

Can you improve your readme?

  • add detailed explanation
  • add exemples

ldez avatar Jul 30 '22 12:07 ldez

I mean count of methods in interface

sashamelentyev avatar Jul 30 '22 12:07 sashamelentyev

What is the rule that you want to apply? is it limit the number of methods in an interface? Can you explain why (please provide links to documentation)?

ldez avatar Jul 30 '22 12:07 ldez

Yes, limit the number of methods in an interface interface bloat (fat interface) - it's anti-pattern

https://en.wikipedia.org/wiki/Interface_bloat https://stackoverflow.com/questions/1894021/what-is-interface-bloat

sashamelentyev avatar Jul 30 '22 13:07 sashamelentyev

So now, you have to improve your readme with the links and examples.

ldez avatar Jul 30 '22 13:07 ldez

@ldez I add short description and links

sashamelentyev avatar Jul 31 '22 10:07 sashamelentyev

https://github.com/sashamelentyev/interfacebloat/pull/1

ldez avatar Aug 20 '22 00:08 ldez

The test failure is related to https://github.com/golangci/golangci-lint/pull/3104/commits/6e756cb7b51d399a5a6cf8b3a49030db910d6305 and fixed by #3118

ldez avatar Aug 21 '22 00:08 ldez