Skip to content
New issue

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

Apply clang tidy fix to entire code base (Part 1) #1366

Merged
merged 17 commits into from Feb 28, 2019

Conversation

RoboticsYY
Copy link
Contributor

@RoboticsYY RoboticsYY commented Feb 27, 2019

Description

Redo moveit#1354 for Melodic.

Since the clang-tidy fixes can involve many file changes, which makes it difficult for reviewing. The previous PR will be split into several PRs. This is the first one which contains some low risk fixes. Please note clang-tidy-3.9 is used, and there are some manual fixes to the auto clang-tidy fix, they are related to:

  • performance-unnecessary-copy-initialization may falsely convert non-const variable to const variable
  • modernize-use-nullptr may convert some unnecessary NULL and 0 to nullptr.
    • Boost function pointer initialization by nullptr seems not allowed.
    • Some NULL and 0 refer to int or enum or null Qstring, it may not be safe to replace them by nullptr.
  • readability-simplify-boolean-expr may convert if(...){...}...return... clause by return... clause. But some code cannot be ignored.

Checklist

  • Required by CI: Code is auto formatted using [clang-format]

Copy link
Contributor

@BryceStevenWilley BryceStevenWilley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that manual fixes for readability-simplify-boolean-expr aren't necessary, but that's my only sticking point for this PR. Looks good!

@@ -420,14 +420,14 @@ void DefaultCollisionsWidget::showHeaderContextMenu(const QPoint& p)
menu.addActions(header_actions_);
menu.exec(global);

clicked_headers_ = 0;
clicked_section_ = -1;
// clicked_headers_ = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this change functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the whole function pasted below, seems these two operations override the operations in the previous if...else if...else... clause, which I think is not necessary.

