Skip to content
This repository was archived by the owner on Jul 13, 2019. It is now read-only.

Commit fa7a263

Browse files
committed
Merge branch 'single-line-lambdas'
2 parents dbe2ed8 + cde2b9b commit fa7a263

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

cpplint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4477,6 +4477,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
44774477
'Lines should be <= %i characters long' % _line_length)
44784478

44794479
if (cleansed_line.count(';') > 1 and
4480+
# allow simple single line lambdas
4481+
not Match(r'^[^{};]*\[[^\[\]]*\][^{}]*\{[^{}\n\r]*\}',
4482+
line) and
44804483
# for loops are allowed two ;'s (and may run over two lines).
44814484
cleansed_line.find('for') == -1 and
44824485
(GetPreviousNonBlankLine(clean_lines, linenum)[0].find('for') == -1 or

cpplint_unittest.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,54 @@ def testMultipleStatementsOnSameLine(self):
32113211
error_collector)
32123212
cpplint._cpplint_state.verbose_level = old_verbose_level
32133213

3214+
def testLambdasOnSameLine(self):
3215+
error_collector = ErrorCollector(self.assert_)
3216+
old_verbose_level = cpplint._cpplint_state.verbose_level
3217+
cpplint._cpplint_state.verbose_level = 0
3218+
cpplint.ProcessFileData('foo.cc', 'cc',
3219+
['const auto lambda = '
3220+
'[](const int i) { return i; };'],
3221+
error_collector)
3222+
cpplint._cpplint_state.verbose_level = old_verbose_level
3223+
self.assertEquals(0, error_collector.Results().count(
3224+
'More than one command on the same line [whitespace/newline] [0]'))
3225+
3226+
error_collector = ErrorCollector(self.assert_)
3227+
old_verbose_level = cpplint._cpplint_state.verbose_level
3228+
cpplint._cpplint_state.verbose_level = 0
3229+
cpplint.ProcessFileData('foo.cc', 'cc',
3230+
['const auto result = std::any_of(vector.begin(), '
3231+
'vector.end(), '
3232+
'[](const int i) { return i > 0; });'],
3233+
error_collector)
3234+
cpplint._cpplint_state.verbose_level = old_verbose_level
3235+
self.assertEquals(0, error_collector.Results().count(
3236+
'More than one command on the same line [whitespace/newline] [0]'))
3237+
3238+
error_collector = ErrorCollector(self.assert_)
3239+
old_verbose_level = cpplint._cpplint_state.verbose_level
3240+
cpplint._cpplint_state.verbose_level = 0
3241+
cpplint.ProcessFileData('foo.cc', 'cc',
3242+
['return mutex::Lock<void>([this]() { '
3243+
'this->ReadLock(); }, [this]() { '
3244+
'this->ReadUnlock(); });'],
3245+
error_collector)
3246+
cpplint._cpplint_state.verbose_level = old_verbose_level
3247+
self.assertEquals(0, error_collector.Results().count(
3248+
'More than one command on the same line [whitespace/newline] [0]'))
3249+
3250+
error_collector = ErrorCollector(self.assert_)
3251+
old_verbose_level = cpplint._cpplint_state.verbose_level
3252+
cpplint._cpplint_state.verbose_level = 0
3253+
cpplint.ProcessFileData('foo.cc', 'cc',
3254+
['return mutex::Lock<void>([this]() { '
3255+
'this->ReadLock(); }, [this]() { '
3256+
'this->ReadUnlock(); }, object);'],
3257+
error_collector)
3258+
cpplint._cpplint_state.verbose_level = old_verbose_level
3259+
self.assertEquals(0, error_collector.Results().count(
3260+
'More than one command on the same line [whitespace/newline] [0]'))
3261+
32143262
def testEndOfNamespaceComments(self):
32153263
error_collector = ErrorCollector(self.assert_)
32163264
cpplint.ProcessFileData('foo.cc', 'cc',

0 commit comments

Comments
 (0)