Skip to content

Commit 0afe2d9

Browse files
committed
Testing: add GitHub action to check all lines are <= 80 characters
1 parent dc2b8e7 commit 0afe2d9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Line Length Check
2+
3+
on:
4+
pull_request:
5+
branches: [ '*' ]
6+
7+
jobs:
8+
line-length-check:
9+
runs-on: ubuntu-latest
10+
name: Check 80 character line limit
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Check line length in PR changes
19+
run: |
20+
# Get the base branch (usually main/master)
21+
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
22+
23+
echo "Checking line length (max 80 characters) for changed files in " \
24+
"src/, examples/, and jni/ directories..."
25+
echo "================================================================"
26+
27+
# Get all changed files in this PR and filter for target directories
28+
git diff --name-only "origin/$BASE_BRANCH"...HEAD | \
29+
grep -E '^(src/|examples/|jni/)' > changed_files.txt || true
30+
31+
# Create a temporary file to collect violations
32+
violation_count=0
33+
echo > violations.tmp
34+
35+
# Check each changed file
36+
while IFS= read -r file; do
37+
if [[ -f "$file" ]]; then
38+
echo "Checking: $file"
39+
40+
# Get added lines and check their length
41+
git diff "origin/$BASE_BRANCH"...HEAD "$file" | \
42+
grep '^+' | grep -v '^+++' | \
43+
while read -r added_line; do
44+
# Remove the leading +
45+
actual_line="${added_line:1}"
46+
char_count=${#actual_line}
47+
48+
if [[ $char_count -gt 80 ]]; then
49+
echo "❌ $file - Line too long ($char_count characters)"
50+
echo " Line: $actual_line"
51+
echo "violation" >> violations.tmp
52+
fi
53+
done
54+
fi
55+
done < changed_files.txt
56+
57+
# Count violations
58+
if [[ -f violations.tmp ]]; then
59+
violation_count=$(grep -c "violation" violations.tmp || echo 0)
60+
else
61+
violation_count=0
62+
fi
63+
64+
echo "================================================================"
65+
66+
if [[ $violation_count -gt 0 ]]; then
67+
echo "❌ Found $violation_count line(s) exceeding 80 " \
68+
"characters in PR changes"
69+
echo ""
70+
echo "Please ensure all lines are 80 characters or less " \
71+
"as per coding standards."
72+
echo "You can check line length in your editor or use this command:"
73+
echo " grep -n '.\{81,\}' <filename>"
74+
rm -f violations.tmp changed_files.txt
75+
exit 1
76+
else
77+
echo "✅ All changed lines are within the 80 character limit"
78+
rm -f violations.tmp changed_files.txt
79+
exit 0
80+
fi

src/main/java/com/wolfssl/wolfcrypt/Ecc.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class Ecc extends NativeStruct {
3636
/* used with native wc_ecc_set_rng() */
3737
private Rng rng = null;
3838

39+
/* this is a long comment that goes over 80 character and is a good test to see if our new GH action catches it */
3940
/* Do we own the Rng struct, or has that been passed in? Used
4041
* during Rng cleanup. */
4142
private boolean weOwnRng = true;
@@ -60,6 +61,7 @@ public Ecc() {
6061
/* Internal state is initialized on first use */
6162
}
6263

64+
private String tmpVarTooLong = "This is also a very long line of code that goes over 80 characters, let's see if GH action catches it.";
6365
/**
6466
* Create new Ecc object with existing Rng object.
6567
*

0 commit comments

Comments
 (0)