• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 12857640190

19 Jan 2025 10:16PM CUT coverage: 57.418% (-0.4%) from 57.843%
12857640190

push

github

web-flow
Check for name conflicts in re-exports (#72)

18 of 33 new or added lines in 3 files covered. (54.55%)

4 existing lines in 1 file now uncovered.

836 of 1456 relevant lines covered (57.42%)

8.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/document/processor.go
1
package document
2

3
import (
4
        "fmt"
5
        "log"
6
        "os"
7
        "strings"
8
        "text/template"
9
)
10

11
type Config struct {
12
        InputFile       string
13
        OutputDir       string
14
        TemplateDirs    []string
15
        UseExports      bool
16
        ShortLinks      bool
17
        CaseInsensitive bool
18
        Strict          bool
19
        DryRun          bool
20
}
21

22
type Processor struct {
23
        Config             *Config
24
        Template           *template.Template
25
        Formatter          Formatter
26
        Docs               *Docs
27
        ExportDocs         *Docs
28
        allPaths           map[string]bool
29
        linkTargets        map[string]elemPath
30
        linkExports        map[string]string
31
        linkExportsReverse map[string]*exportError
32
        writer             func(file, text string) error
33
}
34

35
func NewProcessor(docs *Docs, f Formatter, t *template.Template, config *Config) *Processor {
8✔
36
        return NewProcessorWithWriter(docs, f, t, config, func(file, text string) error {
8✔
37
                return os.WriteFile(file, []byte(text), 0666)
×
38
        })
×
39
}
40

41
func NewProcessorWithWriter(docs *Docs, f Formatter, t *template.Template, config *Config, writer func(file, text string) error) *Processor {
12✔
42
        return &Processor{
12✔
43
                Config:    config,
12✔
44
                Template:  t,
12✔
45
                Formatter: f,
12✔
46
                Docs:      docs,
12✔
47
                writer:    writer,
12✔
48
        }
12✔
49
}
12✔
50

51
// PrepareDocs processes the API docs for subsequent rendering.
52
func (proc *Processor) PrepareDocs() error {
4✔
53
        // Collect the paths of all (sub)-elements in the original structure.
4✔
54
        proc.collectElementPaths()
4✔
55
        // Re-structure according to exports.
4✔
56
        err := proc.filterPackages()
4✔
57
        if err != nil {
4✔
58
                return err
×
59
        }
×
60
        // Collect all link target paths.
61
        proc.collectPaths()
4✔
62
        if !proc.Config.UseExports {
7✔
63
                for k := range proc.linkTargets {
16✔
64
                        proc.linkExports[k] = k
13✔
65
                }
13✔
66
        }
67
        // Replaces cross-refs by placeholders.
68
        if err := proc.processLinksPackage(proc.Docs.Decl, []string{}); err != nil {
4✔
69
                return err
×
70
        }
×
71
        return nil
4✔
72
}
73

74
func (proc *Processor) WriteFile(file, text string) error {
15✔
75
        return proc.writer(file, text)
15✔
76
}
15✔
77

UNCOV
78
func (proc *Processor) warnOrError(pattern string, args ...any) error {
×
UNCOV
79
        if proc.Config.Strict {
×
80
                return fmt.Errorf(pattern, args...)
×
81
        }
×
UNCOV
82
        log.Printf("WARNING: "+pattern+"\n", args...)
×
UNCOV
83
        return nil
×
84
}
85

86
func (proc *Processor) addLinkExport(oldPath, newPath []string) {
28✔
87
        pNew := strings.Join(newPath, ".")
28✔
88
        pOld := strings.Join(oldPath, ".")
28✔
89
        if present, ok := proc.linkExportsReverse[pNew]; ok {
28✔
NEW
90
                present.OldPaths = append(present.OldPaths, pOld)
×
91
        } else {
28✔
92
                proc.linkExportsReverse[pNew] = &exportError{
28✔
93
                        NewPath:  pNew,
28✔
94
                        OldPaths: []string{pOld},
28✔
95
                }
28✔
96
        }
28✔
97
        proc.linkExports[pOld] = pNew
28✔
98
}
99

100
func (proc *Processor) addLinkTarget(elPath, filePath []string, kind string, isSection bool) {
34✔
101
        proc.linkTargets[strings.Join(elPath, ".")] = elemPath{Elements: filePath, Kind: kind, IsSection: isSection}
34✔
102
}
34✔
103

104
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
46✔
105
        if isSection {
54✔
106
                return
8✔
107
        }
8✔
108
        proc.allPaths[strings.Join(elPath, ".")] = true
38✔
109
        _, _ = filePath, kind
38✔
110
}
111

112
func (proc *Processor) mkDirs(path string) error {
8✔
113
        if proc.Config.DryRun {
8✔
114
                return nil
×
115
        }
×
116
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
8✔
117
                return err
×
118
        }
×
119
        return nil
8✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc