github.com/daixiang0/gci@v0.13.4/pkg/specificity/specificity.go (about)

     1  package specificity
     2  
     3  type specificityClass int
     4  
     5  const (
     6  	MisMatchClass    = 0
     7  	DefaultClass     = 10
     8  	StandardClass    = 20
     9  	MatchClass       = 30
    10  	NameClass        = 40
    11  	LocalModuleClass = 50
    12  )
    13  
    14  // MatchSpecificity is used to determine which section matches an import best
    15  type MatchSpecificity interface {
    16  	IsMoreSpecific(than MatchSpecificity) bool
    17  	Equal(to MatchSpecificity) bool
    18  	class() specificityClass
    19  }
    20  
    21  func isMoreSpecific(this, than MatchSpecificity) bool {
    22  	return this.class() > than.class()
    23  }
    24  
    25  func equalSpecificity(base, to MatchSpecificity) bool {
    26  	// m.class() == to.class() would not work for Match
    27  	return !base.IsMoreSpecific(to) && !to.IsMoreSpecific(base)
    28  }