flatpak-external-data-checker icon indicating copy to clipboard operation
flatpak-external-data-checker copied to clipboard

Prevent line truncation in YAML manifests

Open guihkx opened this issue 2 years ago • 2 comments

Hello,

In this pull request, the bot unnecessarily truncates line 34.

I'm not sure if Flathub has a "max line-length" guideline, but nevertheless this can be properly configured using the width option of ruamel, e.g. at:

https://github.com/flathub/flatpak-external-data-checker/blob/88e46ff8ee3176b4fea752876304e4a249765462/src/lib/utils.py#L417-L422

We'd add:

# allows lines to have at most one thousand characters
_yaml.width = 1000

Thanks!

guihkx avatar Mar 26 '22 05:03 guihkx

The code to write manifests back supports reading format preferences from .editorconfig and applying them to JSON files.

It seems that a max_line_length property is defined.

You could teach the dump_manifest function to check for such a key and apply it?

wjt avatar Apr 05 '22 12:04 wjt

Something like this except tested and passing checks and maybe not modifying global state?

diff --git a/src/lib/utils.py b/src/lib/utils.py
index c5f767f..1b83604 100644
--- a/src/lib/utils.py
+++ b/src/lib/utils.py
@@ -456,6 +456,10 @@ def dump_manifest(contents: t.Dict, manifest_path: t.Union[Path, str]):
     else:
         indent = 4
 
+    max_line_length = conf.get("max_line_length")
+    if isinstance(max_line_length, int):
+        _yaml.width = max_line_length
+
     # Determine trailing newline preference
     newline: t.Optional[bool]
     if "insert_final_newline" in conf:

wjt avatar Apr 05 '22 12:04 wjt