Skip to content

Commit 1b1c0c5

Browse files
committed
Introduce EditorConfig
Originally, the indentation of the scripts was not unified: ones in 'scripts/' used 2 spaces, and ones in '.ci/' used 4. Even though the former used 2 spaces, the style was not implemented well as some indents in the files were 4 spaces. This patch unifies the style of the scripts, and note it with an EditorConfig file. EditorConfig is used because it's supported out-of-the-box by many editors, helping the auto-indent functionality works. Change-Id: I41be8779ef5b0e94192c144bb48605625727963f
1 parent 3c7c7b3 commit 1b1c0c5

File tree

11 files changed

+66
-43
lines changed

11 files changed

+66
-43
lines changed

.ci/check-format.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -x
66

77
for file in ${SOURCES};
88
do
9-
clang-format-18 ${file} > expected-format
10-
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
9+
clang-format-18 ${file} > expected-format
10+
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
1111
done
1212
exit $(clang-format-18 --output-replacements-xml ${SOURCES} | grep -E -c "</replacement>")

.ci/check-newline.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ ret=0
66
show=0
77
# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
88
while IFS= read -rd '' f; do
9-
if file --mime-encoding "$f" | grep -qv binary; then
10-
tail -c1 < "$f" | read -r _ || show=1
11-
if [ $show -eq 1 ]; then
12-
echo "Warning: No newline at end of file $f"
13-
ret=1
14-
show=0
15-
fi
9+
if file --mime-encoding "$f" | grep -qv binary; then
10+
tail -c1 < "$f" | read -r _ || show=1
11+
if [ $show -eq 1 ]; then
12+
echo "Warning: No newline at end of file $f"
13+
ret=1
14+
show=0
1615
fi
16+
fi
1717
done < <(git ls-files -z src tests/arch-test-target)
1818

1919
exit $ret

.ci/check-provisioning.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PROVISION_DIR=lab0-c-private
44
if test -f $PROVISION_DIR/queue.c; then
5-
cp -f $PROVISION_DIR/queue.c .
6-
# Skip complexity checks
7-
sed -i '/17:/d' scripts/driver.py
5+
cp -f $PROVISION_DIR/queue.c .
6+
# Skip complexity checks
7+
sed -i '/17:/d' scripts/driver.py
88
fi

.ci/check-sanity.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
SHA1SUM=$(which sha1sum)
44
if [ $? -ne 0 ]; then
5-
SHA1SUM=shasum
5+
SHA1SUM=shasum
66
fi
77

88
$SHA1SUM -c scripts/checksums
99
if [ $? -ne 0 ]; then
10-
echo "[!] You are not allowed to change the header file queue.h or list.h" >&2
11-
exit 1
10+
echo "[!] You are not allowed to change the header file queue.h or list.h" >&2
11+
exit 1
1212
fi

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[Makefile]
8+
indent_style = tab
9+
indent_size = 4
10+
max_line_length = 80
11+
12+
[**/*.[ch]]
13+
indent_style = space
14+
indent_size = 4
15+
max_line_length = 80
16+
17+
[**/*.py]
18+
indent_style = space
19+
indent_size = 4
20+
21+
[**/*.{sh,hook,yml}]
22+
indent_style = space
23+
indent_size = 2

.github/workflows/main.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ jobs:
1010
- uses: webfactory/[email protected]
1111
continue-on-error: true
1212
with:
13-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
13+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
1414
- name: install-dependencies
1515
run: |
16-
.ci/check-sanity.sh
17-
sudo apt-get update
18-
sudo apt-get -q -y install build-essential cppcheck
16+
.ci/check-sanity.sh
17+
sudo apt-get update
18+
sudo apt-get -q -y install build-essential cppcheck
1919
- name: make
2020
run: |
21-
git clone [email protected]:sysprog21/lab0-c-private || echo "No provisioning profile found"
22-
.ci/check-provisioning.sh
23-
make
21+
git clone [email protected]:sysprog21/lab0-c-private || echo "No provisioning profile found"
22+
.ci/check-provisioning.sh
23+
make
2424
- name: make check
2525
run: |
26-
make check || (cat scripts/weeping.raw ; exit 1)
27-
cat scripts/kirby.raw
26+
make check || (cat scripts/weeping.raw ; exit 1)
27+
cat scripts/kirby.raw
2828
- name: make test
2929
run: |
30-
make test || (cat scripts/weeping.raw ; exit 1)
31-
cat scripts/kirby.raw
30+
make test || (cat scripts/weeping.raw ; exit 1)
31+
cat scripts/kirby.raw
3232
3333
coding-style:
3434
runs-on: ubuntu-24.04
3535
steps:
3636
- uses: actions/checkout@v4
3737
- name: coding convention
3838
run: |
39-
sudo apt-get install -q -y clang-format-18
40-
.ci/check-newline.sh
41-
.ci/check-format.sh
39+
sudo apt-get install -q -y clang-format-18
40+
.ci/check-newline.sh
41+
.ci/check-format.sh
4242
shell: bash

scripts/aspell-pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,4 @@ typedef
350350
BitInt
351351
noreturn
352352
pragma
353+
EditorConfig

scripts/check-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ curl -sSL -o "$temp_file" "$COMMITS_URL"
8181
# general grep pattern that finds commit links
8282
upstream_hash=$(
8383
grep -Po 'href="[^"]*/commit/\K[0-9a-f]{40}' "$temp_file" \
84-
| head -n 1
84+
| head -n 1
8585
)
8686

