Skip to content
This repository was archived by the owner on Jul 13, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
'Lines should be <= %i characters long' % _line_length)

if (cleansed_line.count(';') > 1 and
# allow simple single line lambdas
not Match(r'^[^{};]*\[[^\[\]]*\][^{}]*\{[^{}\n\r]*\}',
line) and
# for loops are allowed two ;'s (and may run over two lines).
cleansed_line.find('for') == -1 and
(GetPreviousNonBlankLine(clean_lines, linenum)[0].find('for') == -1 or
Expand Down
48 changes: 48 additions & 0 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,54 @@ def testMultipleStatementsOnSameLine(self):
error_collector)
cpplint._cpplint_state.verbose_level = old_verbose_level

def testLambdasOnSameLine(self):
error_collector = ErrorCollector(self.assert_)
old_verbose_level = cpplint._cpplint_state.verbose_level
cpplint._cpplint_state.verbose_level = 0
cpplint.ProcessFileData('foo.cc', 'cc',
['const auto lambda = '
'[](const int i) { return i; };'],
error_collector)
cpplint._cpplint_state.verbose_level = old_verbose_level
self.assertEquals(0, error_collector.Results().count(
'More than one command on the same line [whitespace/newline] [0]'))

error_collector = ErrorCollector(self.assert_)
old_verbose_level = cpplint._cpplint_state.verbose_level
cpplint._cpplint_state.verbose_level = 0
cpplint.ProcessFileData('foo.cc', 'cc',
['const auto result = std::any_of(vector.begin(), '
'vector.end(), '
'[](const int i) { return i > 0; });'],
error_collector)
cpplint._cpplint_state.verbose_level = old_verbose_level
self.assertEquals(0, error_collector.Results().count(
'More than one command on the same line [whitespace/newline] [0]'))

error_collector = ErrorCollector(self.assert_)
old_verbose_level = cpplint._cpplint_state.verbose_level
cpplint._cpplint_state.verbose_level = 0
cpplint.ProcessFileData('foo.cc', 'cc',
['return mutex::Lock<void>([this]() { '
'this->ReadLock(); }, [this]() { '
'this->ReadUnlock(); });'],
error_collector)
cpplint._cpplint_state.verbose_level = old_verbose_level
self.assertEquals(0, error_collector.Results().count(
'More than one command on the same line [whitespace/newline] [0]'))

error_collector = ErrorCollector(self.assert_)
old_verbose_level = cpplint._cpplint_state.verbose_level
cpplint._cpplint_state.verbose_level = 0
cpplint.ProcessFileData('foo.cc', 'cc',
['return mutex::Lock<void>([this]() { '
'this->ReadLock(); }, [this]() { '
'this->ReadUnlock(); }, object);'],
error_collector)
cpplint._cpplint_state.verbose_level = old_verbose_level
self.assertEquals(0, error_collector.Results().count(
'More than one command on the same line [whitespace/newline] [0]'))

def testEndOfNamespaceComments(self):
error_collector = ErrorCollector(self.assert_)
cpplint.ProcessFileData('foo.cc', 'cc',
Expand Down