You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

  1. """Command to look over a keyboard/keymap and check for common mistakes.
  2. """
  3. from milc import cli
  4. from qmk.decorators import automagic_keyboard, automagic_keymap
  5. from qmk.info import info_json
  6. from qmk.keyboard import keyboard_completer
  7. from qmk.keymap import locate_keymap
  8. from qmk.path import is_keyboard, keyboard
  9. @cli.argument('--strict', action='store_true', help='Treat warnings as errors.')
  10. @cli.argument('-kb', '--keyboard', completer=keyboard_completer, help='The keyboard to check.')
  11. @cli.argument('-km', '--keymap', help='The keymap to check.')
  12. @cli.subcommand('Check keyboard and keymap for common mistakes.')
  13. @automagic_keyboard
  14. @automagic_keymap
  15. def lint(cli):
  16. """Check keyboard and keymap for common mistakes.
  17. """
  18. if not cli.config.lint.keyboard:
  19. cli.log.error('Missing required argument: --keyboard')
  20. cli.print_help()
  21. return False
  22. if not is_keyboard(cli.config.lint.keyboard):
  23. cli.log.error('No such keyboard: %s', cli.config.lint.keyboard)
  24. return False
  25. # Gather data about the keyboard.
  26. ok = True
  27. keyboard_path = keyboard(cli.config.lint.keyboard)
  28. keyboard_info = info_json(cli.config.lint.keyboard)
  29. readme_path = keyboard_path / 'readme.md'
  30. # Check for errors in the info.json
  31. if keyboard_info['parse_errors']:
  32. ok = False
  33. cli.log.error('Errors found when generating info.json.')
  34. if cli.config.lint.strict and keyboard_info['parse_warnings']:
  35. ok = False
  36. cli.log.error('Warnings found when generating info.json (Strict mode enabled.)')
  37. # Check for a readme.md and warn if it doesn't exist
  38. if not readme_path.exists():
  39. ok = False
  40. cli.log.error('Missing %s', readme_path)
  41. # Keymap specific checks
  42. if cli.config.lint.keymap:
  43. keymap_path = locate_keymap(cli.config.lint.keyboard, cli.config.lint.keymap)
  44. if not keymap_path:
  45. ok = False
  46. cli.log.error("Can't find %s keymap for %s keyboard.", cli.config.lint.keymap, cli.config.lint.keyboard)
  47. else:
  48. keymap_readme = keymap_path.parent / 'readme.md'
  49. if not keymap_readme.exists():
  50. cli.log.warning('Missing %s', keymap_readme)
  51. if cli.config.lint.strict:
  52. ok = False
  53. # Check and report the overall status
  54. if ok:
  55. cli.log.info('Lint check passed!')
  56. return True
  57. cli.log.error('Lint check failed!')
  58. return False