Skip to content

Commit

Permalink
#2140 Add linting configuration
Browse files Browse the repository at this point in the history
The carma_cooperative_perception package now lints the code when testing
is enabled. This commit changes a lot of the existing code to satisfy
the linting requirements. Most of the changes include license header
relocation to the very top of the file, include guard name changes
according to the ROS style guide, and removing namespace
using-declarations.
  • Loading branch information
adamlm committed Sep 6, 2023
1 parent 556442a commit 3901422
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 369 deletions.
73 changes: 52 additions & 21 deletions carma_cooperative_perception/cmake/FindPROJ4.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# BSD 3-Clause License
#
# Copyright (c) 2009, Mateusz Loskot <mateusz@loskot.net>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the {copyright_holder} nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

###############################################################################
# CMake module to search for PROJ.4 library
#
Expand All @@ -16,37 +46,38 @@
#
###############################################################################

# lint_cmake: -linelength
# Reference: https://raw.githubusercontent.com/mloskot/cmake-modules/master/modules/FindPROJ4.cmake

# Try to use OSGeo4W installation
if(WIN32)
set(PROJ4_OSGEO4W_HOME "C:/OSGeo4W")
set(PROJ4_OSGEO4W_HOME "C:/OSGeo4W")

if($ENV{OSGEO4W_HOME})
set(PROJ4_OSGEO4W_HOME "$ENV{OSGEO4W_HOME}")
endif()
if($ENV{OSGEO4W_HOME})
set(PROJ4_OSGEO4W_HOME "$ENV{OSGEO4W_HOME}")
endif()
endif()

find_path(PROJ4_INCLUDE_DIR proj_api.h
PATHS ${PROJ4_OSGEO4W_HOME}/include
DOC "Path to PROJ.4 library include directory")

if (PROJ4_INCLUDE_DIR)
# Extract version from proj_api.h (ex: 480)
file(STRINGS ${PROJ4_INCLUDE_DIR}/proj_api.h
PJ_VERSIONSTR
REGEX "#define[ ]+PJ_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" PJ_VERSIONSTR ${PJ_VERSIONSTR})

# TODO: Should be formatted as 4.8.0?
set(PROJ4_VERSION ${PJ_VERSIONSTR})
PATHS ${PROJ4_OSGEO4W_HOME}/include
DOC "Path to PROJ.4 library include directory")

if(PROJ4_INCLUDE_DIR)
# Extract version from proj_api.h (ex: 480)
file(STRINGS ${PROJ4_INCLUDE_DIR}/proj_api.h
PJ_VERSIONSTR
REGEX "#define[ ]+PJ_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" PJ_VERSIONSTR ${PJ_VERSIONSTR})

# TODO: Should be formatted as 4.8.0?
set(PROJ4_VERSION ${PJ_VERSIONSTR})
endif()

set(PROJ4_NAMES ${PROJ4_NAMES} proj proj_i)
find_library(PROJ4_LIBRARY
NAMES ${PROJ4_NAMES}
PATHS ${PROJ4_OSGEO4W_HOME}/lib
DOC "Path to PROJ.4 library file")
NAMES ${PROJ4_NAMES}
PATHS ${PROJ4_OSGEO4W_HOME}/lib
DOC "Path to PROJ.4 library file")

if(PROJ4_LIBRARY)
set(PROJ4_LIBRARIES ${PROJ4_LIBRARY})
Expand All @@ -56,5 +87,5 @@ endif()
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PROJ4 DEFAULT_MSG
PROJ4_LIBRARY
PROJ4_INCLUDE_DIR)
PROJ4_LIBRARY
PROJ4_INCLUDE_DIR)
5 changes: 3 additions & 2 deletions carma_cooperative_perception/cmake/get_cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# lint_cmake: -linelength
# Reference: https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/master/cmake/get_cpm.cmake

set(CPM_DOWNLOAD_VERSION 0.38.2)
Expand All @@ -38,8 +39,8 @@ get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

Expand Down
14 changes: 14 additions & 0 deletions carma_cooperative_perception/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
include(cmake/get_cpm.cmake)
set(CPM_USE_LOCAL_PACKAGES ON)

