While trying to make slither work with pre-commit, I noticed slither expects a single file, or directory as CLI args, whereas (my) pre-commit-config.yaml provides slither with a list of space separated filenames.
Working in CLI
After installing slither with: python3 -m pip install slither-analyzer
one can use it like:
slither src
slither .
slither src/some_file.sol
slither src/anotherfile.sol
slither test
slither test/some_test_file
These all allow slither to run successfully.
Pre-commit config
However, The following pre-commit config:
- repo: local
hooks:
- id: slither
name: Slither analysis for smart contracts
entry: slither .
language: system
# folder: src
# files: src
# files: ^(src/)
# files: ^(src/DecentralisedInvestmentManager.sol)
yields output:
...
target can be:
- file.sol // a Solidity file
- project_directory // a project directory. See https://github.com/crytic/crytic-compile/#crytic-compile for the supported platforms
- 0x.. // a contract on mainnet
- NETWORK:0x.. // a contract on a different network. Supported networks: mainet,optim,goerli,sepolia,tobalaba,bsc,testnet.bsc,arbi,testnet.arbi,poly,mumbai,avax,testnet.avax,ftm,goerli.base,base,gno,polyzk,blast
slither: error: unrecognized arguments: .env.example src/DecentralisedInvestmentManager.sol .github/workflows/ci.yml book.toml test/unit/SaasPaymentProcessor.t.sol test/unit/Tier.t.sol
usage: slither target [flag]
target can be:
- file.sol // a Solidity file
- project_directory // a project directory. See https://github.com/crytic/crytic-compile/#crytic-compile for the supported platforms
- 0x.. // a contract on mainnet
- NETWORK:0x.. // a contract on a different network. Supported networks: mainet,optim,goerli,sepolia,tobalaba,bsc,testnet.bsc,arbi,testnet.arbi,poly,mumbai,avax,testnet.avax,ftm,goerli.base,base,gno,polyzk,blast
slither: error: unrecognized arguments: test/integration/MultipleInvestmentTest.sol test/unit/Tier_increaseMultiple_indirect.t.sol test/integration/partialReturn.t.sol branch_coverage .gitpod.yml test/unit/Tier_increaseMultiple_direct.t.sol
usage: slither target [flag]
target can be:
- file.sol // a Solidity file
- project_directory // a project directory. See https://github.com/crytic/crytic-compile/#crytic-compile for the supported platforms
- 0x.. // a contract on mainnet
- NETWORK:0x.. // a contract on a different network. Supported networks: mainet,optim,goerli,sepolia,tobalaba,bsc,testnet.bsc,arbi,testnet.arbi,poly,mumbai,avax,testnet.avax,ftm,goerli.base,base,gno,polyzk,blast
slither: error: unrecognized arguments: classDiagram.svg Images/laser_eyes_4.jpg test/unit/CounterOffer.test.sol test/unit/WorkerGetReward/AddWorkerReward.t.sol foundry.toml test/unit/CustomPaymentSplitter.t.sol
...
Because slither expects 1 file or a folder, not a list of files/folders.
Question
How can I change my pre-commit-config.yaml
to call slither twice with a different folder src
and test
(or multiple times with one relative filepath per call {instead of a list of space separated relative filepaths})?