Skip to content

Clang tidy core (v2) - #880

Merged
davetcoleman merged 12 commits into
moveit:kinetic-develfrom
BryceStevenWilley:clang-tidy-core-better-history
May 23, 2018
Merged

davetcoleman merged 12 commits into
moveit:kinetic-develfrom
BryceStevenWilley:clang-tidy-core-better-history

Conversation

@BryceStevenWilley

Copy link
Copy Markdown
Contributor

Description

(A redo of #746, which had messy history)

Extended clang-tidy from collision_detection (#693) to the rest of moveit_core. Each commit is a specific clang-tidy check, it's probably easier to browse through each commit individually.

To keep this commit manageable, I only did clang-tidy checks that included automatic/simple fixes. In the future, we should look into enabling and fixing checks like cppcoreguidelines-* (http://releases.llvm.org/3.8.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html), as those are the most likely to result in fewer segfaults and silent bugs.

Checklist

  • Required: Code is auto formatted using clang-format
  • Extended the tutorials / documentation, if necessary reference
  • Include a screenshot if changing a GUI
  • Optional: Created tests, which fail without this PR reference
  • Optional: Decide if this should be cherry-picked to other current ROS branches (Indigo, Jade, Kinetic)

@BryceStevenWilley BryceStevenWilley mentioned this pull request May 3, 2018
5 tasks done
@davetcoleman

Copy link
Copy Markdown
Member

You still have fixup! that need to be autosquashed into the history

Although I will assume we will 'Squash and merge' so I suppose it does not matter.

Comment thread .vscode/c_cpp_properties.json Outdated
@@ -0,0 +1,50 @@
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove? i don't know what this is.

Comment thread .vscode/settings.json Outdated
@@ -0,0 +1,6 @@
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mistaken IDE files. Removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

feel free to add these types of files to moveit's .gitignore

@BryceStevenWilley
BryceStevenWilley force-pushed the clang-tidy-core-better-history branch 2 times, most recently from 7c9fe42 to 0ce754b Compare May 3, 2018 01:24
@BryceStevenWilley

Copy link
Copy Markdown
Contributor Author

Should be good now. Thanks, I just learned that fixup! is actually meant to be squashed, I just though it was a convention.

@v4hn v4hn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I looked through it once more and have the same comments on auto in range-based loops, but otherwise this looks very reasonable and nice to have.

queue_change_event_(REMOVE, *it);
for (auto& event : removed)
queue_change_event_(REMOVE, event);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

huge 👍 to removing iterators&index loops.


bool satisfiesBounds(double margin = 0.0) const;
bool satisfiesBounds(const JointModelGroup* joint_group, double margin = 0.0) const;
bool satisfiesBounds(const JointModelGroup* group, double margin = 0.0) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you change the names here anyway, wouldn't it make sense to streamline this file to JointModelGroup* jmg?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is mainly about automatic changes. I wouldn't mix in such manual changes. Actually I suggest to drop these variable renamings, because there not always satisfactory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think we shouldn't be too picky about the power of clang-tidy and how much time it saves us from doing these optimizations and cleanup tasks manually...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree with rhaschke, I'll drop the readability-inconsistent-declaration-parameter-name check for now, and make another PR that will manually resolve and use the 'better' name if it comes from the header (clang-tidy defaults to using the name used in the cpp file).

Once that is finished, we can add readability-inconsistent-declaration-parameter-name back to the checks to ensure no new changes are added that use different names.

mjs.joint_names.clear();
mjs.transforms.clear();
for (std::size_t i = 0; i < js.size(); ++i)
for (auto model : js)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It took me a moment to understand that auto& would be redundant here because it's a primitive JointModel* ...

for (std::map<std::string, AttachedBody*>::const_iterator it = attached_body_map_.begin();
it != attached_body_map_.end(); ++it)
if (it->second->getAttachedLink() == lm)
for (const auto& attached : attached_body_map_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Personally, I would still prefer to keep the type in range-based for loops, especially for maps.
In this case that would be
for(const std::pair<const std::string, AttachedBody*>& attached : attached_body_map_)
... or we stay with the original.
Otherwise, the (non-trivial) type of attached.second is given in the header file only (in the definition of attached_body_map_).
Unless you use an IDE that provides this information to you automatically, this is horrible to read.

But if multiple other maintainers agree we should prefer auto in loops, I will not insist.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good point about attached.second being very hard to read, i'm ok with reverting this auto change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's true, I agree that auto in for loops is the most annoying use of auto.

Something to keep in mind is that clang-tidy doesn't gives you the option of automatically converting to for range loops without using auto. The good news is that it doesn't complain if you replace auto in an existing for loop, so manually adding the type like you suggested wouldn't be changed again.

I'll revert that commit, and in the future make a seperate PR that runs modernize-loop-convert and then follows up manually and fills in the actual types instead of auto.

@rhaschke rhaschke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Except readability-inconsistent-declaration-parameter-name and modernize-pass-by-value I approve these changes.
This PR will conflict with #882. Is there a clang-tidy command for handling namespace usage as well?

* @return
*/
IKSamplingPose(const kinematic_constraints::PositionConstraintPtr& pc);
IKSamplingPose(kinematic_constraints::PositionConstraintPtr pc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see why the const-ref is removed here. This actually avoids creating a new shared_ptr copy.
Such changes (clang-tidy:modernize-pass-by-value) should be reverted in my opinion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting, yes some of the results of that commit are surprising to me.

the std::move changes look like speed improving though.

i think we should remove that commit and discuss it in a separate PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll remove.

* @param allowed_collision_type The allowed collision type will be filled here */
bool getEntry(const std::string& name1, const std::string& name2,
AllowedCollision::Type& allowed_collision_type) const;
AllowedCollision::Type& allowed_collision) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The automatically suggested names are not always satisfactory. I suggest to drop/revert this commit for now and tackle this separately later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is not clang-tidy's fault, its a bug by the original author who has the wrong name in the .cpp file.

i think we should make the variable names more consistent. but would you be happier if the "longer" or "more descriptive" variable name was kept instead of the one in the .cpp file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know. clang-tidy cannot guess the "best" or "intended" name. That's why this type of cleanup requires manual revision and that's the reason I suggested to discuss it in a separate PR.

@BryceStevenWilley

Copy link
Copy Markdown
Contributor Author

Is there a clang-tidy command for handling namespace usage as well?

I don't think there are any relating to what y'all are doing in #882. There are some useful ones, see google-build-using-namespace and llvm-namespace-comment.

@BryceStevenWilley
BryceStevenWilley force-pushed the clang-tidy-core-better-history branch from 0ce754b to 07159db Compare May 4, 2018 01:11
@davetcoleman
davetcoleman merged commit 2f5b22b into moveit:kinetic-devel May 23, 2018
@davetcoleman

Copy link
Copy Markdown
Member

This PR needs to be merged in quick as it changes many files in a very safe way - it is auto-implementing best practices. I believe @BryceStevenWilley address @rhaschke's concerns in the last update of this PR, merging.

davetcoleman pushed a commit to davetcoleman/moveit that referenced this pull request May 23, 2018
* clang-tidy: modernize-redundant-void-arg

* clang-tidy:modernize-use-nullptr

* clang-tidy:modernize-use-default

* clang-tidy:modernize-use-override

* clang-tidy:readability-redundant-smartptr-get

* clang-tidy:readability-simplify-boolean-expr

* clang-tidy:readability-container-size-empty

* clang-tidy:readability-named-parameter

* Updated project-wide .clang-tidy with run checks.

* One last run of clang-tidy to catch the most recent changes.

* clang-format

* Added .vscode to the gitignore.
@davetcoleman

Copy link
Copy Markdown
Member

Melodic: #911

v4hn pushed a commit that referenced this pull request May 23, 2018
* clang-tidy: modernize-redundant-void-arg

* clang-tidy:modernize-use-nullptr

* clang-tidy:modernize-use-default

* clang-tidy:modernize-use-override

* clang-tidy:readability-redundant-smartptr-get

* clang-tidy:readability-simplify-boolean-expr

* clang-tidy:readability-container-size-empty

* clang-tidy:readability-named-parameter

* Updated project-wide .clang-tidy with run checks.

* One last run of clang-tidy to catch the most recent changes.

* clang-format

* Added .vscode to the gitignore.
@BryceStevenWilley
BryceStevenWilley deleted the clang-tidy-core-better-history branch May 24, 2018 04:03
dg-shadow pushed a commit to shadow-robot/moveit that referenced this pull request Jul 30, 2018
* clang-tidy: modernize-redundant-void-arg

* clang-tidy:modernize-use-nullptr

* clang-tidy:modernize-use-default

* clang-tidy:modernize-use-override

* clang-tidy:readability-redundant-smartptr-get

* clang-tidy:readability-simplify-boolean-expr

* clang-tidy:readability-container-size-empty

* clang-tidy:readability-named-parameter

* Updated project-wide .clang-tidy with run checks.

* One last run of clang-tidy to catch the most recent changes.

* clang-format

* Added .vscode to the gitignore.
@BryceStevenWilley BryceStevenWilley mentioned this pull request Nov 3, 2018
1 of 2 tasks
@RoboticsYY RoboticsYY mentioned this pull request Feb 18, 2019
1 task done
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.

4 participants