Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit f5ea9f2

Browse files
Add rust linting commands to scripts-dev/lint.sh (#14822)
1 parent b50c008 commit f5ea9f2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

changelog.d/14822.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `cargo fmt` and `cargo clippy` to the lint script.

scripts-dev/lint.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,43 @@ echo
101101
# Print out the commands being run
102102
set -x
103103

104+
# Ensure the sort order of imports.
104105
isort "${files[@]}"
106+
107+
# Ensure Python code conforms to an opinionated style.
105108
python3 -m black "${files[@]}"
109+
110+
# Ensure the sample configuration file conforms to style checks.
106111
./scripts-dev/config-lint.sh
112+
113+
# Catch any common programming mistakes in Python code.
107114
# --quiet suppresses the update check.
108115
ruff --quiet "${files[@]}"
116+
117+
# Catch any common programming mistakes in Rust code.
118+
#
119+
# --bins, --examples, --lib, --tests combined explicitly disable checking
120+
# the benchmarks, which can fail due to `#![feature]` macros not being
121+
# allowed on the stable rust toolchain (rustc error E0554).
122+
#
123+
# --allow-staged and --allow-dirty suppress clippy raising errors
124+
# for uncommitted files. Only needed when using --fix.
125+
#
126+
# -D warnings disables the "warnings" lint.
127+
#
128+
# Using --fix has a tendency to cause subsequent runs of clippy to recompile
129+
# rust code, which can slow down this script. Thus we run clippy without --fix
130+
# first which is quick, and then re-run it with --fix if an error was found.
131+
if ! cargo-clippy --bins --examples --lib --tests -- -D warnings > /dev/null 2>&1; then
132+
cargo-clippy \
133+
--bins --examples --lib --tests --allow-staged --allow-dirty --fix -- -D warnings
134+
fi
135+
136+
# Ensure the formatting of Rust code.
137+
cargo-fmt
138+
139+
# Ensure all Pydantic models use strict types.
109140
./scripts-dev/check_pydantic_models.py lint
141+
142+
# Ensure type hints are correct.
110143
mypy

0 commit comments

Comments
 (0)