MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / check

Method check

tools/mage/headers.go:133–160  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

131}
132
133func (h Headers) check(path string) error {
134 rule := headerConfig.get(path)
135 if rule == nil {
136 return nil
137 }
138 f, err := os.Open(path)
139 if err != nil {
140 return err
141 }
142 defer f.Close()
143 s := bufio.NewScanner(f)
144 for i, expected := range rule.headerLines {
145 if !s.Scan() {
146 return &checkErr{Path: path, Reason: "has less lines than expected header"}
147 }
148 line := s.Bytes()
149 if i == 0 && bytes.Contains(line, []byte("generated")) {
150 return nil // Skip generated files.
151 }
152 if !bytes.Equal(line, bytes.TrimSpace([]byte(rule.Prefix))) && !expected.Match(bytes.TrimPrefix(line, []byte(rule.Prefix))) {
153 return &checkErr{Path: path, Reason: fmt.Sprintf("did not match expected header line: %v", expected)}
154 }
155 }
156 if s.Scan() && len(s.Bytes()) != 0 {
157 return &checkErr{Path: path, Reason: "does not have empty line after header"}
158 }
159 return nil
160}
161
162type errorSlice []error
163

Callers 15

CheckMethod · 0.95
checkFromStateFunction · 0.80
feature-checks.jsFile · 0.80
RequireFunction · 0.80
DeviceGeneralSettingsFunction · 0.80
profile.spec.jsFile · 0.80
import.spec.jsFile · 0.80
checkOTAAMethod · 0.80
checkABPMethod · 0.80

Calls 7

TrimPrefixMethod · 0.80
CloseMethod · 0.65
BytesMethod · 0.65
ContainsMethod · 0.65
EqualMethod · 0.65
MatchMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected