MCPcopy Create free account
hub / github.com/vale-cli/vale / commonIndent

Function commonIndent

internal/lint/code/query.go:93–108  ·  view source on GitHub ↗

commonIndent returns the length, in bytes, of the longest run of leading `cutset` characters shared by every non-blank line. Blank lines (those that are empty after trimming) are ignored so they don't force the indent to zero.

(lines []string, cutset string)

Source from the content-addressed store, hash-verified

91// `cutset` characters shared by every non-blank line. Blank lines (those that
92// are empty after trimming) are ignored so they don't force the indent to zero.
93func commonIndent(lines []string, cutset string) int {
94 common := -1
95 for _, line := range lines {
96 if strings.TrimLeft(line, cutset) == "" {
97 continue
98 }
99 n := len(line) - len(strings.TrimLeft(line, cutset))
100 if common == -1 || n < common {
101 common = n
102 }
103 }
104 if common < 0 {
105 return 0
106 }
107 return common
108}
109
110// stripIndent removes up to `n` leading `cutset` characters from `line` (a line
111// with fewer than `n` leading cutset characters -- e.g. a blank line -- loses

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…