Skip to content

Updated cpplint and cppcheck to exclude directories and files#234

Merged
ahcorde merged 6 commits intoament:masterfrom
ahcorde:ahcorde/cpp_linter_exclude
May 13, 2020
Merged

Updated cpplint and cppcheck to exclude directories and files#234
ahcorde merged 6 commits intoament:masterfrom
ahcorde:ahcorde/cpp_linter_exclude

Conversation

@ahcorde
Copy link
Copy Markdown
Contributor

@ahcorde ahcorde commented Apr 30, 2020

As we discussed in this PR ros2/geometry2#258 (comment), it makes sense to exclude from cppcheck or cpplint some of the files or directories in a package.

We can use these arguments:

  • ament_cppcheck
  ament_cppcheck(LANGUAGE "c++"
    EXCLUDE_DIRS
      "include/tf2/LinearMath/* include/tf2/impl/*"
    EXCLUDE_FILES
       include/tf2/LinearMath/Scalar.h
       include/tf2/LinearMath/MinMax.h
  )
  • ament_lint
  ament_cpplint(EXCLUDE_DIRS include/tf2/LinearMath/)

Signed-off-by: ahcorde ahcorde@gmail.com

Signed-off-by: ahcorde <ahcorde@gmail.com>
@dirk-thomas
Copy link
Copy Markdown
Contributor

There is no need for two separate arguments for files and directories. Also the excluded items should be configurable in CMake when using the automatic linting (by setting a global variable) where the package doesn't involve the CMake directly and can't pass a parameter.

See other linters for reference.

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented May 1, 2020

I added language configuration to the global variables too for uncrustify and cppcheck. But I will open a PR when this is merged

@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented May 1, 2020

Right now can be used:

  set(ament_cmake_cppcheck_ADDITIONAL_EXCLUDE "include/tf2/LinearMath/*")
  set(ament_cmake_cpplint_ADDITIONAL_EXCLUDE_DIRS include/tf2/LinearMath/)
  set(ament_cmake_uncrustify_ADDITIONAL_ARGS --exclude LinearMath)

  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()

The other PR will alllow:

  set(ament_cmake_cppcheck_ADDITIONAL_LANGUAGE c++)
  set(ament_cmake_uncrustify_ADDITIONAL_LANGUAGE "C++")

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde force-pushed the ahcorde/cpp_linter_exclude branch from bcd5729 to 2c1c73c Compare May 1, 2020 11:43
@ahcorde ahcorde requested a review from dirk-thomas May 6, 2020 14:55
@ahcorde ahcorde self-assigned this May 6, 2020
@ahcorde ahcorde added the enhancement New feature or request label May 6, 2020
Copy link
Copy Markdown
Contributor

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

The options / arguments / variables seem inconsistent. Do they support only directories or also files? If both, then don't use either one in the naming.

Signed-off-by: ahcorde <ahcorde@gmail.com>
@dirk-thomas
Copy link
Copy Markdown
Contributor

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented May 8, 2020

@dirk-thomas I allowed to exclude files too.

@dirk-thomas
Copy link
Copy Markdown
Contributor

The file cpplint.py is imported from another project. Please do not modify it in this PR (since all changes are comments only).

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented May 11, 2020

Restored cpplint.py. Applied the patch in this PR #238

Copy link
Copy Markdown
Contributor

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

LGTM with passing CI.

@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented May 12, 2020

Ruuning CI up-to rclto check that linters (cppcheck, cpplint and uncrustify) are still working fine:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit d1a1bc1 into ament:master May 13, 2020
for include_dir in (args.include_dirs or []):
cmd.extend(['-I', include_dir])
for exclude in (args.exclude or []):
cmd.extend(['--suppress=*:', exclude])
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 code is wrong. This is effectively cppcheck ... --suppress=*: <exclude> ..., which appends <exclude> to the list of files to check but then ignores all checks on all files.

What you were looking for was actually cppcheck ... --suppress=*:<exclude> ... (without the space before <exclude>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants