Format lists and dicts of a single item onto one line

example:
"dict":
{
 "value": 10
}
becomes
"dict": { "value": 10 }
This commit is contained in:
Joey de l'Arago 2022-11-22 21:42:42 +01:00
parent a470f02373
commit ad7e719146
3 changed files with 17 additions and 2 deletions

View file

@ -9,7 +9,7 @@ format:
format-definition-paired-coordinate-array: true format-definition-paired-coordinate-array: true
format-definition-sort-keys: true format-definition-sort-keys: true
format-definition-indent: 4 format-definition-indent: 4
format-definition-single-value-single-line: true format-definition-single-value-single-line: true # Format dicts and lists with a single item on one line "dict": { "value": 10 }
format-profile-space-around-delimiters: true format-profile-space-around-delimiters: true
format-profile-sort-keys: true format-profile-sort-keys: true
diagnostic-mesh-file-size: 1200000 diagnostic-mesh-file-size: 1200000

View file

@ -0,0 +1,11 @@
# Printer Linter
Printer linter is a python package that does linting on Cura definitions files.
Running this on your definition files will get them ready for a pull request.
## Running Locally
From the Cura root folder.
```python3 printer-linter/src/terminal.py "flashforge_dreamer_nx.def.json" "flashforge_base.def.json" --fix --format```
## Developing

View file

@ -49,7 +49,11 @@ def formatFile(file: Path, settings) -> None:
content = newline.sub(r"\1\2:\1{", content) content = newline.sub(r"\1\2:\1{", content)
if settings["format"].get("format-definition-single-value-single-line", True): if settings["format"].get("format-definition-single-value-single-line", True):
pass # TODO: format entries in the override section which only define a single value to be on one line single_value_dict = re.compile(r"(:)(\s*\n?.*\{\s+)(\".*)(\d*\s*\})(\s*)(,?)")
content = single_value_dict.sub(r"\1 { \3 }\6", content)
single_value_list = re.compile(r"(:)(\s*\n?.*\[\s+)(\".*)(\d*\s*\])(\s*)(,?)")
content = single_value_list.sub(r"\1 [ \3 ]\6", content)
if settings["format"].get("format-definition-paired-coordinate-array", True): if settings["format"].get("format-definition-paired-coordinate-array", True):
paired_coordinates = re.compile(r"(\[)\s+(-?\d*),\s*(-?\d*)\s*(\])") paired_coordinates = re.compile(r"(\[)\s+(-?\d*),\s*(-?\d*)\s*(\])")