-
Notifications
You must be signed in to change notification settings - Fork 580
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
Add new clang-tidy style rules #2177
Add new clang-tidy style rules #2177
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2177 +/- ##
==========================================
- Coverage 50.78% 50.77% -0.01%
==========================================
Files 392 392
Lines 32125 32125
==========================================
- Hits 16313 16307 -6
- Misses 15812 15818 +6
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readability-static-definition-in-anonymous-namespace
is a good check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ROS cpp style guide discourages using static members.
Discouraging doesn't mean that static members are not allowed meaningful.
If you do want to share information across multiple instances of a class, a static member is the way to go. For sure, you then need to handle synchronization issues in multi-threaded environments.
Should we try to remove static class members rather than adding an explicit naming convention for them and do we want to introduce a global naming convention for static variables?
I strongly advise not to do this! As far as I know, MoveIt only sparsely uses static members - if they are needed.
Most usages are const static
, which don't pose sync issues anyway.
Furthermore, the introduced naming rule for free functions diverges from the ROS style guidelines. Do we want that or should this rule be changed to camelBack?
Why, in first place, you want to change free functions to lower_case
style? This will invalidate all existing free functions, thus also breaking API.
Note, that clang-tidy runs on code changes only by default. Thus changes to the .clang-tidy
config file do not automatically trigger a check of the whole code base w.r.t. these new rules.
You're right, we should probably exclude these exceptions from the clang-tidy check 👍 . What do you think about adding a dedicated naming convention for static variables like
It is not about changing but unifying sometimes we use lower_case (here or here) sometimes upperCase (here or here). I don't have a strong opinion about which rule to enforce (maybe
I am aware of that but thanks for the hint! What is the best way to run the checks globally once to enforce a new (and probably existing ones too 😅 ) rule everywhere? |
Just a note on using snake case vs camel case. The ROS wiki does not apply to ROS 2 anymore and pretty much all of ROS core is using snake case to basically follow what the C++ std library is doing. There is a note on that in the ROS 2 docs. I don't really have a strong opinion on which version is better, but we should certainly be consistent about it, and it would probably not be wrong to be consistent with the ROS 2 ecosystem and the std libs that we use. Also, this is pretty funny (from ROS 2 docs):
... on static members: |
Our existing style rules (at least for MoveIt 1) enforced camelCase function names. The source locations you pointed out using snake_case, @sjahr, where only recently added to MoveIt (one of them by you)! I fully agree of being consistent. But just change all wrong spelling to camelCase 😉
Manually trigger the job on github. That's at least what I configured for MoveIt1 several years ago.
@sjahr raised exactly that question in his original post. And I argued strongly against it. Meanwhile, the wording was changed from "remove" to "avoid" static members. |
I'm not aware of the technical details, but somehow the CI pipeline is telling clang-tidy to only run on whatever files changed in a given PR which means that changes to only .clang-tidy result in clang-tidy simply not being re-ran. Is there any way to make a special rule that any changes to .clang-tidy results in clang-tidy being ran across the entire codebase? It's simply not viable to change the .clang-tidy file if you don't re-run clang-tidy across the entire codebase to see the impact of the new rules. |
- key: readability-identifier-naming.StaticVariableCasePrefix | ||
value: 's_' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add prefixes or suffixes to variable names. Marking static variables via UPPER_CASE should be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the case where the static variable is mutable and not a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, we just had lower_case
names for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our conclusion in the maintainer meeting was that we'd like to mark mutable static variables due to their impact on thread safety. Having a unique naming rule will give them more visibility for reviewers and developers. However, there was no strong preference for a specific naming rule. What would be your reasoning against a unique naming rule and if you don't have any objections, which naming convention would you prefere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to mark mutable static variables, using a prefix s_
is probably the way to go. Note that this will require many code changes, which all should be part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that, generally, we don't use mutable static variables except in some generic code for edge cases. I don't know if that is true though :/
This PR is stale because it has been open for 45 days with no activity. Please tag a maintainer for help on completing this PR, or close it if you think it has become obsolete. |
This pull request is in conflict. Could you fix it @sjahr? |
@sjahr do you plan on picking back up this work? I'm sorry this got stale. |
0948c35
to
8f1caae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay snakeCase
, maybe over time I'll learn to like it
(cherry picked from commit 63e0c3a) # Conflicts: # moveit_core/planning_request_adapter/src/planning_request_adapter.cpp # moveit_core/robot_state/test/robot_state_jacobian_benchmark.cpp # moveit_core/robot_state/test/robot_state_test.cpp # moveit_core/robot_trajectory/include/moveit/robot_trajectory/robot_trajectory.h # moveit_core/robot_trajectory/src/robot_trajectory.cpp # moveit_core/robot_trajectory/test/test_robot_trajectory.cpp # moveit_core/utils/include/moveit/utils/logger.hpp # moveit_core/utils/src/logger.cpp # moveit_core/utils/test/logger_dut.cpp # moveit_core/utils/test/logger_from_child_dut.cpp # moveit_ros/perception/mesh_filter/include/moveit/mesh_filter/gl_renderer.h # moveit_ros/perception/mesh_filter/src/gl_renderer.cpp # moveit_ros/warehouse/src/broadcast.cpp # moveit_ros/warehouse/src/constraints_storage.cpp # moveit_ros/warehouse/src/import_from_text.cpp # moveit_ros/warehouse/src/initialize_demo_db.cpp # moveit_ros/warehouse/src/planning_scene_storage.cpp # moveit_ros/warehouse/src/planning_scene_world_storage.cpp # moveit_ros/warehouse/src/save_as_text.cpp # moveit_ros/warehouse/src/save_to_warehouse.cpp # moveit_ros/warehouse/src/state_storage.cpp # moveit_ros/warehouse/src/trajectory_constraints_storage.cpp # moveit_ros/warehouse/src/warehouse_connector.cpp # moveit_ros/warehouse/src/warehouse_services.cpp
Description
As discussed in our previous standup some additional style guidelines. I've added new rules for const member variables and functions in general + an additional check for static variables in anonymous namespaces. However, I did not come up with a good solution to the problem that initiated this discussion: static member variables.
According to the documentation there are rules for the
StaticConstCase
and theStaticVariableCase
but not specifically for the static member case (right now they are subject to the private/protected member naming conventions). The ROS cpp style guide even discourages using static members in the first place.Should we try to
removeavoid static class members rather than adding an explicit naming convention for them and do we want to introduce a global naming convention for static variables?Furthermore, the introduced naming rule for free functions diverges from the ROS style guidelines. Do we want that or should this rule be changed to camelBack?
Checklist