nits.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. #
  3. # Project nits enforced here
  4. #
  5. set -e
  6. cd "$(dirname "$0")/.."
  7. source ci/_
  8. # Logging hygiene: Please don't print from --lib, use the `log` crate instead
  9. declare prints=(
  10. 'print!'
  11. 'println!'
  12. 'eprint!'
  13. 'eprintln!'
  14. 'dbg!'
  15. )
  16. # Parts of the tree that are expected to be print free
  17. declare print_free_tree=(
  18. ':core/src/**.rs'
  19. ':^core/src/validator.rs'
  20. ':faucet/src/**.rs'
  21. ':ledger/src/**.rs'
  22. ':metrics/src/**.rs'
  23. ':net-utils/src/**.rs'
  24. ':platform-tools-sdk/**.rs'
  25. ':platform-tools-sdk/sbf/rust/rust-utils/**.rs'
  26. ':^platform-tools-sdk/cargo-build-sbf/**.rs'
  27. ':runtime/src/**.rs'
  28. ':sdk/**.rs'
  29. ':^sdk/msg/src/lib.rs'
  30. ':^sdk/program-option/src/lib.rs'
  31. ':^sdk/pubkey/src/lib.rs'
  32. ':^sdk/sysvar/src/program_stubs.rs'
  33. ':programs/**.rs'
  34. ':^**bin**.rs'
  35. ':^**bench**.rs'
  36. ':^**test**.rs'
  37. ':^**/build.rs'
  38. )
  39. if _ git --no-pager grep -n "${prints[@]/#/-e}" -- "${print_free_tree[@]}"; then
  40. exit 1
  41. fi
  42. # Ref: https://github.com/solana-labs/solana/pull/30843#issuecomment-1480399497
  43. if _ git --no-pager grep -F '.hidden(true)' -- '*.rs'; then
  44. echo 'use ".hidden(hidden_unless_forced())" instead'
  45. exit 1
  46. fi
  47. # Github Issues should be used to track outstanding work items instead of
  48. # marking up the code
  49. #
  50. # Ref: https://github.com/solana-labs/solana/issues/6474
  51. #
  52. # shellcheck disable=1001
  53. declare useGithubIssueInsteadOf=(
  54. X\XX
  55. T\BD
  56. F\IXME
  57. #T\ODO # TODO: Disable TODOs once all other TODOs are purged
  58. )
  59. if _ git --no-pager grep -n --max-depth=0 "${useGithubIssueInsteadOf[@]/#/-e }" -- '*.rs' '*.sh' '*.md'; then
  60. exit 1
  61. fi
  62. # TODO: Remove this `git grep` once TODOs are banned above
  63. # (this command is only used to highlight the current offenders)
  64. _ git --no-pager grep -n --max-depth=0 "-e TODO" -- '*.rs' '*.sh' '*.md' || true
  65. echo "^^^ +++"
  66. # END TODO