void DefaultCollisionsWidget::showHeaderContextMenu(const QPoint& p)
{
  // This method might be triggered from either of the headers
  QPoint global;
  if (sender() == collision_table_->verticalHeader())
  {
    clicked_section_ = collision_table_->verticalHeader()->logicalIndexAt(p);
    clicked_headers_ = Qt::Vertical;
    global = collision_table_->verticalHeader()->mapToGlobal(p);
  }
  else if (sender() == collision_table_->horizontalHeader())
  {
    clicked_section_ = collision_table_->horizontalHeader()->logicalIndexAt(p);
    clicked_headers_ = Qt::Horizontal;
    global = collision_table_->horizontalHeader()->mapToGlobal(p);
  }
  else
  {
    clicked_section_ = -1;
    clicked_headers_ = Qt::Horizontal | Qt::Vertical;
  }

  QMenu menu;
  if (clicked_section_ < 0)
    menu.addAction(header_actions_.at(0));  // only 'show' action
  else
    menu.addActions(header_actions_);
  menu.exec(global);

  // clicked_headers_ = nullptr;
  // clicked_section_ = -1;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but there are other functions in this class that don't set these values, meaning this function likely needs to end by setting them to their default values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep this PR from getting held up, i think we should err on keeping things the way they are in issues like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to keep these two lines for now. I think this is beyond a clang-tidy topic. clicked_headers_ = {} is a better option.

@@ -420,14 +420,14 @@ void DefaultCollisionsWidget::showHeaderContextMenu(const QPoint& p)
menu.addActions(header_actions_);
menu.exec(global);

clicked_headers_ = 0;
clicked_section_ = -1;
// clicked_headers_ = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to a Qt mailing list thread, you can use clicked_headers_ = {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know a better solution for this.

@@ -214,7 +214,7 @@ bool ompl_interface::StateValidityChecker::isValidWithCache(const ompl::base::St
collision_detection::CollisionResult res;
planning_context_->getPlanningScene()->checkCollision(
verbose ? collision_request_simple_verbose_ : collision_request_simple_, res, *robot_state);
if (!res.collision)
if (!res.collision) // NOLINT(readability-simplify-boolean-expr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can still be simplified though:

if (!res.collision)
{
  const_cast<ob::State*>(state)->as<ModelBasedStateSpace::StateType>()->markValid();
}
else
{
  const_cast<ob::State*>(state)->as<ModelBasedStateSpace::StateType>()->markInvalid();
}
return !res.collision;

There shouldn't be any need to mark them NOLINT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to simplify in this way!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is further simplified in the suggested way.

@@ -171,7 +171,7 @@ bool SrvKinematicsPlugin::getPositionIK(const geometry_msgs::Pose& ik_pose, cons
std::vector<double>& solution, moveit_msgs::MoveItErrorCodes& error_code,
const kinematics::KinematicsQueryOptions& options) const
{
const IKCallbackFn solution_callback = 0;
const IKCallbackFn solution_callback = 0; // NOLINT(modernize-use-nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, great idea adding the check after the NOLINT. Does clang recognize that, or is that just for documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, clang recognize this. Please see the guidelines. Maybe this should also be added to the style guidelines on MoveIt! website similar to clang-format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely should be added to the docs, I missed that fact when first doing clang-tidy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please add a new section to https://github.com/ros-planning/moveit.ros.org/blob/gh-pages/documentation/contributing/code/index.markdown documenting how to ignore some clang-tidy rules!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davetcoleman @BryceStevenWilley The exception rules of clang-tidy were added to the style guidelines in moveit.ros.org#258. Please help review.

@@ -406,7 +406,7 @@ void ompl_interface::ModelBasedPlanningContext::convertPath(const ompl::geometri
bool ompl_interface::ModelBasedPlanningContext::getSolutionPath(robot_trajectory::RobotTrajectory& traj) const
{
traj.clear();
if (!ompl_simple_setup_->haveSolutionPath())
if (!ompl_simple_setup_->haveSolutionPath()) // NOLINT(readability-simplify-boolean-expr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with these here:

if (ompl_simple_setup_->haveSolutionPath())
{
  convertPath(ompl_simple_setup_->getSolutionPath(), traj);
}
return ompl_simple_setup_->haveSolutionPath();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I would rather to keep NOLINT. Convert in this way could make it more expensive.

@@ -461,7 +461,7 @@ ompl::base::StateStoragePtr ompl_interface::ConstraintsLibrary::constructConstra

// construct the constrained states

robot_state::RobotState robot_state(default_state);
robot_state::RobotState robot_state(default_state); // NOLINT(performance-unnecessary-copy-initialization)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not compile after linting, or does it just add a bug implicitly? You're correct; this shouldn't be const. I just didn't think that clang-tidy would put the project in a state where it can't compile.

@@ -171,7 +171,7 @@ bool SrvKinematicsPlugin::getPositionIK(const geometry_msgs::Pose& ik_pose, cons
std::vector<double>& solution, moveit_msgs::MoveItErrorCodes& error_code,
const kinematics::KinematicsQueryOptions& options) const
{
const IKCallbackFn solution_callback = 0;
const IKCallbackFn solution_callback = 0; // NOLINT(modernize-use-nullptr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please add a new section to https://github.com/ros-planning/moveit.ros.org/blob/gh-pages/documentation/contributing/code/index.markdown documenting how to ignore some clang-tidy rules!

@@ -420,14 +420,14 @@ void DefaultCollisionsWidget::showHeaderContextMenu(const QPoint& p)
menu.addActions(header_actions_);
menu.exec(global);

clicked_headers_ = 0;
clicked_section_ = -1;
// clicked_headers_ = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep this PR from getting held up, i think we should err on keeping things the way they are in issues like this

@BryceStevenWilley
Copy link
Contributor

Everything looks good to me. 👍

@davetcoleman davetcoleman merged commit 822a991 into moveit:melodic-devel Feb 28, 2019
@welcome
Copy link

welcome bot commented Feb 28, 2019

Congrats on getting your first MoveIt! pull request merged and improving open source robotics!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants