CLI: Lint non-data driven macros in info.json (#16739)
* CLI: Lint non-data driven macros in info.json Macros in info.json should either have the "matrix" key with the matrix data or should should be also present in <keyboard>.h * Add verification of matrix data * Use generic '<keyboard>.h' in output * Add keyboard name to output * Make C layout macro finding more robust The old code missed C macros if they had whitespace between '#' and 'define' or had whitespace before '#'.
This commit is contained in:
		@@ -10,6 +10,7 @@ from qmk.comment_remover import comment_remover
 | 
				
			|||||||
default_key_entry = {'x': -1, 'y': 0, 'w': 1}
 | 
					default_key_entry = {'x': -1, 'y': 0, 'w': 1}
 | 
				
			||||||
single_comment_regex = re.compile(r'\s+/[/*].*$')
 | 
					single_comment_regex = re.compile(r'\s+/[/*].*$')
 | 
				
			||||||
multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE)
 | 
					multi_comment_regex = re.compile(r'/\*(.|\n)*?\*/', re.MULTILINE)
 | 
				
			||||||
 | 
					layout_macro_define_regex = re.compile(r'^#\s*define')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def strip_line_comment(string):
 | 
					def strip_line_comment(string):
 | 
				
			||||||
@@ -51,7 +52,7 @@ def find_layouts(file):
 | 
				
			|||||||
    file_contents = file_contents.replace('\\\n', '')
 | 
					    file_contents = file_contents.replace('\\\n', '')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for line in file_contents.split('\n'):
 | 
					    for line in file_contents.split('\n'):
 | 
				
			||||||
        if line.startswith('#define') and '(' in line and 'LAYOUT' in line:
 | 
					        if layout_macro_define_regex.match(line.lstrip()) and '(' in line and 'LAYOUT' in line:
 | 
				
			||||||
            # We've found a LAYOUT macro
 | 
					            # We've found a LAYOUT macro
 | 
				
			||||||
            macro_name, layout, matrix = _parse_layout_macro(line.strip())
 | 
					            macro_name, layout, matrix = _parse_layout_macro(line.strip())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,6 +116,13 @@ def lint(cli):
 | 
				
			|||||||
            if not keymap_check(kb, cli.config.lint.keymap):
 | 
					            if not keymap_check(kb, cli.config.lint.keymap):
 | 
				
			||||||
                ok = False
 | 
					                ok = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Check if all non-data driven macros exist in <keyboard.h>
 | 
				
			||||||
 | 
					        for layout, data in keyboard_info['layouts'].items():
 | 
				
			||||||
 | 
					            # Matrix data should be a list with exactly two integers: [0, 1]
 | 
				
			||||||
 | 
					            if not data['c_macro'] and not all('matrix' in key_data.keys() or len(key_data) == 2 or all(isinstance(n, int) for n in key_data) for key_data in data['layout']):
 | 
				
			||||||
 | 
					                cli.log.error(f'{kb}: "{layout}" has no "matrix" definition in either "info.json" or "<keyboard>.h"!')
 | 
				
			||||||
 | 
					                ok = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Report status
 | 
					        # Report status
 | 
				
			||||||
        if not ok:
 | 
					        if not ok:
 | 
				
			||||||
            failed.append(kb)
 | 
					            failed.append(kb)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user