Skip to content

Commit 4bb7a91

Browse files
author
Ziad Mostafa
committed
iox-eclipse-iceoryx#921 Add markdownlint hook and ci script
Signed-off-by: Ziad Mostafa <ziad.mostafa@apex.ai>
1 parent ace5f51 commit 4bb7a91

File tree

4 files changed

+334
-0
lines changed

4 files changed

+334
-0
lines changed

.markdownlint.yaml

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Default state for all rules
2+
default: true
3+
4+
# Path to configuration file to extend
5+
extends: null
6+
7+
# MD001/heading-increment/header-increment - Heading levels should only increment by one level at a time
8+
MD001: true
9+
10+
# MD002/first-heading-h1/first-header-h1 - First heading should be a top-level heading
11+
MD002:
12+
# Heading level
13+
level: 1
14+
15+
# MD003/heading-style/header-style - Heading style
16+
MD003:
17+
# Heading style
18+
style: "consistent"
19+
20+
# MD004/ul-style - Unordered list style
21+
MD004:
22+
# List style
23+
style: "consistent"
24+
25+
# MD005/list-indent - Inconsistent indentation for list items at the same level
26+
MD005: true
27+
28+
# MD006/ul-start-left - Consider starting bulleted lists at the beginning of the line
29+
MD006: true
30+
31+
# MD007/ul-indent - Unordered list indentation
32+
MD007:
33+
# Spaces for indent
34+
indent: 4
35+
# Whether to indent the first level of the list
36+
start_indented: false
37+
38+
# MD009/no-trailing-spaces - Trailing spaces
39+
MD009:
40+
# Spaces for line break
41+
br_spaces: 2
42+
# Allow spaces for empty lines in list items
43+
list_item_empty_lines: false
44+
# Include unnecessary breaks
45+
strict: false
46+
47+
# MD010/no-hard-tabs - Hard tabs
48+
MD010:
49+
# Include code blocks
50+
code_blocks: true
51+
52+
# MD011/no-reversed-links - Reversed link syntax
53+
MD011: true
54+
55+
# MD012/no-multiple-blanks - Multiple consecutive blank lines
56+
MD012:
57+
# Consecutive blank lines
58+
maximum: 1
59+
60+
# MD013/line-length - Line length
61+
MD013:
62+
# Number of characters
63+
line_length: 100
64+
# Number of characters for headings
65+
heading_line_length: 100
66+
# Number of characters for code blocks
67+
code_block_line_length: 100 # Ignored due to next option
68+
# Include code blocks
69+
code_blocks: false
70+
# Include tables
71+
tables: false
72+
# Include headings
73+
headings: true
74+
# Include headings
75+
headers: true
76+
# Strict length checking
77+
strict: false
78+
# Stern length checking
79+
stern: false
80+
81+
# MD014/commands-show-output - Dollar signs used before commands without showing output
82+
MD014: false
83+
84+
# MD018/no-missing-space-atx - No space after hash on atx style heading
85+
MD018: true
86+
87+
# MD019/no-multiple-space-atx - Multiple spaces after hash on atx style heading
88+
MD019: true
89+
90+
# MD020/no-missing-space-closed-atx - No space inside hashes on closed atx style heading
91+
MD020: true
92+
93+
# MD021/no-multiple-space-closed-atx - Multiple spaces inside hashes on closed atx style heading
94+
MD021: true
95+
96+
# MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines
97+
MD022:
98+
# Blank lines above heading
99+
lines_above: 1
100+
# Blank lines below heading
101+
lines_below: 1
102+
103+
# MD023/heading-start-left/header-start-left - Headings must start at the beginning of the line
104+
MD023: true
105+
106+
# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content
107+
MD024:
108+
# Only check sibling headings
109+
allow_different_nesting: false
110+
# Only check sibling headings
111+
siblings_only: true
112+
113+
# MD025/single-title/single-h1 - Multiple top-level headings in the same document
114+
MD025:
115+
# Heading level
116+
level: 1
117+
# RegExp for matching title in front matter
118+
front_matter_title: "^\\s*title\\s*[:=]"
119+
120+
# MD026/no-trailing-punctuation - Trailing punctuation in heading
121+
MD026:
122+
# Punctuation characters
123+
punctuation: ".,;:!。,;:!"
124+
125+
# MD027/no-multiple-space-blockquote - Multiple spaces after blockquote symbol
126+
MD027: true
127+
128+
# MD028/no-blanks-blockquote - Blank line inside blockquote
129+
MD028: true
130+
131+
# MD029/ol-prefix - Ordered list item prefix
132+
MD029:
133+
# List style
134+
style: "one_or_ordered"
135+
136+
# MD030/list-marker-space - Spaces after list markers
137+
MD030:
138+
# Spaces for single-line unordered list items
139+
ul_single: 1
140+
# Spaces for single-line ordered list items
141+
ol_single: 1
142+
# Spaces for multi-line unordered list items
143+
ul_multi: 1
144+
# Spaces for multi-line ordered list items
145+
ol_multi: 1
146+
147+
# MD031/blanks-around-fences - Fenced code blocks should be surrounded by blank lines
148+
MD031:
149+
# Include list items
150+
list_items: true
151+
152+
# MD032/blanks-around-lists - Lists should be surrounded by blank lines
153+
MD032: true
154+
155+
# MD033/no-inline-html - Inline HTML
156+
MD033:
157+
# Allowed elements
158+
allowed_elements: []
159+
160+
# MD034/no-bare-urls - Bare URL used
161+
MD034: true
162+
163+
# MD035/hr-style - Horizontal rule style
164+
MD035:
165+
# Horizontal rule style
166+
style: "consistent"
167+
168+
# MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading
169+
MD036:
170+
# Punctuation characters
171+
punctuation: ".,;:!?。,;:!?"
172+
173+
# MD037/no-space-in-emphasis - Spaces inside emphasis markers
174+
MD037: true
175+
176+
# MD038/no-space-in-code - Spaces inside code span elements
177+
MD038: true
178+
179+
# MD039/no-space-in-links - Spaces inside link text
180+
MD039: true
181+
182+
# MD040/fenced-code-language - Fenced code blocks should have a language specified
183+
MD040: true
184+
185+
# MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading
186+
MD041:
187+
# Heading level
188+
level: 1
189+
# RegExp for matching title in front matter
190+
front_matter_title: "^\\s*title\\s*[:=]"
191+
192+
# MD042/no-empty-links - No empty links
193+
MD042: true
194+
195+
# MD043/required-headings/required-headers - Required heading structure
196+
MD043:
197+
# List of headings
198+
headings: null
199+
# List of headings
200+
headers: null
201+
202+
# MD044/proper-names - Proper names should have the correct capitalization
203+
MD044:
204+
# List of proper names
205+
names: [
206+
'iceoryx',
207+
'Cyclone DDS',
208+
'CPU',
209+
'CPUs',
210+
'GPS',
211+
'Grafana',
212+
'GUI',
213+
'IMU',
214+
'LiDAR',
215+
'LiDARs',
216+
'MISRA',
217+
'MacOS X',
218+
'MySQL',
219+
'RADAR',
220+
'RADARs',
221+
'ROS 1',
222+
'ROS 2',
223+
'RPi',
224+
'Linux',
225+
'Ubuntu',
226+
'QOS',
227+
'e.g.',
228+
'i.e.',
229+
'SLAM',
230+
'SOME/IP',
231+
'TimescaleDB',
232+
'UI',
233+
'Bazel',
234+
'Zynq',
235+
'RTSP'
236+
]
237+
# Include code blocks
238+
code_blocks: false
239+
240+
# MD045/no-alt-text - Images should have alternate text (alt text)
241+
MD045: true
242+
243+
# MD046/code-block-style - Code block style
244+
MD046:
245+
# Block style
246+
style: "fenced"
247+
248+
# MD047/single-trailing-newline - Files should end with a single newline character
249+
MD047: true
250+
251+
# MD048/code-fence-style - Code fence style
252+
MD048:
253+
# Code fence syle
254+
style: "consistent"

