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

refactor(gnss_poser): apply static analysis #7874

Merged

Conversation

a-maumau
Copy link
Contributor

@a-maumau a-maumau commented Jul 5, 2024

Description

This PR applies some suggestions from the linter to sensing/gnss_poser.
Checked with clang-tidy and cppcheck.

Fixed:

  • use explicit cast
  • change variable names
    • camelCase to snake_case for variable
    • add _ to private variable
  • change function/method
    • camelCase to snake_case
    • add keyword to function/method which linter suggested

Related links

Parent Issue:

  • Link

How was this PR tested?

Checked with clang-tidy (v14.0.0) and cppcheck (v2.14.1)

check_linter.sh
#!/bin/bash
set -eux

TARGET_DIR=$1

current_dir=$(basename $(pwd))
if [[ ! $current_dir =~ ^(autoware|pilot-auto) ]]; then
    echo "This script must be run in a directory with a prefix of autoware or pilot-auto."
    exit 1
fi

set +eux
export CPLUS_INCLUDE_PATH=/usr/include/c++/11:/usr/include/x86_64-linux-gnu/c++/11:$CPLUS_INCLUDE_PATH
set -eux

fdfind -e cpp -e hpp --full-path ${TARGET_DIR} | xargs -P $(nproc) -I{} cpplint {}
fdfind -e cpp -e hpp --full-path ${TARGET_DIR} | xargs -P $(nproc) -I{} clang-tidy -p build/ {}

Before fixing the code:

