summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2020-11-07 09:56:08 -0800
committerGitHub <noreply@github.com>2020-11-07 09:56:08 -0800
commit4d33d72975f2d63c7b6ff6fd4aa7e0f4c4347583 (patch)
treeafc9f0ebeeefed8405443cbe8636458d6c4c18d2 /lib/python/qmk/cli
parent7ce5402417b0332569bf48cf2c51e412cd35a18a (diff)
New command: qmk lint (#10761)
* Basic qmk lint command * check for keymap readme * change the workflow from qmk info to qmk lint * add a strict mode * parsing -> parse * document qmk lint * small info logging cleanup * Apply suggestions from code review Co-authored-by: Ryan <fauxpark@gmail.com> * honor --strict in more places * change the job name to lint Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/__init__.py1
-rw-r--r--lib/python/qmk/cli/lint.py70
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 3868f94bb2..77724a2448 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -19,6 +19,7 @@ from . import hello
from . import info
from . import json
from . import json2c
+from . import lint
from . import list
from . import kle2json
from . import new
diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py
new file mode 100644
index 0000000000..74467021e0
--- /dev/null
+++ b/lib/python/qmk/cli/lint.py
@@ -0,0 +1,70 @@
+"""Command to look over a keyboard/keymap and check for common mistakes.
+"""
+from milc import cli
+
+from qmk.decorators import automagic_keyboard, automagic_keymap
+from qmk.info import info_json
+from qmk.keymap import locate_keymap
+from qmk.path import is_keyboard, keyboard
+
+
+@cli.argument('--strict', action='store_true', help='Treat warnings as errors.')
+@cli.argument('-kb', '--keyboard', help='The keyboard to check.')
+@cli.argument('-km', '--keymap', help='The keymap to check.')
+@cli.subcommand('Check keyboard and keymap for common mistakes.')
+@automagic_keyboard
+@automagic_keymap
+def lint(cli):
+ """Check keyboard and keymap for common mistakes.
+ """
+ if not cli.config.lint.keyboard:
+ cli.log.error('Missing required argument: --keyboard')
+ cli.print_help()
+ return False
+
+ if not is_keyboard(cli.config.lint.keyboard):
+ cli.log.error('No such keyboard: %s', cli.config.lint.keyboard)
+ return False
+
+ # Gather data about the keyboard.
+ ok = True
+ keyboard_path = keyboard(cli.config.lint.keyboard)
+ keyboard_info = info_json(cli.config.lint.keyboard)
+ readme_path = keyboard_path / 'readme.md'
+
+ # Check for errors in the info.json
+ if keyboard_info['parse_errors']:
+ ok = False
+ cli.log.error('Errors found when generating info.json.')
+
+ if cli.config.lint.strict and keyboard_info['parse_warnings']:
+ ok = False
+ cli.log.error('Warnings found when generating info.json (Strict mode enabled.)')
+
+ # Check for a readme.md and warn if it doesn't exist
+ if not readme_path.exists():
+ ok = False
+ cli.log.error('Missing %s', readme_path)
+
+ # Keymap specific checks
+ if cli.config.lint.keymap:
+ keymap_path = locate_keymap(cli.config.lint.keyboard, cli.config.lint.keymap)
+
+ if not keymap_path:
+ ok = False
+ cli.log.error("Can't find %s keymap for %s keyboard.", cli.config.lint.keymap, cli.config.lint.keyboard)
+ else:
+ keymap_readme = keymap_path.parent / 'readme.md'
+ if not keymap_readme.exists():
+ cli.log.warning('Missing %s', keymap_readme)
+
+ if cli.config.lint.strict:
+ ok = False
+
+ # Check and report the overall status
+ if ok:
+ cli.log.info('Lint check passed!')
+ return True
+
+ cli.log.error('Lint check failed!')
+ return False