瀏覽代碼

Fix various lint errors (#17255)

* Fix various lint errors

* reduce complexity
Joel Challis 3 年之前
父節點
當前提交
2879573688

+ 1 - 1
keyboards/axolstudio/yeti/hotswap/hotswap.c

@@ -98,7 +98,7 @@ led_config_t g_led_config = {
     }, {
     }, {
         {0, 0},{16, 0},{32, 0},{48, 0},{64, 0},{80, 0},{96, 0},{112, 0},{128, 0},{144, 0},{160, 0},{176, 0},{192, 0},{208, 0},{224, 0},
         {0, 0},{16, 0},{32, 0},{48, 0},{64, 0},{80, 0},{96, 0},{112, 0},{128, 0},{144, 0},{160, 0},{176, 0},{192, 0},{208, 0},{224, 0},
         {0, 16},{16,16},{32,16},{48,16},{64,16},{80,16},{96,16},{112,16},{128,16},{144,16},{160,16},{176,16},{192,16},{208,16},{224,16},
         {0, 16},{16,16},{32,16},{48,16},{64,16},{80,16},{96,16},{112,16},{128,16},{144,16},{160,16},{176,16},{192,16},{208,16},{224,16},
-        {0,32},{16,32},{32,32},{48,32},{64,32},{80,32},{96,32},{112,32},{128,32},{144,32},{160,32},{176,32},{192,32},{224},
+        {0,32},{16,32},{32,32},{48,32},{64,32},{80,32},{96,32},{112,32},{128,32},{144,32},{160,32},{176,32},{192,32},{224, 32},
         {16,48},{32,48},{48,48},{64,48},{80,48},{96,48},{112,48},{128,48},{144,48},{160,48},{176,48},{192,48},{224,48},
         {16,48},{32,48},{48,48},{64,48},{80,48},{96,48},{112,48},{128,48},{144,48},{160,48},{176,48},{192,48},{224,48},
         {16,64},{48,64},{80,64},{96,64},{128,64},{160,64},{224,64}
         {16,64},{48,64},{80,64},{96,64},{128,64},{160,64},{224,64}
     }, {
     }, {

+ 1 - 1
keyboards/phase_studio/titan65/hotswap/hotswap.c

@@ -20,7 +20,7 @@
 led_config_t g_led_config = {
 led_config_t g_led_config = {
     {
     {
         {     52,     53, 54,     55,     56,     57, 58,     59,     60,     61, 62, 63,     64,    NO_LED,      65, 66 },
         {     52,     53, 54,     55,     56,     57, 58,     59,     60,     61, 62, 63,     64,    NO_LED,      65, 66 },
-        {     51, NO_LED, 50,     49,     48,     47, 46,     45,     44,     43, 42, 41,     40,         39,    .38, 37 },
+        {     51, NO_LED, 50,     49,     48,     47, 46,     45,     44,     43, 42, 41,     40,         39,     38, 37 },
         {     23, NO_LED, 24,     25,     26,     27, 28,     29,     30,     31, 32, 33,     34,         35, NO_LED, 36 },
         {     23, NO_LED, 24,     25,     26,     27, 28,     29,     30,     31, 32, 33,     34,         35, NO_LED, 36 },
         { NO_LED,     22, 21,     20,     19,     18, 17,     16,     15,     14, 13, 12, NO_LED,         11,     10,  9 },
         { NO_LED,     22, 21,     20,     19,     18, 17,     16,     15,     14, 13, 12, NO_LED,         11,     10,  9 },
         {      0,      1, NO_LED, 2, NO_LED, NO_LED,  3, NO_LED, NO_LED, NO_LED,  4,  5, NO_LED,          6,      7,  8 }
         {      0,      1, NO_LED, 2, NO_LED, NO_LED,  3, NO_LED, NO_LED, NO_LED,  4,  5, NO_LED,          6,      7,  8 }

+ 1 - 2
keyboards/signum/3_0/3_0.h

@@ -18,7 +18,7 @@
 #include "quantum.h"
 #include "quantum.h"
 
 
 // clang-format off
 // clang-format off
-# define LAYOUT( \
+# define LAYOUT_ortho_4x12( \
 	K000, K001, K002, K003, K004, K005, K006, K007, K008, K009, K010, K011, \
 	K000, K001, K002, K003, K004, K005, K006, K007, K008, K009, K010, K011, \
 	K100, K101, K102, K103, K104, K105, K106, K107, K108, K109, K110, K111, \
 	K100, K101, K102, K103, K104, K105, K106, K107, K108, K109, K110, K111, \
 	K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, \
 	K200, K201, K202, K203, K204, K205, K206, K207, K208, K209, K210, K211, \
@@ -30,4 +30,3 @@
 	{ K300,  K301,  K302,  K303,  K304,  K305,  K306,  K307,  K308,  K309,  K310,  K311 }  \
 	{ K300,  K301,  K302,  K303,  K304,  K305,  K306,  K307,  K308,  K309,  K310,  K311 }  \
 }
 }
 // clang-format on
 // clang-format on
-#define LAYOUT_ortho_4x12 LAYOUT

+ 3 - 0
keyboards/signum/3_0/info.json

@@ -2,6 +2,9 @@
     "keyboard_name": "Signum 3.0",
     "keyboard_name": "Signum 3.0",
     "url": "http://troyfletcher.net/",
     "url": "http://troyfletcher.net/",
     "maintainer": "jceb",
     "maintainer": "jceb",
+    "layout_aliases": {
+        "LAYOUT": "LAYOUT_ortho_4x12"
+    },
     "layouts": {
     "layouts": {
         "LAYOUT_ortho_4x12": {
         "LAYOUT_ortho_4x12": {
             "layout": [
             "layout": [

+ 27 - 16
lib/python/qmk/c_parse.py

@@ -24,6 +24,14 @@ def _get_chunks(it, size):
     return iter(lambda: tuple(islice(it, size)), ())
     return iter(lambda: tuple(islice(it, size)), ())
 
 
 
 
+def _preprocess_c_file(file):
+    """Load file and strip comments
+    """
+    file_contents = file.read_text(encoding='utf-8')
+    file_contents = comment_remover(file_contents)
+    return file_contents.replace('\\\n', '')
+
+
 def strip_line_comment(string):
 def strip_line_comment(string):
     """Removes comments from a single line string.
     """Removes comments from a single line string.
     """
     """
@@ -58,9 +66,7 @@ def find_layouts(file):
     parsed_layouts = {}
     parsed_layouts = {}
 
 
     # Search the file for LAYOUT macros and aliases
     # Search the file for LAYOUT macros and aliases
-    file_contents = file.read_text(encoding='utf-8')
-    file_contents = comment_remover(file_contents)
-    file_contents = file_contents.replace('\\\n', '')
+    file_contents = _preprocess_c_file(file)
 
 
     for line in file_contents.split('\n'):
     for line in file_contents.split('\n'):
         if layout_macro_define_regex.match(line.lstrip()) and '(' in line and 'LAYOUT' in line:
         if layout_macro_define_regex.match(line.lstrip()) and '(' in line and 'LAYOUT' in line:
@@ -205,13 +211,23 @@ def _coerce_led_token(_type, value):
         return value_map[value]
         return value_map[value]
 
 
 
 
+def _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags):
+    # TODO: Improve crude parsing/validation
+    if len(matrix) != matrix_rows and len(matrix) != (matrix_rows / 2):
+        raise ValueError("Unable to parse g_led_config matrix data")
+    if len(position) != len(flags):
+        raise ValueError("Unable to parse g_led_config position data")
+    if len(matrix_indexes) and (max(matrix_indexes) >= len(flags)):
+        raise ValueError("OOB within g_led_config matrix data")
+    if not all(isinstance(n, int) for n in matrix_indexes):
+        raise ValueError("matrix indexes are not all ints")
+    if (len(position_raw) % 2) != 0:
+        raise ValueError("Malformed g_led_config position data")
+
+
 def _parse_led_config(file, matrix_cols, matrix_rows):
 def _parse_led_config(file, matrix_cols, matrix_rows):
     """Return any 'raw' led/rgb matrix config
     """Return any 'raw' led/rgb matrix config
     """
     """
-    file_contents = file.read_text(encoding='utf-8')
-    file_contents = comment_remover(file_contents)
-    file_contents = file_contents.replace('\\\n', '')
-
     matrix_raw = []
     matrix_raw = []
     position_raw = []
     position_raw = []
     flags = []
     flags = []
@@ -219,7 +235,7 @@ def _parse_led_config(file, matrix_cols, matrix_rows):
     found_led_config = False
     found_led_config = False
     bracket_count = 0
     bracket_count = 0
     section = 0
     section = 0
-    for _type, value in lex(file_contents, CLexer()):
+    for _type, value in lex(_preprocess_c_file(file), CLexer()):
         # Assume g_led_config..stuff..;
         # Assume g_led_config..stuff..;
         if value == 'g_led_config':
         if value == 'g_led_config':
             found_led_config = True
             found_led_config = True
@@ -248,17 +264,12 @@ def _parse_led_config(file, matrix_cols, matrix_rows):
     position = list(_get_chunks(position_raw, 2))
     position = list(_get_chunks(position_raw, 2))
     matrix_indexes = list(filter(lambda x: x is not None, matrix_raw))
     matrix_indexes = list(filter(lambda x: x is not None, matrix_raw))
 
 
-    # If we have not found anything - bail
+    # If we have not found anything - bail with no error
     if not section:
     if not section:
         return None
         return None
 
 
-    # TODO: Improve crude parsing/validation
-    if len(matrix) != matrix_rows and len(matrix) != (matrix_rows / 2):
-        raise ValueError("Unable to parse g_led_config matrix data")
-    if len(position) != len(flags):
-        raise ValueError("Unable to parse g_led_config position data")
-    if len(matrix_indexes) and (max(matrix_indexes) >= len(flags)):
-        raise ValueError("OOB within g_led_config matrix data")
+    # Throw any validation errors
+    _validate_led_config(matrix, matrix_rows, matrix_indexes, position, position_raw, flags)
 
 
     return (matrix, position, flags)
     return (matrix, position, flags)