Skip to content

Commit 657406d

Browse files
authored
Add AMReX style CI and EditorConfig file (AMReX-Astro#1349)
https://editorconfig.org/ has instructions on setting up your editor to follow the configured style.
1 parent 0ad0ab2 commit 657406d

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

.editorconfig

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# http://EditorConfig.org
2+
#
3+
# precedence of rules is bottom to top
4+
5+
# this is the top-most EditorConfig file
6+
root = true
7+
8+
9+
[*.{c,h,cpp,hpp,H,py}]
10+
# 4 space indentation
11+
indent_style = space
12+
indent_size = 4
13+
14+
# Clean up trailing whitespace
15+
trim_trailing_whitespace = true
16+
17+
# unix-style newlines
18+
end_of_line = lf
19+
20+
# newline ending in files
21+
insert_final_newline = true
22+
23+
[networks/**/reaclib_rates.H]
24+
# some reaclib rate labels have trailing spaces
25+
trim_trailing_whitespace = false
26+
27+
28+
[*.md]
29+
# two end of line whitespaces are newlines without a paragraph
30+
trim_trailing_whitespace = false
31+
32+
33+
[*.rst]
34+
# Enforce UTF-8 encoding
35+
charset = utf-8
36+
37+
# Unix-style newlines
38+
end_of_line = lf
39+
40+
# Newline ending in files
41+
insert_final_newline = true
42+
43+
# 3 space indentation
44+
indent_style = space
45+
indent_size = 3
46+
47+
# Clean up trailing whitespace
48+
trim_trailing_whitespace = true
49+
50+
[{Makefile,GNUmakefile,Make.*}]
51+
# TABs are part of its syntax
52+
indent_style = tab
53+
indent_size = unset
54+
55+
56+
[util/gcem/**]
57+
# don't mess with the gcem subtree
58+
indent_style = unset
59+
indent_size = unset
60+
trim_trailing_whitespace = unset
61+
end_of_line = unset
62+
insert_final_newline = unset

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Replaced tabs with spaces and trimmed trailing whitespace
2+
5a2247f598f88f80ad8b186188fccfd5537b18d3

.github/workflows/style.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Style
2+
3+
on: [push, pull_request]
4+
5+
concurrency:
6+
group: ${{ github.ref }}-${{ github.head_ref }}-style
7+
cancel-in-progress: true
8+
9+
jobs:
10+
tabs:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Tabs
15+
run: .github/workflows/style/check_tabs.sh
16+
17+
trailing_whitespaces:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Trailing Whitespaces
22+
run: .github/workflows/style/check_trailing_whitespaces.sh

.github/workflows/style/check_tabs.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
find . -type d \( -name .git \
6+
-o -path ./paper \
7+
-o -name build -o -name install \
8+
-o -name tmp_build_dir -o -name tmp_install_dir \
9+
\) -prune -o \
10+
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \
11+
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \
12+
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \
13+
-o -name "*.py" \
14+
-o -name "*.md" -o -name "*.rst" \
15+
-o -name "*.sh" \
16+
-o -name "*.tex" \
17+
-o -name "*.txt" \
18+
-o -name "*.yml" \) \
19+
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \
20+
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \) \
21+
\) \
22+
-exec grep -Iq . {} \; \
23+
-exec sed -i 's/\t/\ \ \ \ /g' {} +
24+
25+
gitdiff=`git diff`
26+
27+
if [ -z "$gitdiff" ]
28+
then
29+
exit 0
30+
else
31+
echo -e "\nTabs are not allowed. Changes suggested by"
32+
echo -e " ${0}\n"
33+
git --no-pager diff
34+
echo ""
35+
exit 1
36+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
find . -type d \( -name .git \
6+
-o -path ./paper \
7+
-o -name build -o -name install \
8+
-o -name tmp_build_dir -o -name tmp_install_dir \
9+
-o -path ./util/gcem \
10+
\) -prune -o \
11+
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \
12+
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \
13+
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \
14+
-o -name "*.py" \
15+
-o -name "*.rst" \
16+
-o -name "*.sh" \
17+
-o -name "*.tex" \
18+
-o -name "*.txt" \
19+
-o -name "*.yml" \) \
20+
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \
21+
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \
22+
-a ! -path "./networks/*/reaclib_rates.H" \) \
23+
\) \
24+
-exec grep -Iq . {} \; \
25+
-exec sed -i 's/[[:blank:]]\+$//g' {} +
26+
27+
gitdiff=`git diff`
28+
29+
if [ -z "$gitdiff" ]
30+
then
31+
exit 0
32+
else
33+
echo -e "\nTrailing whitespaces at the end of a line are not allowed. Changes suggested by"
34+
echo -e " ${0}\n"
35+
git --no-pager diff
36+
echo ""
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)