Skip to content

Commit 47369fb

Browse files
authored
Support stdlib NOLINT comment on functions (#226)
1 parent a60a42d commit 47369fb

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: false
99
matrix:
1010
os: [macos-latest, windows-latest, ubuntu-latest]
11-
python-version: [3.6, 3.7, 3.8]
11+
python-version: ['3.8', '3.9', '3.10']
1212
name: Test - ${{ matrix.os }}, ${{ matrix.python-version }}
1313
runs-on: ${{ matrix.os }}
1414
steps:
@@ -136,7 +136,7 @@ jobs:
136136

137137
- uses: actions/setup-python@v2
138138
with:
139-
python-version: 3.7
139+
python-version: '3.10'
140140

141141
- name: Install Python dependencies
142142
run: pip install wheel

wpiformat/wpiformat/stdlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ def func_substitute(header, lines):
223223
pos = match.start(1) + len(header.prefix) + len(match.group(1))
224224

225225
# If function name is part of this header, substitute its name
226-
if match.group(1) in header.func_names:
226+
line = lines[match.start(1):lines.find("\n", match.start(1))]
227+
if match.group(1) in header.func_names and "NOLINT" not in line:
227228
lines = lines[0:match.start(1)] + header.prefix + \
228229
match.group(1) + lines[match.end(1):]
229230
return lines

wpiformat/wpiformat/test/test_stdlib.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ def test_stdlib():
3636
" std::free(mem);" + os.linesep + \
3737
"}" + os.linesep, True)
3838

39-
# Test NOLINT
39+
# Test NOLINT on #include
4040
test.add_input("./Main.cpp",
4141
"#include <cstdint> // NOLINT" + os.linesep + \
4242
"#include <stdlib.h> // NOLINT" + os.linesep)
4343
test.add_latest_input_as_output(True)
4444

45+
# Test NOLINT on function
46+
test.add_input("./Main.cpp",
47+
" abs() // NOLINT" + os.linesep + \
48+
" abs()" + os.linesep + \
49+
" abs() // NOLINT" + os.linesep)
50+
test.add_output(
51+
" abs() // NOLINT" + os.linesep + \
52+
" std::abs()" + os.linesep + \
53+
" abs() // NOLINT" + os.linesep, True)
54+
4555
# FILE should be recognized as type here
4656
test.add_input("./Class.cpp", "static FILE* Class::file = nullptr;")
4757
test.add_output("static std::FILE* Class::file = nullptr;", True)

0 commit comments

Comments
 (0)