Check with check_linter.sh
$ ./check_linter.sh gnss_poser
...
19756 warnings generated.
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:52:8: warning: invalid case style for function 'callbackMapProjectorInfo' [readability-identifier-naming]
  void callbackMapProjectorInfo(const MapProjectorInfo::Message::ConstSharedPtr msg);
       ^~~~~~~~~~~~~~~~~~~~~~~~
       callback_map_projector_info
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:53:8: warning: invalid case style for function 'callbackNavSatFix' [readability-identifier-naming]
  void callbackNavSatFix(const sensor_msgs::msg::NavSatFix::ConstSharedPtr nav_sat_fix_msg_ptr);
       ^~~~~~~~~~~~~~~~~
       callback_nav_sat_fix
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:54:8: warning: invalid case style for function 'callbackGnssInsOrientationStamped' [readability-identifier-naming]
  void callbackGnssInsOrientationStamped(
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       callback_gnss_ins_orientation_stamped
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:57:8: warning: invalid case style for function 'isFixed' [readability-identifier-naming]
  bool isFixed(const sensor_msgs::msg::NavSatStatus & nav_sat_status_msg);
       ^~~~~~~
       is_fixed
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:58:8: warning: invalid case style for function 'canGetCovariance' [readability-identifier-naming]
  bool canGetCovariance(const sensor_msgs::msg::NavSatFix & nav_sat_fix_msg);
       ^~~~~~~~~~~~~~~~
       can_get_covariance
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:59:29: warning: invalid case style for function 'getMedianPosition' [readability-identifier-naming]
  geometry_msgs::msg::Point getMedianPosition(
                            ^~~~~~~~~~~~~~~~~
                            get_median_position
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:61:29: warning: invalid case style for function 'getAveragePosition' [readability-identifier-naming]
  geometry_msgs::msg::Point getAveragePosition(
                            ^~~~~~~~~~~~~~~~~~
                            get_average_position
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:63:34: warning: invalid case style for function 'getQuaternionByHeading' [readability-identifier-naming]
  geometry_msgs::msg::Quaternion getQuaternionByHeading(const int heading);
                                 ^~~~~~~~~~~~~~~~~~~~~~
                                 get_quaternion_by_heading
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:64:34: warning: invalid case style for function 'getQuaternionByPositionDifference' [readability-identifier-naming]
  geometry_msgs::msg::Quaternion getQuaternionByPositionDifference(
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 get_quaternion_by_position_difference
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:67:8: warning: invalid case style for function 'getTransform' [readability-identifier-naming]
  bool getTransform(
       ^~~~~~~~~~~~
       get_transform
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:70:8: warning: invalid case style for function 'getStaticTransform' [readability-identifier-naming]
  bool getStaticTransform(
       ^~~~~~~~~~~~~~~~~~
       get_static_transform
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:74:8: warning: invalid case style for function 'publishTF' [readability-identifier-naming]
  void publishTF(
       ^~~~~~~~~
       publish_tf
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/include/gnss_poser/gnss_poser_core.hpp:102:7: warning: invalid case style for private member 'gnss_pose_pub_method' [readability-identifier-naming]
  int gnss_pose_pub_method;
      ^~~~~~~~~~~~~~~~~~~~
      gnss_pose_pub_method_
Suppressed 19754 warnings (19743 in non-user code, 11 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
25632 warnings generated.
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:39:24: warning: narrowing conversion from 'long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
  gnss_pose_pub_method(declare_parameter<int>("gnss_pose_pub_method"))
                       ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:48:20: warning: narrowing conversion from 'long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
  int buff_epoch = declare_parameter<int>("buff_epoch");
                   ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:213:17: warning: method 'isFixed' can be made static [readability-convert-member-functions-to-static]
bool GNSSPoser::isFixed(const sensor_msgs::msg::NavSatStatus & nav_sat_status_msg)
                ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:218:17: warning: method 'canGetCovariance' can be made static [readability-convert-member-functions-to-static]
bool GNSSPoser::canGetCovariance(const sensor_msgs::msg::NavSatFix & nav_sat_fix_msg)
                ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:224:38: warning: method 'getMedianPosition' can be made static [readability-convert-member-functions-to-static]
geometry_msgs::msg::Point GNSSPoser::getMedianPosition(
                                     ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:227:8: warning: invalid case style for variable 'getMedian' [readability-identifier-naming]
  auto getMedian = [](std::vector<double> array) {
       ^~~~~~~~~
       get_median
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:252:38: warning: method 'getAveragePosition' can be made static [readability-convert-member-functions-to-static]
geometry_msgs::msg::Point GNSSPoser::getAveragePosition(
                                     ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:274:43: warning: method 'getQuaternionByHeading' can be made static [readability-convert-member-functions-to-static]
geometry_msgs::msg::Quaternion GNSSPoser::getQuaternionByHeading(const int heading)
                                          ^
/home/masakibaba/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:291:43: warning: method 'getQuaternionByPositionDifference' can be made static [readability-convert-member-functions-to-static]
geometry_msgs::msg::Quaternion GNSSPoser::getQuaternionByPositionDifference(
                                          ^
Suppressed 25634 warnings (25623 in non-user code, 11 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Check with cppcheck: (nothing to change)


After this PR:

Check with check_linter.sh
$ ./check_linter.sh gnss_poser
...
19743 warnings generated.
Suppressed 19754 warnings (19743 in non-user code, 11 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
25610 warnings generated.
Suppressed 25621 warnings (25610 in non-user code, 11 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
@github-actions github-actions bot added the component:sensing Data acquisition from sensors, drivers, preprocessing. (auto-assigned) label Jul 5, 2024
Copy link

github-actions bot commented Jul 5, 2024

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@KYabuuchi KYabuuchi added tag:run-clang-tidy-differential run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) labels Jul 5, 2024
Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.

Project coverage is 28.67%. Comparing base (93a6abf) to head (6be2885).
Report is 42 commits behind head on main.

Files Patch % Lines
sensing/gnss_poser/src/gnss_poser_core.cpp 0.00% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7874      +/-   ##
==========================================
- Coverage   28.68%   28.67%   -0.01%     
==========================================
  Files        1587     1589       +2     
  Lines      116303   116318      +15     
  Branches    49656    49656              
==========================================
  Hits        33356    33356              
- Misses      73868    73883      +15     
  Partials     9079     9079              
Flag Coverage Δ *Carryforward flag
differential 0.00% <0.00%> (?)
total 28.68% <ø> (+<0.01%) ⬆️ Carriedforward from 93a6abf

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@KYabuuchi KYabuuchi left a comment

Choose a reason for hiding this comment

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

Thank you for your refactoring 😄
I have confirmed that gnss_poser works as before in logging_simualtor.

Looks Good To Me.

@KYabuuchi KYabuuchi merged commit e1cd1da into autowarefoundation:main Jul 8, 2024
47 of 48 checks passed
kyoichi-sugahara pushed a commit to kyoichi-sugahara/autoware.universe that referenced this pull request Jul 8, 2024
* refactor based on linter

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>

* style(pre-commit): autofix

---------

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
palas21 pushed a commit to palas21/autoware.universe that referenced this pull request Jul 12, 2024
* refactor based on linter

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>

* style(pre-commit): autofix

---------

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: palas21 <palas21@itu.edu.tr>
KhalilSelyan pushed a commit that referenced this pull request Jul 22, 2024
* refactor based on linter

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>

* style(pre-commit): autofix

---------

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Ariiees pushed a commit to Ariiees/autoware.universe that referenced this pull request Jul 22, 2024
* refactor based on linter

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>

* style(pre-commit): autofix

---------

Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@a-maumau a-maumau deleted the mau/refactor/sensing/gnss_poser branch August 1, 2024 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:sensing Data acquisition from sensors, drivers, preprocessing. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants