github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/tflint/module_variable.go (about)

     1  package tflint
     2  
     3  import hcl "github.com/hashicorp/hcl/v2"
     4  
     5  type moduleVariable struct {
     6  	Root      bool
     7  	Parents   []*moduleVariable
     8  	Callers   []*moduleVariable
     9  	DeclRange hcl.Range
    10  }
    11  
    12  func (m *moduleVariable) roots() []*moduleVariable {
    13  	if m.Root {
    14  		return []*moduleVariable{m}
    15  	}
    16  
    17  	ret := []*moduleVariable{}
    18  	for _, parent := range m.Parents {
    19  		for _, parentRoot := range parent.roots() {
    20  			parentRoot.Callers = append(parentRoot.Callers, m)
    21  			ret = append(ret, parentRoot)
    22  		}
    23  	}
    24  	return ret
    25  }
    26  
    27  func (m *moduleVariable) callers() []hcl.Range {
    28  	ret := make([]hcl.Range, len(m.Callers)+1)
    29  	ret[0] = m.DeclRange
    30  
    31  	for idx, caller := range m.Callers {
    32  		ret[idx+1] = caller.DeclRange
    33  	}
    34  	return ret
    35  }