tools/docker/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ RUN apt-get update && apt-get install -y \
3636
g++ \
3737
wget
3838

39+
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
40+
RUN apt-get install -y \
41+
nodejs
42+
43+
RUN npm install -g markdownlint-cli
44+
3945
ADD . /iceoryx
4046
WORKDIR /iceoryx
4147

tools/git-hooks/pre-commit

+6
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ if ! tools/scripts/check_test_ids.sh; then
5656
exit 1
5757
fi
5858

59+
## check for md files change
60+
if ! tools/scripts/markdownlint.sh hook; then
61+
echo "Error executing markdownlint"
62+
exit 1
63+
fi
64+
5965
cd "${current_dir}" || exit

tools/scripts/markdownlint.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2023 by Apex.AI Inc. 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.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
set -e
20+
21+
SCOPE=${1:-full} # Can be either `full` for all files or `hook` for formatting with git hooks
22+
23+
24+
fail() {
25+
printf "\033[1;31merror: %s: %s\033[0m\n" ${FUNCNAME[1]} "${1:-"Unknown error"}"
26+
exit 1
27+
}
28+
29+
hash git || fail "git not found"
30+
31+
# Check if we have at least a specific markdownlint version installed
32+
MARKDOWNLINT_VERSION=0.33.0
33+
MARKDOWNLINT_CMD="markdownlint"
34+
if ! command -v $MARKDOWNLINT_CMD &> /dev/null
35+
then
36+
MARKDOWNLINT_MAJOR_VERSION=$(markdownlint --version | sed -rn 's/.*([0-9][0-9])\.[0-9].*/\1/p')
37+
if [[ $MARKDOWNLINT_MAJOR_VERSION -lt "$MARKDOWNLINT_VERSION" ]]; then
38+
echo "Warning: markdownlint version $MARKDOWNLINT_VERSION or higher is not installed."
39+
echo "Code will not be formatted."
40+
exit 0
41+
else
42+
MARKDOWNLINT_CMD="markdownlint"
43+
fi
44+
fi
45+
46+
cd "$(git rev-parse --show-toplevel)"
47+
48+
if [[ "$SCOPE" == "hook"* ]]; then
49+
md_files=$(git diff --cached --name-only --diff-filter=ACMRT | grep -E "\.md"| cat)
50+
if [[ -n ${md_files} ]]; then
51+
52+
echo "Running markdownlint on the following file(s):"
53+
echo "--------------------------------------------"
54+
echo "${md_files}" | sed 's/^/\ -\ /g'
55+
echo
56+
57+
for file in $md_files ; do
58+
if [ -f "$file" ]; then
59+
$MARKDOWNLINT_CMD --output ./markdownlint.log --config ./.markdownlint.yaml "${file}"
60+
git add "${file}"
61+
fi
62+
done
63+
fi
64+
elif [[ "$SCOPE" == "full"* ]]; then
65+
git ls-files | grep -E "\.md"| xargs markdownlint --output ./markdownlint.log --config ./.markdownlint.yaml
66+
elif [[ "$SCOPE" == "check"* ]]; then
67+
git ls-files | grep -E "\.md"| xargs markdownlint --output ./markdownlint.log --config ./.markdownlint.yaml
68+
fi

0 commit comments

Comments
 (0)