We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug TooManyStatementsPerLine is shown for one-line short lambdas which I find strange.
To Reproduce Analyze code that contains lambdas. Examples: const auto get_value = [](const auto& element) noexcept { return element.second; }; std::for_each(files.begin(), files.end(), [&](const auto& i_file) { new_files.AddFile(i_file); });
const auto get_value = [](const auto& element) noexcept { return element.second; };
std::for_each(files.begin(), files.end(), [&](const auto& i_file) { new_files.AddFile(i_file); });
Expected behavior In my opinion there should be no "cxx:TooManyStatementsPerLine" code smells in such cases.
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered:
Hi @Nekto89,
easy workaround would be (looks also much more readable):
const auto get_value = [](const auto& element) noexcept { return element.second; }; std::for_each(files.begin(), files.end(), [&](const auto& i_file) { new_files.AddFile(i_file); });
The check is implemented here, maybe you can have a look to it:
sonar-cxx/cxx-checks/src/main/java/org/sonar/cxx/checks/metrics/TooManyStatementsPerLineCheck.java
Line 44 in a65a14d
sonar-cxx/cxx-squid-bridge/src/main/java/org/sonar/cxx/squidbridge/checks/AbstractOneStatementPerLineCheck.java
Line 33 in a65a14d
In the SSLR toolkit you can narrow it down. Maybe should only check inside statementSeq?
statementSeq
Regards,
Sorry, something went wrong.
How SonarSource is implementing this https://rules.sonarsource.com/cpp/RSPEC-122/
cxx unit test https://github.com/SonarOpenCommunity/sonar-cxx/blob/master/cxx-checks/src/test/java/org/sonar/cxx/checks/metrics/TooManyStatementsPerLineCheckTest.java test file https://github.com/SonarOpenCommunity/sonar-cxx/blob/master/cxx-checks/src/test/resources/checks/TooManyStatementsPerLine.cc
No branches or pull requests
Describe the bug
TooManyStatementsPerLine is shown for one-line short lambdas which I find strange.
To Reproduce
Analyze code that contains lambdas.
Examples:
const auto get_value = [](const auto& element) noexcept { return element.second; };
std::for_each(files.begin(), files.end(), [&](const auto& i_file) { new_files.AddFile(i_file); });
Expected behavior
In my opinion there should be no "cxx:TooManyStatementsPerLine" code smells in such cases.
Screenshots

Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: