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

mlange-42 / modo / 12858490261

20 Jan 2025 12:18AM CUT coverage: 56.633% (-0.8%) from 57.418%
12858490261

Pull #73

github

web-flow
Merge af153f20f into ef546a39d
Pull Request #73: Fix cross-refs to package and module aliases

8 of 34 new or added lines in 7 files covered. (23.53%)

2 existing lines in 2 files now uncovered.

841 of 1485 relevant lines covered (56.63%)

8.1 hits per line

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

75.36
/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

4✔
56
        // Re-structure according to exports.
4✔
57
        err := proc.filterPackages()
4✔
58
        if err != nil {
4✔
59
                return err
×
60
        }
×
61
        // Collect all link target paths.
62
        proc.collectPaths()
4✔
63
        if !proc.Config.UseExports {
7✔
64
                for k := range proc.linkTargets {
16✔
65
                        proc.linkExports[k] = k
13✔
66
                }
13✔
67
        }
68
        // Replaces cross-refs by placeholders.
69
        if err := proc.processLinksPackage(proc.Docs.Decl, []string{}); err != nil {
4✔
70
                return err
×
71
        }
×
72
        return nil
4✔
73
}
74

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

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

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

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

105
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
46✔
106
        if isSection && kind != "package" && kind != "module" { // actually, we are catching aliases here
53✔
107
                return
7✔
108
        }
7✔
109
        proc.allPaths[strings.Join(elPath, ".")] = true
39✔
110
        _, _ = filePath, kind
39✔
111
}
112

113
func (proc *Processor) mkDirs(path string) error {
8✔
114
        if proc.Config.DryRun {
8✔
115
                return nil
×
116
        }
×
117
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
8✔
118
                return err
×
119
        }
×
120
        return nil
8✔
121
}
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