Skip to content

Commit c07021f

Browse files
authored
Add pre-commit (#5)
* add claude support in devcontainer * pre-commit
1 parent 26283a4 commit c07021f

File tree

25 files changed

+1147
-662
lines changed

25 files changed

+1147
-662
lines changed

.cpplint.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Because of cpplint's config file assumptions, this can't be contained in .config/ directory
2+
linelength=256
3+
4+
filter=-legal/copyright
5+
filter=-build/header_guard
6+
filter=-build/c++17
7+
8+
# Disable all formatting checks, this is handled by clang-format
9+
filter=-readability/braces
10+
filter=-whitespace/braces
11+
filter=-whitespace/indent
12+
filter=-whitespace/newline
13+
filter=-whitespace/parens
14+
filter=-whitespace/semicolon

.devcontainer/Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22
ARG ROS_DISTRO=humble
33
FROM ros:${ROS_DISTRO}-ros-base
44

5-
# Install only essential ROS development tools not in base image
6-
RUN apt-get update && apt-get install -y \
5+
# Install development tools not in base image
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
python3-pip \
78
python3-colcon-common-extensions \
89
python3-rosdep \
910
openssh-client \
1011
curl \
1112
&& rm -rf /var/lib/apt/lists/*
1213

14+
# Install pre-commit
15+
RUN python3 -m pip install --no-cache-dir pre-commit==3.8.0
16+
1317
# Install Node.js 20 LTS (required for Claude Code)
18+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1419
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
15-
apt-get install -y nodejs && \
20+
apt-get install -y --no-install-recommends nodejs && \
1621
rm -rf /var/lib/apt/lists/*
1722

1823
# Install Claude Code CLI via npm
19-
RUN npm install -g @anthropic-ai/claude-code
24+
RUN npm install -g @anthropic-ai/claude-code@1.0.0
2025

2126
# Initialize rosdep
2227
RUN rosdep init || true
@@ -29,16 +34,18 @@ ARG USERNAME
2934

3035
SHELL ["/bin/bash", "-c"]
3136
COPY .env /tmp/.env
37+
# hadolint ignore=SC2086
3238
RUN source /tmp/.env && rm /tmp/.env \
3339
&& groupadd --gid $USER_GID $USERNAME \
3440
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/bash \
3541
&& apt-get update \
36-
&& apt-get install -y sudo \
42+
&& apt-get install -y --no-install-recommends sudo \
3743
&& echo $USERNAME ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
3844
&& chmod 0440 /etc/sudoers.d/$USERNAME \
3945
&& cp /etc/skel/.bashrc /home/$USERNAME/.bashrc \
4046
&& cp /etc/skel/.profile /home/$USERNAME/.profile \
41-
&& chown $USERNAME:$USERNAME /home/$USERNAME/.bashrc /home/$USERNAME/.profile
47+
&& chown $USERNAME:$USERNAME /home/$USERNAME/.bashrc /home/$USERNAME/.profile \
48+
&& rm -rf /var/lib/apt/lists/*
4249

4350
# Set the default user. Omit if you want to keep the default as root.
4451
USER $USERNAME

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@
2828
"workspaceFolder": "/deep_ros_ws",
2929
"workspaceMount": "source=${localWorkspaceFolder},target=/deep_ros_ws,type=bind",
3030
"containerName": "deep-ros-devcontainer",
31-
"runArgs": ["--hostname=deep-devcontainer"]
31+
"runArgs": [
32+
"--hostname=deep-devcontainer"
33+
]
3234
}

.devcontainer/gen_env.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#!/bin/bash
22

3+
# Copyright (c) 2025-present WATonomous. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
316
set -e
417

518
# Check if ROS_DISTRO was provided as argument
@@ -12,10 +25,12 @@ ROS_DISTRO="$1"
1225
ENV_FILE=".devcontainer/.env"
1326

1427
echo "Generating $ENV_FILE ..."
15-
echo "USER=$(whoami)" > "$ENV_FILE"
16-
echo "USER_UID=$(id -u)" >> "$ENV_FILE"
17-
echo "USER_GID=$(id -g)" >> "$ENV_FILE"
18-
echo "ROS_DISTRO=$ROS_DISTRO" >> "$ENV_FILE"
28+
{
29+
echo "USER=$(whoami)"
30+
echo "USER_UID=$(id -u)"
31+
echo "USER_GID=$(id -g)"
32+
echo "ROS_DISTRO=$ROS_DISTRO"
33+
} >> "$ENV_FILE"
1934

2035
echo "Done. Contents:"
2136
cat "$ENV_FILE"

.pre-commit-config.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
# WATonomous Pre-commit Config
3+
4+
# See https://pre-commit.com for more information on these settings
5+
repos:
6+
# General-purpose sanity checks
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v5.0.0
9+
hooks:
10+
- id: check-added-large-files
11+
- id: check-ast
12+
- id: check-case-conflict
13+
- id: check-merge-conflict
14+
- id: check-shebang-scripts-are-executable
15+
- id: check-symlinks
16+
- id: check-toml
17+
- id: check-xml
18+
- id: end-of-file-fixer
19+
- id: forbid-submodules
20+
- id: mixed-line-ending
21+
- id: trailing-whitespace
22+
23+
# JSON (supports comments)
24+
- repo: https://gitlab.com/bmares/check-json5
25+
rev: v1.0.0
26+
hooks:
27+
- id: check-json5
28+
files: '\.(json|json5|jsonc)$'
29+
30+
# Python (formatting + linting)
31+
- repo: https://github.com/astral-sh/ruff-pre-commit
32+
rev: v0.11.5
33+
hooks:
34+
- id: ruff-format
35+
- id: ruff
36+
args: [--fix]
37+
38+
# C++ formatting
39+
- repo: https://github.com/pre-commit/mirrors-clang-format
40+
rev: v19.1.7
41+
hooks:
42+
- id: clang-format
43+
args: ["--style=file:.config/clang-format"]
44+
45+
# C++ linting
46+
- repo: https://github.com/cpplint/cpplint
47+
rev: 2.0.0
48+
hooks:
49+
- id: cpplint
50+
args: ["--config=.cpplint.cfg", "--filter=-runtime/references", --quiet, --output=sed]
51+
52+
# CMake linting
53+
- repo: https://github.com/cmake-lint/cmake-lint
54+
rev: 1.4.3
55+
hooks:
56+
- id: cmakelint
57+
args: [--linelength=140]
58+
59+
# Bash / Shell scripts
60+
- repo: https://github.com/shellcheck-py/shellcheck-py
61+
rev: v0.10.0.1
62+
hooks:
63+
- id: shellcheck
64+
args: [-e, SC1091]
65+
66+
# Dockerfile linting
67+
- repo: https://github.com/AleksaC/hadolint-py
68+
rev: v2.12.1b3
69+
hooks:
70+
- id: hadolint
71+
args: [--ignore, SC1091, --ignore, DL3006, --ignore, DL3008]
72+
73+
# Markdown linting
74+
- repo: https://github.com/jackdewinter/pymarkdown
75+
rev: v0.9.28
76+
hooks:
77+
- id: pymarkdown
78+
args: [-d, MD013, fix]
79+
80+
# XML (ROS-specific)
81+
- repo: https://github.com/emersonknapp/ament_xmllint
82+
rev: v0.1
83+
hooks:
84+
- id: ament_xmllint
85+
86+
# YAML linting
87+
- repo: https://github.com/adrienverge/yamllint.git
88+
rev: v1.29.0
89+
hooks:
90+
- id: yamllint
91+
args: ["-c", ".config/.yamllint.yaml"]
92+
93+
# License headers
94+
- repo: https://github.com/Lucas-C/pre-commit-hooks
95+
rev: v1.5.5
96+
hooks:
97+
- id: insert-license
98+
types_or: [python, cmake, shell]
99+
name: Copyright headers for Python/CMake
100+
args:
101+
[
102+
--license-filepath,
103+
.config/copyright.txt,
104+
--comment-style,
105+
"#",
106+
--allow-past-years,
107+
--no-extra-eol,
108+
]
109+
- id: insert-license
110+
types_or: [c++, c]
111+
name: Copyright headers for C/C++
112+
args: [--license-filepath, .config/copyright.txt, --comment-style, "//", --allow-past-years]

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ source install/setup.bash
4747
### Troubleshooting
4848

4949
- If the container fails to build, check that Docker is running
50-
- To rebuild from scratch: "Dev Containers: Rebuild Container"
50+
- To rebuild from scratch: "Dev Containers: Rebuild Container"

0 commit comments

Comments
 (0)