1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Merge pull request #7748 from cakebaker/clippy_move_lints_from_ci_to_cargo_toml

Move clippy lints from CI to `Cargo.toml`
This commit is contained in:
Sylvestre Ledru 2025-04-13 18:51:53 +02:00 committed by GitHub
commit efb09204a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 7 deletions

View file

@ -109,11 +109,10 @@ jobs:
command: | command: |
## `cargo clippy` lint testing ## `cargo clippy` lint testing
unset fault unset fault
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone -W clippy::match_bool"
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}" fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]') fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message> # * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=$(cargo clippy --all-targets --features ${{ matrix.job.features }} --tests -pcoreutils -- ${CLIPPY_FLAGS} -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; } S=$(cargo clippy --all-targets --features ${{ matrix.job.features }} --tests -pcoreutils -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; }
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
style_spellcheck: style_spellcheck:

View file

@ -107,7 +107,7 @@ jobs:
if [ -z "\${FAULT}" ]; then if [ -z "\${FAULT}" ]; then
echo "## cargo clippy lint testing" echo "## cargo clippy lint testing"
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message> # * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=\$(cargo clippy --all-targets \${CARGO_UTILITY_LIST_OPTIONS} -- -W clippy::manual_string_new -D warnings 2>&1) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s" "\$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*\$/::\${FAULT_TYPE} file=\2,line=\3,col=\4::\${FAULT_PREFIX}: \\\`cargo clippy\\\`: \1 (file:'\2', line:\3)/p;" -e '}' ; FAULT=true ; } S=\$(cargo clippy --all-targets \${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "\$S" || { printf "%s\n" "\$S" ; printf "%s" "\$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*\$/::\${FAULT_TYPE} file=\2,line=\3,col=\4::\${FAULT_PREFIX}: \\\`cargo clippy\\\`: \1 (file:'\2', line:\3)/p;" -e '}' ; FAULT=true ; }
fi fi
# Clean to avoid to rsync back the files # Clean to avoid to rsync back the files
cargo clean cargo clean

View file

@ -601,4 +601,11 @@ unused_qualifications = "warn"
[workspace.lints.clippy] [workspace.lints.clippy]
all = { level = "deny", priority = -1 } all = { level = "deny", priority = -1 }
#cargo = { level = "warn", priority = -1 } #cargo = { level = "warn", priority = -1 }
cognitive_complexity = "warn"
default_trait_access = "warn"
implicit_clone = "warn"
manual_string_new = "warn"
match_bool = "warn"
range-plus-one = "warn"
redundant-clone = "warn"
ref_option = "warn" ref_option = "warn"

View file

@ -317,12 +317,12 @@ mod tests {
fn mount_info_with_dev_name(mount_dir: &str, dev_name: Option<&str>) -> MountInfo { fn mount_info_with_dev_name(mount_dir: &str, dev_name: Option<&str>) -> MountInfo {
MountInfo { MountInfo {
dev_id: Default::default(), dev_id: String::default(),
dev_name: dev_name.map(String::from).unwrap_or_default(), dev_name: dev_name.map(String::from).unwrap_or_default(),
fs_type: Default::default(), fs_type: String::default(),
mount_dir: String::from(mount_dir), mount_dir: String::from(mount_dir),
mount_option: Default::default(), mount_option: String::default(),
mount_root: Default::default(), mount_root: String::default(),
remote: Default::default(), remote: Default::default(),
dummy: Default::default(), dummy: Default::default(),
} }

View file

@ -473,6 +473,7 @@ mod tests {
} }
#[test] #[test]
#[allow(clippy::cognitive_complexity)]
fn test_take_all_lines_buffer() { fn test_take_all_lines_buffer() {
// 3 lines with new-lines and one partial line. // 3 lines with new-lines and one partial line.
let input_buffer = "a\nb\nc\ndef"; let input_buffer = "a\nb\nc\ndef";