Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ To use `helmfmt` as a pre-commit hook, add the following to your `.pre-commit-co
```yaml
repos:
- repo: https://github.com/digitalstudium/helmfmt
rev: v0.4.3
rev: v0.4.4
hooks:
- id: helmfmt
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.3
0.4.4
58 changes: 29 additions & 29 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
commentEndRe = regexp.MustCompile(`\*\/(?:}}|\s-}})`)

// Паттерны для определения типов токенов
varRe = regexp.MustCompile(`^\s*\$\w+\s*:=`)
varRe = regexp.MustCompile(`^\s*\$\w+\s*:?=`)
controlRe = regexp.MustCompile(`^\s*(if|range|with|define|block)\b`)
elseRe = regexp.MustCompile(`^\s*else\b`)
endRe = regexp.MustCompile(`^\s*end\b`)
Expand Down Expand Up @@ -63,34 +63,34 @@ func validateTemplateSyntax(src string) error {

// Главная функция выравнивания
func formatIndentation(src string, config *Config, filePath string) string {
lines := strings.Split(src, "\n")
depth := 0

for i := 0; i < len(lines); i++ {
trimmed := strings.TrimSpace(lines[i])
if trimmed == "" {
continue
}

// standalone comment block => indent with current depth, don't attach to next token
if commentOpenRe.MatchString(lines[i]) {
cEnd, remainder, ok := skipLeadingBlockComment(lines, i)
if ok && strings.TrimSpace(remainder) == "" {
indent := strings.Repeat(" ", depth*config.IndentSize)
for j := i; j <= cEnd && j < len(lines); j++ {
lines[j] = indent + strings.TrimLeft(lines[j], " \t")
}
i = cEnd
continue
}
}

commentStart := i

keyword, _, endLine, kind, found := getTokenAtLineStartSkippingLeadingComments(lines, i, config)
if !found {
continue
}
lines := strings.Split(src, "\n")
depth := 0

for i := 0; i < len(lines); i++ {
trimmed := strings.TrimSpace(lines[i])
if trimmed == "" {
continue
}

// standalone comment block => indent with current depth, don't attach to next token
if commentOpenRe.MatchString(lines[i]) {
cEnd, remainder, ok := skipLeadingBlockComment(lines, i)
if ok && strings.TrimSpace(remainder) == "" {
indent := strings.Repeat(" ", depth*config.IndentSize)
for j := i; j <= cEnd && j < len(lines); j++ {
lines[j] = indent + strings.TrimLeft(lines[j], " \t")
}
i = cEnd
continue
}
}

commentStart := i

keyword, _, endLine, kind, found := getTokenAtLineStartSkippingLeadingComments(lines, i, config)
if !found {
continue
}

// Check if we should skip indenting this simple function
if kind == tokSimple {
Expand Down
8 changes: 8 additions & 0 deletions templates_test/templates/var_assignment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $value := "" }}
{{- if .Values.option1 }}
{{- $value = .Values.option1.value }}
{{- else if .Values.option2 }}
{{- $value = "some-value" }}
{{- else }}
{{- fail "Either option1.value must be set or option2 must be true" }}
{{- end }}
8 changes: 8 additions & 0 deletions templates_test/templates_expected/var_assignment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $value := "" }}
{{- if .Values.option1 }}
{{- $value = .Values.option1.value }}
{{- else if .Values.option2 }}
{{- $value = "some-value" }}
{{- else }}
{{- fail "Either option1.value must be set or option2 must be true" }}
{{- end }}
3 changes: 3 additions & 0 deletions templates_test/var_assignment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Variable assignment indentation test"
input_file: "templates/var_assignment.yaml"
expected_file: "templates_expected/var_assignment.yaml"
Loading