Skip to content

Commit 9dd5a9a

Browse files
committed
Add ament{_cmake,}_yamllint packages
The yamllint tool is widely used to validate YAML style. This change adds ament_lint support for that tool. At present, the ament_lint_auto glue for ament_cmake_yamllint is omitted. We'll need to clean up all of the violations across the codebase before we can enable it automatically. For now, having the tool available may help us prevent further regressions. Signed-off-by: Scott K Logan <[email protected]>
1 parent d502e7b commit 9dd5a9a

20 files changed

+680
-0
lines changed

ament_cmake_yamllint/CHANGELOG.rst

Whitespace-only changes.

ament_cmake_yamllint/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(ament_cmake_yamlint NONE)
4+
5+
find_package(ament_cmake_core REQUIRED)
6+
find_package(ament_cmake_test REQUIRED)
7+
8+
install(
9+
DIRECTORY cmake
10+
DESTINATION share/${PROJECT_NAME}
11+
)
12+
13+
if(BUILD_TESTING)
14+
find_package(ament_cmake_copyright REQUIRED)
15+
ament_copyright()
16+
17+
find_package(ament_cmake_lint_cmake REQUIRED)
18+
ament_lint_cmake()
19+
20+
find_package(ament_cmake_xmllint REQUIRED)
21+
ament_xmllint()
22+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2014-2018 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#
16+
# Add a test to check YAML files with yamllint.
17+
#
18+
# :param TESTNAME: the name of the test, default: "yamllint"
19+
# :type TESTNAME: string
20+
# :param ARGN: the files or directories to check
21+
# :type ARGN: list of strings
22+
#
23+
# @public
24+
#
25+
function(ament_yamllint)
26+
cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "" ${ARGN})
27+
if(NOT ARG_TESTNAME)
28+
set(ARG_TESTNAME "yamllint")
29+
endif()
30+
31+
find_program(ament_yamllint_BIN NAMES "ament_yamllint")
32+
if(NOT ament_yamllint_BIN)
33+
message(FATAL_ERROR "ament_yamllint() could not find program 'ament_yamllint'")
34+
endif()
35+
36+
set(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${ARG_TESTNAME}.xunit.xml")
37+
set(cmd "${ament_yamllint_BIN}" "--xunit-file" "${result_file}")
38+
list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS})
39+
40+
find_program(yamllint_BIN NAMES "yamllint")
41+
42+
if(NOT yamllint_BIN)
43+
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
44+
message(WARNING "WARNING: 'yamllint' not found, skipping yamllint test creation")
45+
return()
46+
endif()
47+
endif()
48+
49+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_yamllint")
50+
ament_add_test(
51+
"${ARG_TESTNAME}"
52+
COMMAND ${cmd}
53+
OUTPUT_FILE "${CMAKE_BINARY_DIR}/ament_yamllint/${ARG_TESTNAME}.txt"
54+
RESULT_FILE "${result_file}"
55+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
56+
)
57+
set_tests_properties(
58+
"${ARG_TESTNAME}"
59+
PROPERTIES
60+
LABELS "yamllint;linter"
61+
)
62+
if(NOT yamllint_BIN)
63+
set_tests_properties(
64+
"${ARG_TESTNAME}"
65+
PROPERTIES
66+
DISABLED TRUE
67+
)
68+
endif()
69+
endfunction()

ament_cmake_yamllint/doc/index.rst

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
ament_yamllint
2+
==============
3+
4+
Checks YAML files using `yamllint <https://yamllint.readthedocs.io>`_.
5+
Files with the following extensions are being considered: ``.yaml``, ``.yml``.
6+
7+
8+
How to run the check from the command line?
9+
-------------------------------------------
10+
11+
The command line tool is provided by the package `ament_yamllint
12+
<https://github.com/ament/ament_lint>`_.
13+
14+
15+
How to run the check from within a CMake ament package as part of the tests?
16+
----------------------------------------------------------------------------
17+
18+
``package.xml``:
19+
20+
.. code:: xml
21+
22+
<buildtool_depend>ament_cmake</buildtool_depend>
23+
<test_depend>ament_cmake_yamllint</test_depend>
24+
25+
``CMakeLists.txt``:
26+
27+
.. code:: cmake
28+
29+
find_package(ament_cmake REQUIRED)
30+
if(BUILD_TESTING)
31+
find_package(ament_cmake_yamllint REQUIRED)
32+
ament_yamllint()
33+
endif()
34+
35+
The documentation of the package `ament_cmake_test
36+
<https://github.com/ament/ament_cmake>`_ provides more information on testing
37+
in CMake ament packages.

ament_cmake_yamllint/package.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="2">
4+
<name>ament_cmake_yamllint</name>
5+
<version>0.11.3</version>
6+
<description>
7+
The CMake API for ament_yamllint to check YAML file using yamllint.
8+
</description>
9+
10+
<maintainer email="[email protected]">Michael Jeronimo</maintainer>
11+
<maintainer email="[email protected]">Michel Hidalgo</maintainer>
12+
13+
<license>Apache License 2.0</license>
14+
15+
<author email="[email protected]">Scott K Logan</author>
16+
17+
<buildtool_depend>ament_cmake_core</buildtool_depend>
18+
<buildtool_depend>ament_cmake_test</buildtool_depend>
19+
20+
<buildtool_export_depend>ament_cmake_test</buildtool_export_depend>
21+
<buildtool_export_depend>ament_yamllint</buildtool_export_depend>
22+
23+
<test_depend>ament_cmake_copyright</test_depend>
24+
<test_depend>ament_cmake_lint_cmake</test_depend>
25+
<test_depend>ament_cmake_xmllint</test_depend>
26+
27+
<export>
28+
<build_type>ament_cmake</build_type>
29+
</export>
30+
</package>

ament_yamllint/CHANGELOG.rst

Whitespace-only changes.

ament_yamllint/ament_yamllint/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
document-start: disable
6+
indentation:
7+
indent-sequences: consistent
8+
line-length: disable
9+
new-lines: disable

0 commit comments

Comments
 (0)