# lint_cmake: -readability/wonkycase
CPMAddPackage(NAME units
GITHUB_REPOSITORY nholthaus/units
GIT_TAG v2.3.3
Expand All @@ -31,6 +32,7 @@ CPMAddPackage(NAME units
# version upgrade plans.
find_package(PROJ4 REQUIRED MODULE)

# lint_cmake: -readability/wonkycase
CPMAddPackage(NAME Microsoft.GSL
GITHUB_REPOSITORY microsoft/GSL
GIT_TAG v2.1.0 # This is the version shipped with Ubuntu 20.04; newer versions are available
Expand All @@ -52,4 +54,16 @@ if(carma_cooperative_perception_BUILD_TESTS)
include(cmake/ament_auto_add_gtest.cmake)

ament_auto_find_test_dependencies()

if(NOT AMENT_LINT_AUTO_EXCLUDE)
set(AMENT_LINT_AUTO_EXCLUDE "")
endif()

# Uncrustify needs some configuration tweaks to work nicely with trailing
# return types, so we are disabling it.
list(APPEND AMENT_LINT_AUTO_EXCLUDE
ament_cmake_uncrustify
)

ament_lint_auto_find_test_dependencies()
endif()
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef CARMA_COOPERATIVE_PERCEPTION_GEODETIC_HPP_
#define CARMA_COOPERATIVE_PERCEPTION_GEODETIC_HPP_

/*
* Copyright 2023 Leidos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Leidos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CARMA_COOPERATIVE_PERCEPTION__GEODETIC_HPP_
#define CARMA_COOPERATIVE_PERCEPTION__GEODETIC_HPP_

/**
* This file contains functions and helper structs to facilitate transforming
Expand Down Expand Up @@ -189,4 +187,4 @@ auto calculate_grid_convergence(const Wgs84Coordinate & position, const UtmZone

} // namespace carma_cooperative_perception

#endif // CARMA_COOPERATIVE_PERCEPTION_GEODETIC_HPP_
#endif // CARMA_COOPERATIVE_PERCEPTION__GEODETIC_HPP_
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef CARMA_COOPERATIVE_PERCEPTION_J2735_TYPES_HPP_
#define CARMA_COOPERATIVE_PERCEPTION_J2735_TYPES_HPP_

/*
* Copyright 2023 Leidos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Leidos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CARMA_COOPERATIVE_PERCEPTION__J2735_TYPES_HPP_
#define CARMA_COOPERATIVE_PERCEPTION__J2735_TYPES_HPP_

#include <units.h>

Expand Down Expand Up @@ -99,4 +97,4 @@ struct Speed

} // namespace carma_cooperative_perception

#endif // CARMA_COOPERATIVE_PERCEPTION_J2735_TYPES_HPP_
#endif // CARMA_COOPERATIVE_PERCEPTION__J2735_TYPES_HPP_
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef CARMA_COOPERATIVE_PERCEPTION_J3224_TYPES_HPP_
#define CARMA_COOPERATIVE_PERCEPTION_J3224_TYPES_HPP_

/*
* Copyright 2023 Leidos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Leidos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CARMA_COOPERATIVE_PERCEPTION__J3224_TYPES_HPP_
#define CARMA_COOPERATIVE_PERCEPTION__J3224_TYPES_HPP_

#include <units.h>

Expand Down Expand Up @@ -54,4 +52,4 @@ struct MeasurementTimeOffset

} // namespace carma_cooperative_perception

#endif // CARMA_COOPERATIVE_PERCEPTION_J3224_TYPES_HPP_
#endif // CARMA_COOPERATIVE_PERCEPTION__J3224_TYPES_HPP_
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef CARMA_COOPERATIVE_PERCEPTION_MONTH_HPP_
#define CARMA_COOPERATIVE_PERCEPTION_MONTH_HPP_

/*
* Copyright 2023 Leidos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Leidos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CARMA_COOPERATIVE_PERCEPTION__MONTH_HPP_
#define CARMA_COOPERATIVE_PERCEPTION__MONTH_HPP_

/**
* This file contains a Month class implementation that should be source-compatible
Expand Down Expand Up @@ -239,4 +237,4 @@ inline constexpr Month December{12};

} // namespace carma_cooperative_perception

#endif // CARMA_COOPERATIVE_PERCEPTION_MONTH_HPP_
#endif // CARMA_COOPERATIVE_PERCEPTION__MONTH_HPP_
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#ifndef CARMA_COOPERATIVE_PERCEPTION_MSG_CONVERSION_HPP_
#define CARMA_COOPERATIVE_PERCEPTION_MSG_CONVERSION_HPP_

/*
* Copyright 2023 Leidos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Leidos
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_
#define CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_

#include <units.h>

Expand Down Expand Up @@ -43,4 +41,4 @@ auto to_detection_list_msg(const carma_v2x_msgs::msg::SensorDataSharingMessage &

} // namespace carma_cooperative_perception

#endif // CARMA_COOPERATIVE_PERCEPTION_MSG_CONVERSION_HPP_
#endif // CARMA_COOPERATIVE_PERCEPTION__MSG_CONVERSION_HPP_
Loading

0 comments on commit 3901422

Please sign in to comment.