Skip to content

Commit be9a270

Browse files
committed
Introduce EditorConfig
Originally, the indentation of the scripts in directory 'scripts/' and the GitHub workflow was inconsistent due to human error, and some files contains lines with only spaces. This patch introduces EditorConfig, which is supported out-of-the-box by many editors, to help the auto-indent functionality work. It sets the indentation to the currently used indentation of each file respectively, and ask editors to use Unix-like newlines (line feed at the end of each line) and avoid trailing white-spaces. Change-Id: Idaa878cb779b637c1361baa637419645828530cb
1 parent edd54e1 commit be9a270

File tree

6 files changed

+51
-27
lines changed

6 files changed

+51
-27
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[Makefile]
9+
indent_style = tab
10+
indent_size = 4
11+
max_line_length = 80
12+
13+
[**/*.[ch]]
14+
indent_style = space
15+
indent_size = 4
16+
max_line_length = 80
17+
18+
[{**/*.py,.ci/*}]
19+
indent_style = space
20+
indent_size = 4
21+
22+
[{scripts/*,.github/workflows/*}]
23+
indent_style = space
24+
indent_size = 2

.github/workflows/main.yml

+14-14
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

+1
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,4 @@ typedef
350350
BitInt
351351
noreturn
352352
pragma
353+
EditorConfig

scripts/commit-msg.hook

+10-11
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
@@ -656,8 +656,7 @@ _gen_changeid_input() {
656656
}
657657

658658
_gen_changeid() {
659-
_gen_changeid_input |
660-
git hash-object -t commit --stdin
659+
_gen_changeid_input | git hash-object -t commit --stdin
661660
}
662661

663662
# It's showtime.

scripts/pre-commit.hook

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fi
248248
# Cross platform projects tend to avoid non-ASCII filenames; prevent
249249
# them from being added to the repository.
250250
if test $(git diff --cached --name-only --diff-filter=A -z $against |
251-
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
251+
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
252252
then
253253
cat <<\EOF
254254
ERROR: Attempt to add a non-ASCII file name.

scripts/prepare-commit-msg.hook

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COMMIT_MSG_FILE="$1"
44

55
# If the commit message file already contains non-comment lines, do nothing.
66
if grep -qE '^[^[:space:]#]' "$COMMIT_MSG_FILE"; then
7-
exit 0
7+
exit 0
88
fi
99

1010
# Gather a list of staged (changed) files.

0 commit comments

Comments
 (0)