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

evilmartians / lefthook / 17761174587

16 Sep 2025 09:24AM UTC coverage: 73.952% (-1.0%) from 74.989%
17761174587

push

github

web-flow
refactor: reduce the amount of code in a single file (#1118)

* Split controller.go and run_jobs.go 
* Add utils subpackage for common functions
* Add Name to a config.Hook and set it on config load

385 of 505 new or added lines in 14 files covered. (76.24%)

33 existing lines in 4 files now uncovered.

3370 of 4557 relevant lines covered (73.95%)

3.28 hits per line

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

82.61
/internal/run/controller/scope.go
1
package controller
2

3
import (
4
        "maps"
5
        "slices"
6

7
        "github.com/evilmartians/lefthook/internal/config"
8
        "github.com/evilmartians/lefthook/internal/run/controller/utils"
9
)
10

11
type scope struct {
12
        follow bool
13

14
        glob         []string
15
        tags         []string
16
        excludeTags  []string // Consider removing this setting
17
        names        []string
18
        excludeFiles interface{}
19
        env          map[string]string
20
        root         string
21
        hookName     string
22
        filesCmd     string
23
        opts         Options
24
}
25

26
func newScope(hook *config.Hook, opts Options) *scope {
6✔
27
        var excludeFiles []interface{}
6✔
28
        if len(opts.ExcludeFiles) > 0 {
9✔
29
                excludeFiles = make([]interface{}, len(opts.ExcludeFiles))
3✔
30
                for i, e := range opts.ExcludeFiles {
6✔
31
                        excludeFiles[i] = e
3✔
32
                }
3✔
33
        }
34

35
        return &scope{
6✔
36
                hookName:     hook.Name,
6✔
37
                follow:       hook.Follow,
6✔
38
                filesCmd:     hook.Files,
6✔
39
                excludeTags:  hook.ExcludeTags,
6✔
40
                excludeFiles: excludeFiles,
6✔
41
                env:          make(map[string]string),
6✔
42
                opts:         opts,
6✔
43
        }
6✔
44
}
45

46
func (s *scope) extend(job *config.Job) *scope {
3✔
47
        newScope := *s
3✔
48
        newScope.glob = slices.Concat(newScope.glob, job.Glob)
3✔
49
        newScope.tags = slices.Concat(newScope.tags, job.Tags)
3✔
50
        newScope.root = utils.FirstNonBlank(job.Root, s.root)
3✔
51

3✔
52
        // Extend `exclude` list
3✔
53
        switch list := job.Exclude.(type) {
3✔
54
        case []interface{}:
3✔
55
                switch inherited := newScope.excludeFiles.(type) {
3✔
56
                case []interface{}:
3✔
57
                        // List of globs get appended
3✔
58
                        inherited = append(inherited, list...)
3✔
59
                        newScope.excludeFiles = inherited
3✔
NEW
60
                default:
×
NEW
61
                        // Regex value will be overwritten with a list of globs
×
NEW
62
                        newScope.excludeFiles = job.Exclude
×
63
                }
NEW
64
        case string:
×
NEW
65
                // Regex value always overwrites excludes
×
NEW
66
                newScope.excludeFiles = job.Exclude
×
67
        default:
3✔
68
                // Inherit
69
        }
70

71
        // Overwrite --jobs option for nested groups: if group name given, run all its jobs
72
        if len(s.opts.RunOnlyJobs) != 0 && job.Group != nil && slices.Contains(s.opts.RunOnlyJobs, job.Name) {
6✔
73
                newScope.opts.RunOnlyJobs = []string{}
3✔
74
        }
3✔
75

76
        // Overwrite `files` command if present
77
        if len(job.Files) > 0 {
3✔
NEW
78
                s.filesCmd = job.Files
×
NEW
79
        }
×
80

81
        maps.Copy(newScope.env, job.Env)
3✔
82

3✔
83
        return &newScope
3✔
84
}
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

© 2026 Coveralls, Inc