8787
rm -f "$temp_file"

scripts/commit-msg.hook

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ get_all_match_positions() {
119119

120120
# skip if the target is not found
121121
[ -z "$result" ] && continue
122-
122+
123123
# output and update states
124124
local line col
125125
read -r line col <<< "$result"
@@ -250,13 +250,13 @@ validate_commit_message() {
250250
# ------------------------------------------------------------------------------
251251
ASPELL=$(which aspell)
252252
if [ $? -ne 0 ]; then
253-
echo "Aspell not installed - unable to check spelling"
253+
echo "Aspell not installed - unable to check spelling"
254254
else
255-
LINE_NUMBER=1
256-
MISSPELLED_WORDS=$(echo "$COMMIT_MSG_LINES[LINE_NUMBER]" | $ASPELL --lang=en --list --home-dir=scripts --personal=aspell-pws)
257-
if [ -n "$MISSPELLED_WORDS" ]; then
258-
add_warning LINE_NUMBER "Possible misspelled word(s): $MISSPELLED_WORDS"
259-
fi
255+
LINE_NUMBER=1
256+
MISSPELLED_WORDS=$(echo "$COMMIT_MSG_LINES[LINE_NUMBER]" | $ASPELL --lang=en --list --home-dir=scripts --personal=aspell-pws)
257+
if [ -n "$MISSPELLED_WORDS" ]; then
258+
add_warning LINE_NUMBER "Possible misspelled word(s): $MISSPELLED_WORDS"
259+
fi
260260
fi
261261

262262
# 1. Separate subject from body with a blank line
@@ -453,7 +453,7 @@ validate_commit_message() {
453453
FULL_COMMIT_MSG_WITH_SPACE=$(sed '/^[[:space:]]*#/d' "$COMMIT_MSG_FILE" | \
454454
sed -E "/$TRAILER_REGEX/d" | sed -E "s@${URL_REGEX#^}@@g")
455455
FULL_COMMIT_MSG=$(echo "$FULL_COMMIT_MSG_WITH_SPACE" | sed '/^[[:space:]]*$/d')
456-
456+
457457
# Extended list of abusive words (case-insensitive).
458458
# Adjust the list as needed.
459459
ABUSIVE_WORDS_REGEX='\b(fuck|fucking|dick|shit|bitch|asshole|cunt|motherfucker|damn|crap|dumbass|piss)\b'
@@ -475,7 +475,7 @@ validate_commit_message() {
475475
-e "s/(['\"][^'\"]*['\"])//g" \
476476
-e "s/\bcommit[[:space:]]+[0-9a-fA-F]{7,40}\b/commit/g")
477477
MSG_FOR_SPELLCHECK=$(echo "$MSG_FOR_SPELLCHECK_LINE_FINDING" | sed '/^[[:space:]]*$/d')
478-
478+
479479
# Use aspell to list misspelled words according to American English, ignoring quoted text.
480480
MISSPELLED_WORDS=$(echo "$MSG_FOR_SPELLCHECK" | $ASPELL --lang=en --list --home-dir=scripts --personal=aspell-pws)
481481
if [ -n "$MISSPELLED_WORDS" ]; then
@@ -639,8 +639,7 @@ _gen_changeid_input() {
639639
}
640640

641641
_gen_changeid() {
642-
_gen_changeid_input |
643-
git hash-object -t commit --stdin
642+
_gen_changeid_input | git hash-object -t commit --stdin
644643
}
645644

646645
# It's showtime.

scripts/pre-commit.hook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fi
228228
# Cross platform projects tend to avoid non-ASCII filenames; prevent
229229
# them from being added to the repository.
230230
if test $(git diff --cached --name-only --diff-filter=A -z $against |
231-
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
231+
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
232232
then
233233
cat <<\EOF
234234
ERROR: Attempt to add a non-ASCII file name.

0 commit comments

Comments
 (0)