mame icon indicating copy to clipboard operation
mame copied to clipboard

scripts/build: add a python script for checking style rules

Open stonedDiscord opened this issue 3 months ago • 4 comments

I realize this is in direct competition with #14107, I started work on this on saturday when I posted the question if this could be automated in the Discord server.

The action will post code reviews, much like a human reviwer would. An example can be seen here: https://github.com/stonedDiscord/mame/pull/5

I went through https://docs.mamedev.org/contributing/cxx.html to come up with these rules. It will detect

  • Missing newline at EOF
  • Invalid UTF-8
  • Wrong type of line ending
  • Trailing whitespaces
  • Uppercase hex literals
  • Single line block comments
  • Lowercase constants
  • Uppercase functions
  • Uppercase class names
  • Uppercase Enum names

It mostly uses regex to detect those, I haven't run into any false positives yet, but I'm on the fence about dropping the constants check because it will complain about variables that someone has marked const.

stonedDiscord avatar Sep 01 '25 22:09 stonedDiscord

And ironically, it’s a Python script with no final newline…

cuavas avatar Sep 02 '25 12:09 cuavas

I'm aware that I get this constantly wrong, that's why I asked and then wrote this script. I guess I'm simply not used to that style rule and I will probably get it wrong again. The point of the script is to let newbies like myself deal with the review bot so maintainers have more time to review PRs that are ready for merging and don't get fed up or annoyed as much. The CI doesn't block merging, same as with human reviews.

stonedDiscord avatar Sep 02 '25 12:09 stonedDiscord

I've changed it to use no external dependencies and to post a single review with multiple comments, fixing any rate limit issues before they appear.

I've tested the style checker against #14020 here: https://github.com/stonedDiscord/mame/pull/7

stonedDiscord avatar Sep 02 '25 17:09 stonedDiscord

Added checks:

  • SPDX header
  • Include order
  • ROM region

stonedDiscord avatar Nov 08 '25 09:11 stonedDiscord