Skip to content

Commit 6547b81

Browse files
authored
chore(dev): check modified files only for style (#24106)
* chore(dev): check modified files only for style * fix git command
1 parent 31e8d2e commit 6547b81

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

scripts/check-style.sh

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,33 @@ set -euo pipefail
66
# SUMMARY
77
#
88
# Checks that all text files have correct line endings and no trailing spaces.
9+
#
10+
# USAGE
11+
#
12+
# ./scripts/check-style.sh [--fix] [--all]
13+
#
14+
# --fix: Fix issues instead of just reporting them
15+
# --all: Check all files (default: only check modified files)
916

10-
if [ "${1:-}" == "--fix" ]; then
11-
MODE="fix"
12-
else
13-
MODE="check"
14-
fi
17+
MODE="check"
18+
CHECK_ALL=false
19+
20+
# Parse arguments
21+
for arg in "$@"; do
22+
case "$arg" in
23+
--fix)
24+
MODE="fix"
25+
;;
26+
--all)
27+
CHECK_ALL=true
28+
;;
29+
*)
30+
echo "Unknown option: $arg"
31+
echo "Usage: $0 [--fix] [--all]"
32+
exit 1
33+
;;
34+
esac
35+
done
1536

1637
ised() {
1738
local PAT="$1"
@@ -23,8 +44,22 @@ ised() {
2344
rm "$FILE.bak"
2445
}
2546

47+
# Determine which files to check
48+
if [ "$CHECK_ALL" = true ]; then
49+
# Check all files tracked by git
50+
FILES=$(git ls-files)
51+
else
52+
# Check only files changed in current branch compared to origin/master
53+
FILES=$(git diff --name-only "origin/master"...HEAD)
54+
55+
# If no changed files, fall back to checking all files
56+
if [ -z "$FILES" ]; then
57+
FILES=$(git ls-files)
58+
fi
59+
fi
60+
2661
EXIT_CODE=0
27-
for FILE in $(git ls-files); do
62+
for FILE in $FILES; do
2863
# Ignore binary files and generated files.
2964
case "$FILE" in
3065
*png) continue;;

vdev/src/commands/check/fmt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub struct Cli {}
99

1010
impl Cli {
1111
pub fn exec(self) -> Result<()> {
12-
app::exec::<&str>("scripts/check-style.sh", [], true)?;
12+
info!("Checking style (trailing spaces, line endings)...");
13+
app::exec("scripts/check-style.sh", ["--all"], true)?;
14+
15+
info!("Checking Rust formatting...");
1316
app::exec("cargo", ["fmt", "--", "--check"], true)
1417
}
1518
}

vdev/src/commands/fmt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub struct Cli {}
99

1010
impl Cli {
1111
pub fn exec(self) -> Result<()> {
12+
info!("Checking style (trailing spaces, line endings)...");
1213
app::exec("scripts/check-style.sh", ["--fix"], true)?;
14+
15+
info!("Formatting Rust code...");
1316
app::exec("cargo", ["fmt", "--all"], true)
1417
}
1518
}

0 commit comments

Comments
 (0)