# syd's clippy configuration
# please use cargo +nightly clippy if/when you can

cognitive-complexity-threshold = 15
max-fn-params-bools = 0
type-complexity-threshold = 150
disallowed-macros = [
    'std::dbg',
    'std::todo',
    'std::unimplemented',
]
disallowed-methods = [
    # Panics on invalid UTF-8, use var_os instead.
    "std::env::var",

    # Panics on invalid UTF-8, use syd::compat::getdents64 instead.
    "std::fs::read_dir",
    "std::fs::read_to_string",

    # Use proper error handling.
    "std::option::Option::expect",
    "std::option::Option::unwrap",
    "std::result::Result::expect",
    "std::result::Result::unwrap",

    # Use the tempdir crate instead.
    "std::env::temp_dir",

    # Use `std::thread::Builder` and name the thread.
    "std::thread::spawn",

    # We compile with panic = "abort".
    "std::panic::catch_unwind",

    # Use syd::compat::fstatx to stat FDs.
    # fstat() is frequently the wrong thing to do on 32-bit.
    # fstat64() is a poor alternative to fstatx.
    "libc::fstat64",
    "nix::libc::fstat64",
    "nix::sys::stat::fstat",

    # Use syd::compat::fstatfs64 which works on 32-bit.
    # "nix::sys::stat::fstatfs",
    # Use syd::compat::ftruncate64 which works on 32-bit.
    "nix::unistd::ftruncate",

    # Use syd::err::Error instead.
    "anyhow::Error::msg",

    # Use XPath::{push,pop} instead.
    "std::path::PathBuf::push",
    "std::path::PathBuf::pop",
    "std::path::Path::file_name",
    "std::path::Path::parent",

    # This is almost always non-portable and should be avoided.
    "libseccomp::ScmpFilterContext::add_rule_conditional_exact",

    # Use the new system call ABI module `syd::sys`.
    "nix::unistd::setuid",
    "nix::unistd::seteuid",
    "nix::unistd::setresuid",
    "nix::unistd::setgid",
    "nix::unistd::setegid",
    "nix::unistd::setresgid",

    # Use readlinkat(2) with a permitted fd.
    "nix::fcntl::readlink",

    # Use syd::fs:readlinkat.
    "nix::fcntl::readlinkat",

    # Use syd::fs::read_link to reduce allocations.
    "std::fs::read_link",

    # Use syd::lookup::safe_mkdir_all to prevent symlink attacks.
    "std::fs::create_dir_all",

    # Panicing UTF-8 validation in environment variables.
    # use std::env::var_os instead.
    "std::env::var",

    # Use the safe_open_* API with a permitted fd.
    "nix::fcntl::open",
    "nix::fcntl::openat",
    "nix::fcntl::openat2",
    "std::fs::File::open",
    "std::fs::File::create",
    "std::fs::OpenOptions::open",
    "syd::compat::openat2",

    # XXX: Do not use `intersects` which does not do the right thing,
    # possibly because O_RDONLY==0 and breaks internal expectations.
    "nix::fcntl::OFlag::intersects",

    # Handle validation, truncation can lead to unpredicatable results.
    # When truncation is OK, it should be documented why.
    # TODO: https://github.com/rust-lang/rust-clippy/issues/8581
    # "bitflags::Flags::from_bits_truncate",

    # Use pipe2 with O_CLOEXEC.
    "nix::unistd::pipe",

    # Use syd::io::copy which uses sendfile64(2) as necessary.
    "std::io::copy",

    # Use syd::fs:close which panics on EBADF.
    "nix::unistd::close",

    # Use syd::compat versions which compile on Android.
    "libc::dup3",
    "nix::fcntl::openat2",
    "nix::sys::prctl::get_pdeathsig",
    "nix::sys::prctl::set_pdeathsig",
    "nix::sys::prctl::set_child_subreaper",
    "nix::sys::prctl::set_dumpable",
    "nix::sys::prctl::set_name",
    "nix::sys::prctl::set_no_new_privs",
    "nix::sys::prctl::set_pdeathsig",
    "nix::sys::prctl::set_vma_anon_name",
    "nix::sys::stat::makedev",
    "nix::unistd::dup3",
    "nix::unistd::dup3_raw",

    # Use the new mount API with syd::mount.
    "nix::mount::mount",

    # Use syd::compat::clone3 with CLONE_PIDFD.
    "nix::pty::forkpty",
    "nix::sched::clone",
    "nix::unistd::fork",

    # Use the fallible APIs (try_$func).
    "scapegoat::SgMap::insert",
    "scapegoat::SgMap::append",

    # Use safe_close and safe_close_range.
    "libc::close",
    "libc::close_range",
    "nix::unistd::close",

    # Use syd::fd::fdclone.
    "nix::sched::clone",
    "nix::unistd::fork",
]

disallowed-types = [
    # Use syd::err::Error instead.
    "anyhow::Error",
    "anyhow::Result",

    # Use SydRandomState which uses getrandom(2)
    # rather than opening a fd to /dev/urandom.
    "ahash::RandomState",

    # Use SydHashMap and SydHashSet instead.
    "std::collections::HashMap",
    "std::collections::HashSet",

    # Use SydIndexMap and SydIndexSet instead.
    "indexmap::IndexMap",
    "indexmap::IndexSet",

    # Use syd::compat::MsgFlags
    "nix::sys::socket::MsgFlags",

    # Use syd::compat::RenameFlags
    "nix::fcntl::RenameFlags",

    # Use syd::compat::AddWatchFlags
    "nix::sys::inotify::AddWatchFlags",

    # Use syd::compat::MFdFlags
    "nix::sys::memfd::MFdFlags",

    # Use syd::compat alternatives which compile for Android.
    "nix::fcntl::OpenHow",
    "nix::fcntl::ResolveFlag",
    "nix::sys::timer::Expiration",
    "nix::sys::timer::TimerSetTimeFlags",
    "sys::fanotify::Fanotiy",
    "sys::fanotify::MarkFlags",
    "sys::fanotify::MaskFlags",

    # Use syd::compat::FallocateFlags which compiles for Android.
    "nix::fcntl::FallocateFlags",

    # Use syd::compat::Persona which compiles for Android.
    "nix::sys::personality::Persona",

    # Use syd::compat::clone3 with CLONE_PIDFD.
    "nix::pty::ForkptyResult",
    "nix::unistd::ForkResult",

    # Use syd::fd::SafeOwnedFd which uses safe_close.
    "std::os::fd::OwnedFd",
    "std::fs::File",
]
doc-valid-idents = [
    "..",
]
