Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to configure line length #4

Open
peeter-tomberg opened this issue Sep 26, 2021 · 2 comments · May be fixed by #5
Open

Ability to configure line length #4

peeter-tomberg opened this issue Sep 26, 2021 · 2 comments · May be fixed by #5

Comments

@peeter-tomberg
Copy link

Hello!

Awesome project, really loving it!

We've got an internal project using lots of YAML configuration files and using this patch to modify them is really awesome! One thing we did discover though, is that when modifying long lines (length over 80 characters) it would split those lines into multiple lines around the 80 character mark (seems to be preferring white space to do the splitting, so the actual number will vary).

Any thoughts on how we can get around this, or make this configurable?

@grantila
Copy link
Owner

I can only refer to the same kind of problem as this one: #3 (comment)

There currently is no good solution possible afaik.

@levrik levrik linked a pull request Jan 22, 2023 that will close this issue
@LeVraiSylvain
Copy link

LeVraiSylvain commented Jan 29, 2023

Here is the trick. Just parse de new yaml created by yamlOverwrite and create a new yaml with doc.toString({lineWidth: 80})

`
import yaml from 'yaml';
import { yamlOverwrite } from 'yaml-diff-patch';
....

updateChartFile(chart: HelmChart) {
const oldYaml = FileService.read(this.chartFilePath);

const newYaml = yamlOverwrite(oldYaml, chart);

const doc = yaml.parseDocument(newYaml);

FileService.write(this.chartFilePath, doc.toString({
    lineWidth: this.getMaxLineWidth(oldYaml)
}));

}

private getMaxLineWidth(yaml: string) {
return yaml.replace('/\r\n/g', '\n').split('\n').reduce((p, v) => p > v.length ? p : v.length, 0);
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants