please preserve leading whitespace after the ytt inline-code token
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
## Overview
* indentation_preserve_request
* ytt version 0.45.0
## Problem
* ytt processing does not preserve leading whitespace for `#@` expressions
* ytt appears to remove all whitespace after the `#@` when evaluating ytt-enhanced YAML
## Example
* consider the following well-formed ytt YAML document
* we use a ytt function to output a variable
* we use ytt `#@` expressions to specify inline python/starlark code inside the function
* we define a multiline string variable `str_multiline`
* we then assign the function result to yaml data output
```
## -------------------------------------------------------------------
## begin_ ytt.functions
#@ def feature_request_preserve_indentation():
#@ str_multiline = ('''
#@ charlie_info:
#@ charlie_one: 111
#@ charlie_two: 222
#@ charlie_three: 333
#@ delta_info:
#@ delta_one: 111
#@ delta_two: 222
#@ delta_three: 333
#@ echo_info:
#@ echo_one: 111
#@ echo_two: 222
#@ echo_three: 333
#@ ''')
#@ return(str_multiline)
#@ end
## -------------------------------------------------------------------
## begin_ yaml data output
dataroot:
demo_string: #@ feature_request_preserve_indentation()
```
## Results
* we do not want the undesirable result BEFORE
* instead, we want the desirable result AFTER
### Non desired result -- BEFORE
```
dataroot:
demo_string: |2
charlie_info:
charlie_one: 111
charlie_two: 222
charlie_three: 333
delta_info:
delta_one: 111
delta_two: 222
delta_three: 333
echo_info:
echo_one: 111
echo_two: 222
echo_three: 333
```
### Yes desired result -- AFTER
```
dataroot:
demo_string: |
charlie_info:
charlie_one: 111
charlie_two: 222
charlie_three: 333
delta_info:
delta_one: 111
delta_two: 222
delta_three: 333
echo_info:
echo_one: 111
echo_two: 222
echo_three: 333
```
## Feature request
* please allow ytt code regions to preserve leading whitespace that appears after the `#@` token
## Rationale
* sometimes whitespace is significant (as in this example where the `#@` token is used for a multiline string variable
* the current parsing strategy seems to assume that leading whitespace after the `#@` token is not relevant
* this assumption (if correct) limits the kind of code one can deploy using ytt
---
Vote on this request
This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.
👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"
We are also happy to receive and review Pull Requests if you want to help working on this issue.
Contributor guide
Research direction
Reproduce the supplied ytt 0.45.0 example and compare the current output with the requested output. Start by tracing handling of the `#@` inline-code token and leading whitespace in ytt's parser or evaluator; done means the multiline string preserves the nested indentation shown in the AFTER example without changing unrelated expressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100