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(localization_util): apply static analysis #7399

Conversation

a-maumau
Copy link
Contributor

@a-maumau a-maumau commented Jun 10, 2024

Description

This PR applies some suggestions from the linter to localization/localization_util.

Fixed:

  • remove meaningless conditions
  • (removed unused codes in test)

the notion "style: Variable 'ex' can be..." from cppcheck is fixed in #7278

Tests performed

Checked with clang-tidy 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:

output from above commands
$ ./check_linter.sh localization_util
...
9505 warnings generated.
Suppressed 9507 warnings (9505 in non-user code, 2 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
30971 warnings generated.
30906 warnings generated.
Suppressed 30919 warnings (30906 in non-user code, 13 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
31734 warnings generated.
Suppressed 31747 warnings (31734 in non-user code, 13 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
30933 warnings generated.
Suppressed 30946 warnings (30933 in non-user code, 13 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
32362 warnings generated.
Suppressed 32396 warnings (32362 in non-user code, 34 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
61942 warnings generated.
Suppressed 61968 warnings (61942 in non-user code, 26 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:

output
$cppcheck --enable=warning --enable=style --enable=performance --enable=portability --enable=unusedFunction --inconclusive --check-level=exhaustive . -I ../ndt_scan_matcher/src/*

Checking src/smart_pose_buffer.cpp ...
1/6 files checked 6% done
Checking src/util_func.cpp ...
src/util_func.cpp:31:16: style: Condition 'x>0.25' is always true [knownConditionTrueFalse]
  } else if (x > 0.25 && x <= 0.5) {
               ^
src/util_func.cpp:27:9: note: Assuming condition 'x<=0.25' is false
  if (x <= 0.25) {
        ^
src/util_func.cpp:31:16: note: Condition 'x>0.25' is always true
  } else if (x > 0.25 && x <= 0.5) {
               ^
2/6 files checked 17% done
Checking test/test_smart_pose_buffer.cpp ...
3/6 files checked 22% done
Checking ../ndt_scan_matcher/src/map_update_module.cpp ...
4/6 files checked 35% done
Checking ../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp ...
../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp:647:38: style: Variable 'ex' can be declared as reference to const [constVariableReference]
  } catch (tf2::TransformException & ex) {
                                     ^
Checking ../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp: ROS_DISTRO_GALACTIC...
5/6 files checked 96% done
Checking ../ndt_scan_matcher/src/particle.cpp ...
6/6 files checked 100% done
test/test_smart_pose_buffer.cpp:48:0: style: The function 'SetUp' is never used. [unusedFunction]
  void SetUp() override {}
^
test/test_smart_pose_buffer.cpp:50:0: style: The function 'TearDown' is never used. [unusedFunction]
  void TearDown() override {}

After this PR:

Check with check_linter.sh (no change)

Check with cppcheck:

cppcheck --enable=warning --enable=style --enable=performance --enable=portability --enable=unusedFunction --inconclusive --check-level=exhaustive . -I ../ndt_scan_matcher/src/*

Checking src/smart_pose_buffer.cpp ...
1/6 files checked 6% done
Checking src/util_func.cpp ...
2/6 files checked 17% done
Checking test/test_smart_pose_buffer.cpp ...
3/6 files checked 22% done
Checking ../ndt_scan_matcher/src/map_update_module.cpp ...
4/6 files checked 34% done
Checking ../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp ...
../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp:647:38: style: Variable 'ex' can be declared as reference to const [constVariableReference]
  } catch (tf2::TransformException & ex) {
                                     ^
Checking ../ndt_scan_matcher/src/ndt_scan_matcher_core.cpp: ROS_DISTRO_GALACTIC...
5/6 files checked 96% done
Checking ../ndt_scan_matcher/src/particle.cpp ...
6/6 files checked 100% done

Effects on system behavior

Not applicable.

Interface changes

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.

After all checkboxes are checked, anyone who has write access can merge the PR.

@github-actions github-actions bot added the component:localization Vehicle's position determination in its environment. (auto-assigned) label Jun 10, 2024
Signed-off-by: a-maumau <[email protected]>
@SakodaShintaro SakodaShintaro added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Jun 10, 2024
Copy link
Contributor

@SakodaShintaro SakodaShintaro left a comment

Choose a reason for hiding this comment

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

Thanks!
Looks Good To Me

@SakodaShintaro SakodaShintaro merged commit 210513d into autowarefoundation:main Jun 10, 2024
38 checks passed
KhalilSelyan pushed a commit that referenced this pull request Jul 22, 2024
* refactor based on linter

Signed-off-by: a-maumau <[email protected]>

* style(pre-commit): autofix

* apply suggestion

Signed-off-by: a-maumau <[email protected]>

---------

Signed-off-by: a-maumau <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@a-maumau a-maumau deleted the mau/refactor/localization/localization_util 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:localization Vehicle's position determination in its environment. (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