diff --git a/tools/hooks/check-trailing-commas.py b/tools/hooks/check-trailing-commas.py index 79aab10a573fb23d7af7deb9796de9e82733db93..d6f4f2c507bfe3081fa7dd2b467e0bbdd86b68e6 100755 --- a/tools/hooks/check-trailing-commas.py +++ b/tools/hooks/check-trailing-commas.py @@ -101,7 +101,14 @@ def check_first_indent(self, node, attr): if self.should_skip(node, attr): return - first_elt_token = getattr(node, attr)[0].first_token + if getattr(node, attr)[0]: + first_elt_token = getattr(node, attr)[0].first_token + else: + assert isinstance(node, ast.Dict) and attr == 'keys', "None node should only be in dict keys" + # a None node in ast.Dict.keys happens in case of **mapping + # use the tokens of the value then, nevermind the "**" tokens + first_elt_token = node.values[0].first_token + if first_elt_token.start[0] == node.first_token.start[0]: self.add_error( 'first element should start on a new line',