Browse Source

Add rust linting commands to `scripts-dev/lint.sh` (#14822)

tags/v1.76.0rc1
Andrew Morgan 1 year ago
committed by GitHub
parent
commit
f5ea9f2b1d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions
  1. +1
    -0
      changelog.d/14822.misc
  2. +33
    -0
      scripts-dev/lint.sh

+ 1
- 0
changelog.d/14822.misc View File

@@ -0,0 +1 @@
Add `cargo fmt` and `cargo clippy` to the lint script.

+ 33
- 0
scripts-dev/lint.sh View File

@@ -101,10 +101,43 @@ echo
# Print out the commands being run
set -x

# Ensure the sort order of imports.
isort "${files[@]}"

# Ensure Python code conforms to an opinionated style.
python3 -m black "${files[@]}"

# Ensure the sample configuration file conforms to style checks.
./scripts-dev/config-lint.sh

# Catch any common programming mistakes in Python code.
# --quiet suppresses the update check.
ruff --quiet "${files[@]}"

# Catch any common programming mistakes in Rust code.
#
# --bins, --examples, --lib, --tests combined explicitly disable checking
# the benchmarks, which can fail due to `#![feature]` macros not being
# allowed on the stable rust toolchain (rustc error E0554).
#
# --allow-staged and --allow-dirty suppress clippy raising errors
# for uncommitted files. Only needed when using --fix.
#
# -D warnings disables the "warnings" lint.
#
# Using --fix has a tendency to cause subsequent runs of clippy to recompile
# rust code, which can slow down this script. Thus we run clippy without --fix
# first which is quick, and then re-run it with --fix if an error was found.
if ! cargo-clippy --bins --examples --lib --tests -- -D warnings > /dev/null 2>&1; then
cargo-clippy \
--bins --examples --lib --tests --allow-staged --allow-dirty --fix -- -D warnings
fi

# Ensure the formatting of Rust code.
cargo-fmt

# Ensure all Pydantic models use strict types.
./scripts-dev/check_pydantic_models.py lint

# Ensure type hints are correct.
mypy

Loading…
Cancel
Save