diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 14:08:36 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 14:08:36 +0200 |
| commit | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (patch) | |
| tree | 4fa14f455c72f9b206a680dcc1b0f4c1f3708158 /internal/config/dir.go | |
| parent | 07c24054cab965800983ef40f53a05c2db131ede (diff) | |
| download | krino-1d3f2d1e4c59867024470d3444e12698b7ebb22e.tar.gz krino-1d3f2d1e4c59867024470d3444e12698b7ebb22e.zip | |
0.0.4: max-size, exclude forms, --min-agev0.0.4
Diffstat (limited to 'internal/config/dir.go')
| -rw-r--r-- | internal/config/dir.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/internal/config/dir.go b/internal/config/dir.go index 74c538a..461d912 100644 --- a/internal/config/dir.go +++ b/internal/config/dir.go @@ -19,9 +19,41 @@ type Dir struct { PathText string // as written in the file Settings Settings Ignore []string // gitignore patterns, in order + Excludes []*Exclude Rules []*Rule } +// Exclude is one (exclude COND...) form: a file for which every condition +// holds is set aside before any rule runs. Forms may repeat, so a file is +// excluded when any one form matches it. +type Exclude struct { + Pos sexp.Pos + Text string // the form as written, whitespace collapsed, for check and explain + When []*sexp.Node // the conditions, all of which must hold +} + +// parseExclude reads an (exclude COND...) form from src; nil when it has no +// usable condition. +func parseExclude(n *sexp.Node, src []byte, d *diags) *Exclude { + conds := n.Args() + if len(conds) == 0 { + d.at(n, "(exclude) needs a condition, like (exclude (type iso))") + return nil + } + bad := false + for _, c := range conds { + if c.Kind != sexp.List { + d.at(c, "exclude: a condition is a form like (type pdf), not %s", c) + bad = true + } + } + if bad { + return nil + } + text := strings.Join(strings.Fields(string(src[n.Pos.Offset:n.End.Offset])), " ") + return &Exclude{Pos: n.Pos, Text: text, When: conds} +} + // Rule is a named condition with the actions it performs. type Rule struct { Name string @@ -97,6 +129,10 @@ func ParseDir(name, file string, src []byte) (*Dir, []*Diag) { } dir.Ignore = append(dir.Ignore, a.Text) } + case head == "exclude": + if x := parseExclude(n, src, d); x != nil { + dir.Excludes = append(dir.Excludes, x) + } case head == "rule": r := parseRule(n, d) if r == nil { @@ -111,7 +147,7 @@ func ParseDir(name, file string, src []byte) (*Dir, []*Diag) { case isSetting(head): dir.Settings.parse(n, d, seen) default: - d.at(n, "unknown form (%s ...); a directory file has path, ignore, rule and settings like (recursive yes)", head) + d.at(n, "unknown form (%s ...); a directory file has path, ignore, exclude, rule and settings like (recursive yes)", head) } } if pathNode == nil { |
