Skip to content

Commit 13f2462

Browse files
committed
stylecheck: Add uncrastify exception for STATS
Uncrustify removes leading spaces from STATS. This simple awk scrip if executed after uncrustify inserts spaces when expected Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 884ed2e commit 13f2462

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.github/check_style.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def check_file(fname: str, commit: str, upstream: str) -> list[str]:
6161
in_chunk = False
6262

6363
for s in run_cmd(f"uncrustify -q -c uncrustify.cfg -f {tmpf.name} | "
64+
f"awk -f uncrustify.awk | "
6465
f"diff -u0 -p {tmpf.name} - || true"):
6566
m = re.match(r"^@@ -(\d+)(?:,(\d+))? \+\d+(?:,\d+)? @@", s)
6667
if not m:

uncrustify.awk

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# awk script run AFTER uncrustify reformats code to format
21+
# STATS_NAME and STATS_SECT block to have indents removed
22+
# by uncrustify
23+
24+
# detect begining of STATS_NAME section
25+
/^(static )?STATS_NAME_START[(]/ { stats_name = 1 }
26+
# detect end of STATN_NAME section
27+
/^STATS_NAME_END/ { stats_name = 0 }
28+
# for each line in sectin add 4 spaces eaten by uncrustify
29+
/^STATS_NAME[(]/ && stats_name == 1 { printf " " }
30+
31+
# detect begining of STATS_SECT section
32+
/^STATS_SECT_START[(]/ { stats_sect = 1 }
33+
# detect end of STATN_SECT section
34+
/^STATS_SECT_END/ { stats_sect = 0 }
35+
# for each line in sectin add 4 spaces eaten by uncrustify
36+
/^STATS_SECT_ENTRY[(]/ && stats_sect == 1 { printf " " }
37+
{ print }

0 commit comments

Comments
 (0)