Refactor code style for improved readability and consistency.

This commit is contained in:
Overlord committed 2026-10-14 00:28:32 +02:00
1 parent 463c013056
commit 94bfc87e9d
4 files changed
+118 -156

No files matched your search

+15 -19
View File
@@ -24,18 +24,18 @@ func indexPositions(doc []byte) positions {
e := p.Expression()
switch e.Kind {
case unstable.Table, unstable.ArrayTable:
keys, first := keyParts(e.Key())
path := strings.Join(keys, ".")
if e.Kind == unstable.ArrayTable {
n := arrays[path]
arrays[path]++
path = fmt.Sprintf("%s[%d]", path, n)
}
prefix = path
ps.add(&p, path, first)
case unstable.KeyValue:
ps.keyValue(&p, prefix, e)
case unstable.Table, unstable.ArrayTable:
keys, first := keyParts(e.Key())
path := strings.Join(keys, ".")
if e.Kind == unstable.ArrayTable {
n := arrays[path]
arrays[path]++
path = fmt.Sprintf("%s[%d]", path, n)
}
prefix = path
ps.add(&p, path, first)
case unstable.KeyValue:
ps.keyValue(&p, prefix, e)
}
}
@@ -44,7 +44,7 @@ func indexPositions(doc []byte) positions {
func (ps positions) keyValue(p *unstable.Parser, prefix string, kv *unstable.Node) {
keys, first := keyParts(kv.Key())
path := strings.Join(keys, ".")
path := strings.Join(keys, ".")
if prefix != "" {
path = prefix + "." + path
@@ -84,9 +84,7 @@ func (ps positions) add(p *unstable.Parser, path string, n *unstable.Node) {
// that a missing key points at the table it belongs in.
func (ps positions) find(path string) (unstable.Position, bool) {
for path != "" {
if pos, ok := ps[path]; ok {
return pos, true
}
if pos, ok := ps[path]; ok { return pos, true }
i := strings.LastIndexAny(path, ".[")
if i < 0 {
@@ -123,9 +121,7 @@ func keyParts(it unstable.Iterator) ([]string, *unstable.Node) {
for it.Next() {
n := it.Node()
if first == nil {
first = n
}
if first == nil { first = n }
keys = append(keys, string(n.Data))
}