solo-io / go-utils

golang utilities
Apache License 2.0
111 stars 19 forks source link

Helm indent finder #515

Closed jackstine closed 1 year ago

jackstine commented 1 year ago

Description

Includes FindHelmChartWhiteSpaces(), which takes a string, a yaml, and tries to parse it to find issues within the helm chart. Primary this is trying to find issues with white spacing, where each line should be at most off by 0 or -2, given exceptions that work according to the Helm spec.

The function will return a slice of windows (string slices) to represent the areas in the code that contain the issue that it found.

List of features

  1. looks for spacing issues with the next line is off by more than 2
  2. if next line is an array, it can be off by 4 or 2 spaces.
  3. if the line has special breaks (|-, >-, etc.) identified in YAML, these are now ignored areas in the YAML.
  4. if the YAML has empty lines, these are acceptable.
  5. if the YAMl has spaces in an empty line, there is an option to control whether to see these or not. Use the DetectWhiteSpacesInEmptyLines option when parsing.

Context

Users were having issues with formatting in the helm chart. Particularly when faced with this in the YAML. The 2nd line has 2 to many spaces, and so on.

resources:
    name: gloo-role-knative
    labels:
        app: gloo
        gloo: rbac

Use in Gloo

Link to the Gloo PR on usage.

solo-changelog-bot[bot] commented 1 year ago

Issues linked to changelog: https://github.com/solo-io/gloo/issues/8268