Skip to content

Commit d474751

Browse files
authored
Created coding-standard.py to check whitespace/formatting of plain text files (#981)
Created coding-standard.py to check whitespace/formatting of plain text files. The Python script will check text files to make sure they don't have any tab characters (except Makefiles) and they don't have trailing whitespace. I made it smarter than the sample pre-commit hook: it *only checks the files that are being changed*, not the entire repo. This way there's no huge commit just to update whitespace. It's also able to do double duty as a PR check. Same thing, it only checks the files in the PR, not the entire repo. If there's any bad whitespace then it blocks the PR from being committed. I've *also* added checking of the C formatting to the tool. **HOWEVER** it will only check the C++ coding style **IFF** the previous version of the file in the repo *already* conforms to the standard as specified by the `.clang-format` file. I suspect there aren't many files that already conform, if there are any at all, so it's unlikely anyone will run into complaints about an edited file not having proper formatting. A brand new file *will* be expected to conform though. I made a couple of minor changes to the `.clang-format`: no tab characters, and lines should be less than 96 characters long. Two other features are `--fix` which will automatically make the necessary corrections to only the files listed on the command line; and `--show` that reformats the specified file and prints it to stdout.
1 parent 329f3e4 commit d474751

File tree

5 files changed

+502
-4
lines changed

5 files changed

+502
-4
lines changed

.clang-format

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
BasedOnStyle: LLVM
2-
ColumnLimit: 200
2+
ColumnLimit: 95
33
AllowShortBlocksOnASingleLine: true
44
AlwaysBreakAfterReturnType: None
55
IncludeBlocks: Preserve
66
SortIncludes: false
7-
UseTab: Always
87
IndentWidth: 4
9-
TabWidth: 4
8+
UseTab: Never
109
AccessModifierOffset: -4
1110
AlignConsecutiveMacros: true
1211
AlwaysBreakTemplateDeclarations: Yes
@@ -28,4 +27,5 @@ BraceWrapping:
2827
BeforeWhile: false
2928
SplitEmptyRecord: false
3029
SplitEmptyNamespace: false
31-
IndentPPDirectives: None
30+
IndentPPDirectives: None
31+
ReflowComments: true

.dir-locals.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
((c++-mode . ((indent-tabs-mode . nil)
2+
(c-basic-offset . 4)
3+
(c-file-offsets . ((substatement-open . 0)))
4+
)))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Check Formatting
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check-formatting:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0 # needed for diffing against base
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Install your formatter
21+
run: pip install -r .github/workflows/coding-standard-requirements.txt
22+
23+
- name: Run formatting check
24+
run: ./coding-standard.py --against origin/${{ github.base_ref || 'master' }}
25+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyyaml
2+
termcolor

0 commit comments

Comments
 (0)