Skip to content

Commit 7cfe1cb

Browse files
scripts: improve formating
add git lint, script to install git hook, modified formatting cfg Signed-off-by: Robert Gałat <robert.galat@nordicsemi.no>
1 parent 9a0cdf8 commit 7cfe1cb

File tree

6 files changed

+93
-7
lines changed

6 files changed

+93
-7
lines changed

.gitlint

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# All these sections are optional, edit this file as you like.
2+
[general]
3+
ignore=title-trailing-punctuation, T3, title-max-length, T1, body-hard-tab, B3, B1
4+
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
5+
verbosity = 3
6+
# By default gitlint will ignore merge commits. Set to 'false' to disable.
7+
ignore-merge-commits=false
8+
ignore-revert-commits=false
9+
ignore-fixup-commits=false
10+
ignore-squash-commits=false
11+
# Enable debug mode (prints more output). Disabled by default
12+
debug = false
13+
14+
# Set the extra-path where gitlint will search for user defined rules
15+
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
16+
extra-path=../zephyr/scripts/gitlint
17+
18+
[title-max-length-no-revert]
19+
line-length=75
20+
21+
[body-min-line-count]
22+
min-line-count=1
23+
24+
[body-max-line-count]
25+
max-line-count=200
26+
27+
[title-starts-with-subsystem]
28+
regex = ^(?!subsys:)(([^:]+):)(\s([^:]+):)*\s(.+)$
29+
30+
[title-must-not-contain-word]
31+
# Comma-separated list of words that should not occur in the title. Matching is case
32+
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
33+
# will not cause a violation, but "WIP: my title" will.
34+
words=wip
35+
36+
[title-match-regex]
37+
# python like regex (https://docs.python.org/2/library/re.html) that the
38+
# commit-msg title must be matched to.
39+
# Note that the regex can contradict with other rules if not used correctly
40+
# (e.g. title-must-not-contain-word).
41+
#regex=^US[0-9]*
42+
43+
[max-line-length-with-exceptions]
44+
# B1 = body-max-line-length
45+
line-length=72
46+
47+
[body-min-length]
48+
min-length=3
49+
50+
[body-is-missing]
51+
# Whether to ignore this rule on merge commits (which typically only have a title)
52+
# default = True
53+
ignore-merge-commits=false
54+
55+
[body-changed-file-mention]
56+
# List of files that need to be explicitly mentioned in the body when they are changed
57+
# This is useful for when developers often erroneously edit certain files or git submodules.
58+
# By specifying this rule, developers can only change the file when they explicitly reference
59+
# it in the commit message.
60+
#files=gitlint/rules.py,README.md

.uncrustify.cfg

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ sp_arith = add
5353
sp_bool = add
5454
sp_compare = add
5555
sp_assign = add
56-
sp_after_comma = add
5756
sp_func_def_paren = remove # "int foo (){" vs "int foo(){"
5857
sp_func_call_paren = remove # "foo (" vs "foo("
5958
sp_func_proto_paren = remove # "int foo ();" vs "int foo();"
@@ -93,3 +92,10 @@ nl_after_func_body = 2 # number
9392

9493
# The number of newlines after '}' of a single line function body
9594
nl_after_func_body_one_liner = 2 # number
95+
96+
indent_extern = false
97+
code_width = 120
98+
cmt_width = 120
99+
sp_after_comma = force
100+
sp_before_comma = remove
101+
nl_max = 2

scripts/git_hooks/commit-msg

100644100755
File mode changed.

scripts/git_hooks/install_hooks.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
link_hook()
4+
{
5+
hook_name=$1
6+
if test -f "$ZEPHYR_BASE/../sidewalk/.git/hooks/$hook_name"; then
7+
rm -rf $ZEPHYR_BASE/../sidewalk/.git/hooks/$hook_name
8+
fi
9+
10+
ln -s $ZEPHYR_BASE/../sidewalk/scripts/git_hooks/$hook_name $ZEPHYR_BASE/../sidewalk/.git/hooks/$hook_name
11+
chmod +x $ZEPHYR_BASE/../sidewalk/scripts/git_hooks/$hook_name
12+
}
13+
14+
link_hook commit-msg
15+
link_hook pre-commit
16+
link_hook prepare-commit-msg

scripts/git_hooks/pre-commit

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ UNCRUST_CONFIG="$ZEPHYR_BASE/../sidewalk/.uncrustify.cfg"
33
# get list of staged files
44
staged_files=$(git diff --name-only --staged --diff-filter=AMR | grep -E '\.(c|h|cpp|hpp)$')
55
if [ -n "$staged_files" ]; then
6-
echo "## Executing uncrustify"
7-
uncrustify -c $UNCRUST_CONFIG --check $staged_files
8-
if [ $? -ne 0 ]; then
9-
uncrustify -c $UNCRUST_CONFIG --replace --no-backup $staged_files
10-
echo "suggested changes were made on the tracked files, please review them and stage for commit"
11-
exit 1
6+
non_mamazon_files=$(grep -l -L "Copyright .* Amazon.com, Inc. or its affiliates. All rights reserved." $staged_files)
7+
if [ -n "$non_mamazon_files" ]; then
8+
9+
echo "## Executing uncrustify"
10+
uncrustify -c $UNCRUST_CONFIG --check $non_mamazon_files
11+
if [ $? -ne 0 ]; then
12+
uncrustify -c $UNCRUST_CONFIG --replace --no-backup $staged_files
13+
echo "suggested changes were made on the tracked files, please review them and stage for commit"
14+
exit 1
15+
fi
1216
fi
1317
fi

scripts/git_hooks/prepare-commit-msg

100644100755
File mode changed.

0 commit comments

Comments
 (0)