Skip to content

Commit b72d3f8

Browse files
committed
Avoid false positive warnings for QT signals and slots extended syntax.
This reuses the same regex snippet as in Update() Note that QT also allows to use macros instead of keywords: Q_SIGNAL, Q_SIGNALS, Q_SLOT, Q_SLOTS, but apparently this is not used not frequently enough to include in cpplint.
1 parent a687e51 commit b72d3f8

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

cpplint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4803,7 +4803,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
48034803
# if(match($0, " <<")) complain = 0;
48044804
# if(match(prev, " +for \\(")) complain = 0;
48054805
# if(prevodd && match(prevprev, " +for \\(")) complain = 0;
4806-
scope_or_label_pattern = r'\s*\w+\s*:\s*\\?$'
4806+
scope_or_label_pattern = r'\s*(?:public|private|protected|signals)(?:\s+(?:slots\s*)?)?:\s*\\?$'
48074807
classinfo = nesting_state.InnermostClass()
48084808
initial_spaces = 0
48094809
cleansed_line = clean_lines.elided[linenum]

cpplint_unittest.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,14 +3712,31 @@ def testIndent(self):
37123712
self.TestLint(' protected: \\', '')
37133713
self.TestLint(' public: \\', '')
37143714
self.TestLint(' private: \\', '')
3715+
# examples using QT signals/slots macro
37153716
self.TestMultiLineLint(
37163717
TrimExtraIndent("""
37173718
class foo {
37183719
public slots:
37193720
void bar();
3721+
signals:
37203722
};"""),
3721-
'Weird number of spaces at line-start. '
3722-
'Are you using a 2-space indent? [whitespace/indent] [3]')
3723+
'')
3724+
self.TestMultiLineLint(
3725+
TrimExtraIndent("""
3726+
class foo {
3727+
public slots:
3728+
void bar();
3729+
};"""),
3730+
'public slots: should be indented +1 space inside class foo'
3731+
' [whitespace/indent] [3]')
3732+
self.TestMultiLineLint(
3733+
TrimExtraIndent("""
3734+
class foo {
3735+
signals:
3736+
void bar();
3737+
};"""),
3738+
'signals: should be indented +1 space inside class foo'
3739+
' [whitespace/indent] [3]')
37233740
self.TestMultiLineLint(
37243741
TrimExtraIndent('''
37253742
static const char kRawString[] = R"("

0 commit comments

Comments
 (0)