From 3e60997edba46544557b3a775bdb1538e07c3edf Mon Sep 17 00:00:00 2001
From: Zach White <skullydazed@gmail.com>
Date: Thu, 25 Mar 2021 04:38:10 -0700
Subject: Add a `qmk format-json` command that will format JSON files (#12372)

* Add a command to format json files

* change to work after rebase

* add test for qmk format-json

* add documentation for qmk format-json

* Update lib/python/qmk/cli/format/json.py
---
 lib/python/qmk/tests/minimal_info.json    | 13 +++++++++++++
 lib/python/qmk/tests/minimal_keymap.json  |  7 +++++++
 lib/python/qmk/tests/pytest_export.json   |  6 ------
 lib/python/qmk/tests/test_cli_commands.py | 24 ++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 lib/python/qmk/tests/minimal_info.json
 create mode 100644 lib/python/qmk/tests/minimal_keymap.json
 delete mode 100644 lib/python/qmk/tests/pytest_export.json

(limited to 'lib/python/qmk/tests')

diff --git a/lib/python/qmk/tests/minimal_info.json b/lib/python/qmk/tests/minimal_info.json
new file mode 100644
index 0000000000..b91c23bd3d
--- /dev/null
+++ b/lib/python/qmk/tests/minimal_info.json
@@ -0,0 +1,13 @@
+{
+    "keyboard_name": "tester",
+    "maintainer": "qmk",
+    "height": 5,
+    "width": 15,
+    "layouts": {
+        "LAYOUT": {
+            "layout": [
+                { "label": "KC_A", "x": 0, "y": 0, "matrix": [0, 0] }
+            ]
+        }
+    }
+}
diff --git a/lib/python/qmk/tests/minimal_keymap.json b/lib/python/qmk/tests/minimal_keymap.json
new file mode 100644
index 0000000000..258f9e8a9a
--- /dev/null
+++ b/lib/python/qmk/tests/minimal_keymap.json
@@ -0,0 +1,7 @@
+{
+    "keyboard": "handwired/pytest/basic",
+    "keymap": "test",
+    "layers": [["KC_A"]],
+    "layout": "LAYOUT_ortho_1x1",
+    "version": 1
+}
diff --git a/lib/python/qmk/tests/pytest_export.json b/lib/python/qmk/tests/pytest_export.json
deleted file mode 100644
index 5fb0d624f8..0000000000
--- a/lib/python/qmk/tests/pytest_export.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
-    "keyboard":"handwired/pytest/basic",
-    "keymap":"pytest_unittest",
-    "layout":"LAYOUT",
-    "layers":[["KC_A"]]
-}
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index a97472e6be..c57d2b7fc7 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -259,3 +259,27 @@ def test_generate_layouts():
     result = check_subcommand('generate-layouts', '-kb', 'handwired/pytest/basic')
     check_returncode(result)
     assert '#define LAYOUT_custom(k0A) {' in result.stdout
+
+
+def test_format_json_keyboard():
+    result = check_subcommand('format-json', '--format', 'keyboard', 'lib/python/qmk/tests/minimal_info.json')
+    check_returncode(result)
+    assert result.stdout == '{\n    "keyboard_name": "tester",\n    "maintainer": "qmk",\n    "height": 5,\n    "width": 15,\n    "layouts": {\n        "LAYOUT": {\n            "layout": [\n                { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n            ]\n        }\n    }\n}\n'
+
+
+def test_format_json_keymap():
+    result = check_subcommand('format-json', '--format', 'keymap', 'lib/python/qmk/tests/minimal_keymap.json')
+    check_returncode(result)
+    assert result.stdout == '{\n    "version": 1,\n    "keyboard": "handwired/pytest/basic",\n    "keymap": "test",\n    "layout": "LAYOUT_ortho_1x1",\n    "layers": [\n                [\n                        "KC_A"\n                ]\n    ]\n}\n'
+
+
+def test_format_json_keyboard_auto():
+    result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_info.json')
+    check_returncode(result)
+    assert result.stdout == '{\n    "keyboard_name": "tester",\n    "maintainer": "qmk",\n    "height": 5,\n    "width": 15,\n    "layouts": {\n        "LAYOUT": {\n            "layout": [\n                { "label": "KC_A", "matrix": [0, 0], "x": 0, "y": 0 }\n            ]\n        }\n    }\n}\n'
+
+
+def test_format_json_keymap_auto():
+    result = check_subcommand('format-json', '--format', 'auto', 'lib/python/qmk/tests/minimal_keymap.json')
+    check_returncode(result)
+    assert result.stdout == '{\n    "keyboard": "handwired/pytest/basic",\n    "keymap": "test",\n    "layers": [\n        ["KC_A"]\n    ],\n    "layout": "LAYOUT_ortho_1x1",\n    "version": 1\n}\n'
-- 
cgit v1.2.3