github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/linter/disablerule/commands.go (about)

     1  package disablerule
     2  
     3  import (
     4  	"github.com/yoheimuta/go-protoparser/v4/parser"
     5  )
     6  
     7  type commands []command
     8  
     9  func newCommands(
    10  	comments []*parser.Comment,
    11  ) commands {
    12  	var cmds []command
    13  	for _, comment := range comments {
    14  		if comment == nil {
    15  			continue
    16  		}
    17  		cmd, err := newCommand(comment.Raw)
    18  		if err == nil {
    19  			cmds = append(cmds, cmd)
    20  		}
    21  	}
    22  	return cmds
    23  }
    24  
    25  func (cs commands) enabled(
    26  	ruleID string,
    27  ) bool {
    28  	for _, cmd := range cs {
    29  		if cmd.enabled(ruleID) {
    30  			return true
    31  		}
    32  	}
    33  	return false
    34  }
    35  
    36  func (cs commands) disabled(
    37  	ruleID string,
    38  ) bool {
    39  	for _, cmd := range cs {
    40  		if cmd.disabled(ruleID) {
    41  			return true
    42  		}
    43  	}
    44  	return false
    45  }
    46  
    47  func (cs commands) disabledNext(
    48  	ruleID string,
    49  ) bool {
    50  	for _, cmd := range cs {
    51  		if cmd.disabledNext(ruleID) {
    52  			return true
    53  		}
    54  	}
    55  	return false
    56  }
    57  
    58  func (cs commands) disabledThis(
    59  	ruleID string,
    60  ) bool {
    61  	for _, cmd := range cs {
    62  		if cmd.disabledThis(ruleID) {
    63  			return true
    64  		}
    65  	}
    66  	return false
    67  }