google / yamlfmt

An extensible command line tool or library to format yaml files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preserve multiline for line ending with \

ezh opened this issue · comments

Hey. I have the next yaml.

What is the best way to preserve multiline for the regex value?

I cannot use > scan_folded_as_literal because there will be spaces between elements.

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMNodeScrape
metadata:
  name: kubelet
spec:
  metricRelabelConfigs:
    - action: labeldrop
      regex: (uid)
    - action: labeldrop
      regex: (id|name)
    - action: keep
      regex: "go_goroutines|\
        kubelet_cgroup_manager_duration_seconds_bucket|\
        kubelet_cgroup_manager_duration_seconds_count|\
        kubelet_node_config_error|\
        kubelet_node_name|\
        node_quantile:kubelet_pleg_relist_duration_seconds:histogram_quantile|\
        kubelet_pleg_relist_duration_seconds_bucket|\
        kubelet_pleg_relist_duration_seconds_count|\
        kubelet_pleg_relist_interval_seconds_bucket|\
        kubelet_certificate_manager_client_ttl_seconds|\
        kubelet_certificate_manager_client_expiration_renew_errors|\
        kubelet_certificate_manager_server_ttl_seconds|\
        kubelet_pod_start_duration_seconds_bucket|\
        kubelet_pod_start_duration_seconds_count|\
        kubelet_pod_worker_duration_seconds_bucket|\
        kubelet_pod_worker_duration_seconds_count|\
        kubelet_server_expiration_renew_errors|\
        kubelet_running_containers|\
        kubelet_running_container_count|\
        kubelet_running_pods|\
        kubelet_running_pod_count|\
        kubelet_runtime_operations_errors_total|\
        kubelet_runtime_operations_total|\
        kubelet_volume_stats_available_bytes|\
        kubelet_volume_stats_capacity_bytes|\
        kubelet_volume_stats_inodes|\
        kubelet_volume_stats_inodes_used|\
        process_cpu_seconds_total|\
        rest_client_request_duration_seconds_bucket|\
        rest_client_requests_total|\
        storage_operation_duration_seconds_count|\
        storage_operation_errors_total|\
        kubernetes_build_info|\
        volume_manager_total_volumes|\
        process_resident_memory_bytes"

Hi @ezh thanks for opening an issue.

Do you have retain_line_breaks set with this example? See the docs to see how to set that.

$ cat $HOME/.config/yamlfmt/.yamlfmt
formatter:
  type: basic
  retain_line_breaks: true
  scan_folded_as_literal: true

@braydonk You can reproduce it quickly. Copy'n'paste the above YAML to test.yml and run
yamlfmt -conf ~/.config/yamlfmt/.yamlfmt test.yml with retain_line_breaks.

yamlfmt -version
0.10.0