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

Add flake8 linter ignore support #424

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ament_cmake_flake8/cmake/ament_cmake_flake8_lint_hook.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
file(GLOB_RECURSE _python_files FOLLOW_SYMLINKS "*.py")
if(_python_files)
message(STATUS "Added test 'flake8' to check Python code syntax and style conventions")
ament_flake8()
message(STATUS "Configured 'flake8' exclude dirs and/or files: ${AMENT_LINT_AUTO_FILE_EXCLUDE}")
ament_flake8(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE})
endif()
8 changes: 6 additions & 2 deletions ament_cmake_flake8/cmake/ament_flake8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
# :param MAX_LINE_LENGTH: override the maximum line length,
# the default is defined in ament_flake8
# :type MAX_LINE_LENGTH: integer
# :param EXCLUDE: an optional list of exclude directories or files for flake8
# :type EXCLUDE: list
# :param ARGN: the files or directories to check
# :type ARGN: list of strings
#
# @public
#
function(ament_flake8)
cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME;CONFIG_FILE" "" ${ARGN})
cmake_parse_arguments(ARG "" "EXCLUDE;MAX_LINE_LENGTH;TESTNAME;CONFIG_FILE" "" ${ARGN})
if(NOT ARG_TESTNAME)
set(ARG_TESTNAME "flake8")
endif()
Expand All @@ -57,7 +59,9 @@ function(ament_flake8)
if(ARG_MAX_LINE_LENGTH)
list(APPEND cmd "--linelength" "${ARG_MAX_LINE_LENGTH}")
endif()
list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS})
if(ARG_EXCLUDE)
list(APPEND cmd "--exclude" "${ARG_EXCLUDE}")
endif()
RFRIEDM-Trimble marked this conversation as resolved.
Show resolved Hide resolved

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_flake8")
ament_add_test(
Expand Down
21 changes: 20 additions & 1 deletion ament_lint_auto/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ in CMake ament packages.
How to exclude files with ament_lint_auto?
------------------------------------------

Linter hooks conform to the ament_lint_auto convention of excluding files
Linter hooks shall conform to the ament_lint_auto convention of excluding files
specified in the CMake list variable `AMENT_LINT_AUTO_FILE_EXCLUDE`.
As such, the CMake snippet from above can be modified to exclude files across
all linters with one addition.
Expand All @@ -62,3 +62,22 @@ all linters with one addition.
set(AMENT_LINT_AUTO_FILE_EXCLUDE /path/to/ignored_file ...)
ament_lint_auto_find_test_dependencies()
endif()

For a more specific example, this excludes all python files matching a pattern using globbing.
Multiple expressions can be combined on multiple lines.
It might be a good idea to issue a warning to developers that linting is disabled
if you plan to enable it at some point.

.. code:: cmake

file(GLOB_RECURSE AMENT_LINT_AUTO_FILE_EXCLUDE
# Exclude all the python files in src directory
src/*.py
# Exclude all the c++ implementation files in test directory
test/*.cpp
)
message(AUTHOR_WARNING
"Ament lint auto tests are disabled on the following: "
${AMENT_LINT_AUTO_FILE_EXCLUDE}
)