cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.15.3

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/discovery/discovery.go

55lines · modecode

1package discovery
2
3import (
4 "os"
5
6 "github.com/cloudflare/pint/internal/parser"
7
8 "github.com/rs/zerolog/log"
9)
10
11type RuleFinder interface {
12 Find() ([]Entry, error)
13}
14
15type Entry struct {
16 Path string
17 PathError error
18 ModifiedLines []int
19 Rule parser.Rule
20}
21
22func readFile(path string) (entries []Entry, err error) {
23 p := parser.NewParser()
24
25 f, err := os.Open(path)
26 if err != nil {
27 return nil, err
28 }
29
30 content, err := parser.ReadContent(f)
31 f.Close()
32 if err != nil {
33 return nil, err
34 }
35
36 rules, err := p.Parse(content)
37 if err != nil {
38 log.Error().Str("path", path).Err(err).Msg("Failed to parse file content")
39 entries = append(entries, Entry{
40 Path: path,
41 PathError: err,
42 })
43 return entries, nil
44 }
45
46 for _, rule := range rules {
47 entries = append(entries, Entry{
48 Path: path,
49 Rule: rule,
50 })
51 }
52
53 log.Info().Str("path", path).Int("rules", len(entries)).Msg("File parsed")
54 return entries, nil
55}