diff --git a/.printer-linter b/.printer-linter index 856649f420..f9f105e1f7 100644 --- a/.printer-linter +++ b/.printer-linter @@ -9,7 +9,7 @@ format: format-definition-paired-coordinate-array: true format-definition-sort-keys: true 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-sort-keys: true diagnostic-mesh-file-size: 1200000 \ No newline at end of file diff --git a/printer-linter/README.md b/printer-linter/README.md index e69de29bb2..64246e5440 100644 --- a/printer-linter/README.md +++ b/printer-linter/README.md @@ -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 + diff --git a/printer-linter/src/terminal.py b/printer-linter/src/terminal.py index f388dda4c5..d363dc3812 100644 --- a/printer-linter/src/terminal.py +++ b/printer-linter/src/terminal.py @@ -49,7 +49,11 @@ def formatFile(file: Path, settings) -> None: content = newline.sub(r"\1\2:\1{", content) 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): paired_coordinates = re.compile(r"(\[)\s+(-?\d*),\s*(-?\d*)\s*(\])")