Skip to content

Commit

Permalink
improve script (no fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Oct 1, 2024
1 parent 111c1e4 commit 91f1f69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ repos:
types: [rust]
args: [--]

- id: cargo-machete
name: cargo machete
description: Check for unused Rust dependencies
entry: ./tools/run_cargo_machete.sh
language: system
types: [rust]
pass_filenames: false
verbose: true
fail_fast: false

- id: cargo-check-default
name: cargo check (default)
description: Check the package for errors with default features.
Expand Down Expand Up @@ -110,15 +120,6 @@ repos:
types: [rust]
pass_filenames: false

- id: cargo-machete
name: cargo machete
description: Check for unused Rust dependencies
entry: cargo machete
language: system
types: [rust]
pass_filenames: false
args: [--with-metadata]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.19
hooks:
Expand Down
22 changes: 22 additions & 0 deletions tools/run_cargo_machete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# ANSI color codes
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Check if cargo-machete is installed
if ! command -v cargo-machete &> /dev/null
then
echo -e "${YELLOW}Warning: cargo-machete could not be found${NC}"
echo -e "${YELLOW}To install, run: ${GREEN}cargo install cargo-machete${NC}"
echo -e "${YELLOW}Skipping cargo-machete check${NC}"
else
# Run cargo-machete with the --with-metadata flag
echo -e "${GREEN}Running cargo-machete...${NC}"
cargo machete --with-metadata
fi

# Always exit with 0 to not fail
exit 0

0 comments on commit 91f1f69

Please sign in to comment.