diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..7014edc9 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ + + +### What does this PR try to solve? + + +Fixes # + +### Notes to reviewers + + + +LLM involvement: diff --git a/.github/renovate.json5 b/.github/renovate.json5 index cc1fefc3..7dec7acd 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,11 +1,16 @@ { + extends: ["helpers:pinGitHubActionDigests"], schedule: [ 'before 5am on the first day of the month', ], + minimumReleaseAge: "3 days", + internalChecksFilter: "strict", semanticCommits: 'enabled', commitMessageLowerCase: 'never', configMigration: true, - dependencyDashboard: true, + dependencyDashboard: { + enabled: true, + }, "pre-commit": { enabled: true }, @@ -64,11 +69,19 @@ matchDepNames: [ 'prek', ], - extractVersion: '^(?\\d+\\.\\d+\\.\\d+)', - schedule: [ - '* * * * *', + extractVersion: '^v(?\\d+\\.\\d+\\.\\d+)', + automerge: true, + }, + { + matchManagers: [ + 'github-actions', + ], + matchUpdateTypes: [ + 'minor', + 'patch', ], automerge: true, + groupName: 'compatible (actions)', }, // Goals: // - Keep version reqs low, ignoring compatible normal/build dependencies diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 5dcd1a9f..b070313e 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -1,13 +1,10 @@ -name: Security audit +name: Audit permissions: contents: read on: pull_request: - paths: - - '**/Cargo.toml' - - '**/Cargo.lock' push: branches: - main @@ -22,19 +19,38 @@ concurrency: cancel-in-progress: true jobs: - security_audit: + audit: + permissions: + contents: none + name: Audit + needs: [advisories, cargo_deny, actions] + runs-on: ubuntu-latest + if: "always()" + steps: + - name: Failed + run: exit 1 + if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')" + advisories: permissions: issues: write # to create issues (actions-rs/audit-check) checks: write # to create check (actions-rs/audit-check) runs-on: ubuntu-latest # Prevent sudden announcement of a new advisory from failing ci: continue-on-error: true + strategy: + matrix: + checks: + - advisories steps: - name: Checkout repository - uses: actions/checkout@v7 - - uses: actions-rs/audit-check@v1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Lint advisories + uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1 with: - token: ${{ secrets.GITHUB_TOKEN }} + command: check ${{ matrix.checks }} + rust-version: stable cargo_deny: permissions: @@ -46,8 +62,29 @@ jobs: checks: - bans licenses sources steps: - - uses: actions/checkout@v7 - - uses: EmbarkStudios/cargo-deny-action@v2 + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Lint bans + uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1 with: command: check ${{ matrix.checks }} rust-version: stable + + actions: + runs-on: ubuntu-latest + permissions: + security-events: write + contents: read # only needed for private or internal repos + actions: read # only needed for private or internal repos + steps: + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Run zizmor + uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0 + with: + advanced-security: false + annotations: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8d23211..d61f4433 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ env: RUST_BACKTRACE: 1 CARGO_TERM_COLOR: always CLICOLOR: 1 + CARGO_INCREMENTAL: 0 + RUST_TOOLCHAIN_STABLE: "1.100" # STABLE concurrency: group: "${{ github.workflow }}-${{ github.ref }}" @@ -43,13 +45,17 @@ jobs: CARGO_PROFILE_DEV_DEBUG: line-tables-only steps: - name: Checkout repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install Rust - uses: dtolnay/rust-toolchain@stable + run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Install cargo-hack + uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0 with: - toolchain: ${{ matrix.rust }} - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@cargo-hack + tool: cargo-hack - name: Build run: cargo test --workspace --no-run - name: Test @@ -62,13 +68,17 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install Rust - uses: dtolnay/rust-toolchain@stable + run: rustup update --no-self-update stable && rustup default stable + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Install cargo-hack + uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0 with: - toolchain: stable - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@cargo-hack + tool: cargo-hack - name: Default features run: cargo hack check --each-feature --locked --rust-version --ignore-private --workspace --all-targets --keep-going minimal-versions: @@ -79,15 +89,13 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install stable Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: stable + persist-credentials: false + - name: Install stable Rust + run: rustup update --no-self-update stable && rustup default stable - name: Install nightly Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: nightly + run: rustup update --no-self-update nightly && rustup default nightly - name: Downgrade dependencies to minimal versions run: cargo +nightly generate-lockfile -Z minimal-versions - name: Compile with minimal versions @@ -96,12 +104,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: stable - - uses: Swatinem/rust-cache@v2 + persist-credentials: false + - name: Install Rust + run: rustup update --no-self-update stable && rustup default stable + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: "Is lockfile updated?" run: cargo update --workspace --locked docs: @@ -109,28 +118,31 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: "1.99" # STABLE - - uses: Swatinem/rust-cache@v2 + persist-credentials: false + - name: Install Rust + run: rustup update --no-self-update $RUST_TOOLCHAIN_STABLE && rustup default $RUST_TOOLCHAIN_STABLE + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Check documentation env: - RUSTDOCFLAGS: -D warnings + CARGO_BUILD_WARNINGS: deny run: cargo doc --workspace --all-features --no-deps --document-private-items --keep-going rustfmt: name: rustfmt runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: "1.99" # STABLE - components: rustfmt - - uses: Swatinem/rust-cache@v2 + persist-credentials: false + - name: Install Rust + run: rustup update --no-self-update $RUST_TOOLCHAIN_STABLE && rustup default $RUST_TOOLCHAIN_STABLE + - name: Install rustfmt + run: rustup component add rustfmt + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Check formatting run: cargo fmt --check clippy: @@ -140,13 +152,15 @@ jobs: security-events: write # to upload sarif results steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: "1.99" # STABLE - components: clippy - - uses: Swatinem/rust-cache@v2 + persist-credentials: false + - name: Install Rust + run: rustup update --no-self-update $RUST_TOOLCHAIN_STABLE && rustup default $RUST_TOOLCHAIN_STABLE + - name: Install clippy + run: rustup component add clippy + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Install SARIF tools run: cargo install clippy-sarif --locked - name: Install SARIF tools @@ -159,28 +173,37 @@ jobs: | sarif-fmt continue-on-error: true - name: Upload - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 with: sarif_file: clippy-results.sarif wait-for-processing: true - name: Report status - run: cargo clippy --workspace --all-features --all-targets --keep-going -- -D warnings --allow deprecated + env: + CARGO_BUILD_WARNINGS: deny + run: cargo clippy --workspace --all-features --all-targets --keep-going -- --allow deprecated --allow renamed_and_removed_lints coverage: name: Coverage runs-on: ubuntu-latest + permissions: + code-quality: write steps: - name: Checkout repository - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - toolchain: stable - - uses: Swatinem/rust-cache@v2 + persist-credentials: false + - name: Install Rust + run: rustup update --no-self-update stable && rustup default stable + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: Install cargo-tarpaulin - run: cargo install cargo-tarpaulin + uses: taiki-e/install-action@37f7c5781271959fb65b6b35224e28652ff2b63d # v2.87.0 + with: + tool: cargo-tarpaulin - name: Gather coverage - run: cargo tarpaulin --output-dir coverage --out lcov - - name: Publish to Coveralls - uses: coverallsapp/github-action@master + run: cargo tarpaulin --out xml --timeout 120 + - name: Upload coverage report + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + uses: actions/upload-code-coverage@2b21a77928be8d5168c2b9581a67f2adbebacc52 # v1.4.4 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + file: cobertura.xml + language: Rust diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml deleted file mode 100644 index 747fd127..00000000 --- a/.github/workflows/commit-lint.yml +++ /dev/null @@ -1,25 +0,0 @@ -on: - pull_request: - -name: Pull Request Checks - -jobs: - block-fixup: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - name: Block fixup commit merge - uses: 13rac1/block-fixup-merge-action@v2.0.0 - - commit-lint: - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - uses: actions/setup-python@v6 - with: - python-version: '3.x' - - run: pip install gitlint - - run: gitlint --commits $(git merge-base origin/master HEAD)..HEAD diff --git a/.github/workflows/committed.yml b/.github/workflows/committed.yml index 128ad238..773fcd01 100644 --- a/.github/workflows/committed.yml +++ b/.github/workflows/committed.yml @@ -20,9 +20,11 @@ jobs: name: Lint Commits runs-on: ubuntu-latest steps: - - name: Checkout Actions Repository - uses: actions/checkout@v7 + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + filter: "tree:0" + persist-credentials: false - name: Lint Commits - uses: crate-ci/committed@master + uses: crate-ci/committed@faeed42f2e10c244533a01525f13c4d8b6ce383f # v1.1.11 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index f62094fb..2b798597 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -22,7 +22,11 @@ jobs: contents: read runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 - - uses: j178/prek-action@v2 + - name: Checkout repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: prek + uses: j178/prek-action@44924fe9ef4a6f88253c4b6b1bf11c689d3ce53d # v3.1.0 with: prek-version: 'v0.5.9' diff --git a/.github/workflows/rust-next.yml b/.github/workflows/rust-next.yml index d04d42e4..49d8f1a8 100644 --- a/.github/workflows/rust-next.yml +++ b/.github/workflows/rust-next.yml @@ -11,6 +11,7 @@ env: RUST_BACKTRACE: 1 CARGO_TERM_COLOR: always CLICOLOR: 1 + CARGO_INCREMENTAL: 0 concurrency: group: "${{ github.workflow }}-${{ github.ref }}" @@ -33,13 +34,17 @@ jobs: CARGO_PROFILE_DEV_DEBUG: line-tables-only steps: - name: Checkout repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install Rust - uses: dtolnay/rust-toolchain@stable + run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Install cargo-hack + uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0 with: - toolchain: ${{ matrix.rust }} - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@cargo-hack + tool: cargo-hack - name: Build run: cargo test --workspace --no-run - name: Test @@ -54,13 +59,17 @@ jobs: CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS: allow steps: - name: Checkout repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install Rust - uses: dtolnay/rust-toolchain@stable + run: rustup update --no-self-update stable && rustup default stable + - name: Initialize cache + uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Install cargo-hack + uses: taiki-e/install-action@86f7a0ffb25f40114606501a311ebcfaf882ea32 # v2.88.0 with: - toolchain: stable - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@cargo-hack + tool: cargo-hack - name: Update dependencies run: cargo update - name: Build diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml index acb183b9..df7007d3 100644 --- a/.github/workflows/spelling.yml +++ b/.github/workflows/spelling.yml @@ -20,6 +20,8 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Actions Repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Spell Check Repo - uses: crate-ci/typos@master + uses: crate-ci/typos@7f9d0819ca1c008ade73f4b41fa9d258d48f605b # v1.51.1 diff --git a/.github/workflows/template.yml b/.github/workflows/template.yml index eb679cb9..76121eef 100644 --- a/.github/workflows/template.yml +++ b/.github/workflows/template.yml @@ -28,12 +28,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: true # to push the branch and create PR - name: Configure git run: | - git config --global user.name '${{ github.actor }}' + git config --global user.name '${GITHUB_ACTOR}' git config --global user.email '<>' - name: Fetch template run: "git remote add template ${{ env.TEMPLATE_URL }} && git fetch template ${{ env.TEMPLATE_BRANCH }}" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6321d79e..49bc1555 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,7 @@ repos: rev: v1.1.11 hooks: - id: committed + - repo: https://github.com/zizmorcore/zizmor-pre-commit + rev: v1.28.0 + hooks: + - id: zizmor diff --git a/AI_POLICY.md b/AI_POLICY.md new file mode 100644 index 00000000..b2ad65fd --- /dev/null +++ b/AI_POLICY.md @@ -0,0 +1,58 @@ +# AI policy + +Project maintainers are responsible for any code that is published as part of a release. +Contributors are responsible for their contributions, both in terms of communications and code. +This responsibility is for both understanding of and the quality of their contributions. + +## Personal use + +You are free to use an AI locally for your own purposes, +including to answer your questions, analyze, distill, refine, check, suggest, and review. + +## Communication + +**AI should not be used to generate comments when communicating with maintainers.** +We expect comments on our projects to be written by humans. +We may hide or delete any comments where we believe AI generation was involved. + +If you are opening an issue, +we expect you to have personally reproduced the problem and to describe it in your own words. + +If you are opening a pull request, +we expect you to be able to explain the proposed changes in your own words. +This includes the pull request body and responses to questions. +**Do not copy responses from an AI when replying to questions from maintainers.** +Do not run agents or bots on pull requests without first getting approval. + +We understand that AI is useful when communicating as a non-native English speaker. +If you are using AI to edit your comments for this purpose, +please take the time to ensure it reflects your own voice and ideas. +If using AI for translation, we recommend writing in your native language and including the AI translation in a [`
` block]. + +If you wish to include context from an interaction with AI in your comments, +it must be in a [`
` block] and disclosed as such. +The block must include human commentary explaining the relevance and implications of the context. +The content of your comment must stand on its own even without the quoted content. +Do not share long snippets. + +## Code + +Using AI as tools for coding requires receiving permission on the relevant issue before a PR is posted. + +This project requires a human in the loop who understands the work produced by AI. +**We do not allow autonomous agents to be used for contributing to this project**. +We will close any pull requests that we believe were created **without meaningful involvement** from the contributor. +Contributions should not "read" as being written by an AI. + +Some areas require specific expertise or care when touching. +AI generated code, even with human review, is prohibited for: +- none + +We view AI as providing a way to improve quality and will hold AI-assisted contributions to a higher standard. +We will be more free in asking for changes. + +The involvement of AI assistance must be disclosed in PRs. + +For documentation, including comments in code, see [Communication](#communication). + +[`
` block]: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-collapsed-sections) diff --git a/Cargo.toml b/Cargo.toml index 427d6742..ace15e2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,17 +7,20 @@ license = "MIT OR Apache-2.0" edition = "2024" rust-version = "1.85.0" # MSRV include = [ - "build.rs", - "src/**/*", - "Cargo.toml", - "Cargo.lock", - "LICENSE*", - "README.md", - "examples/**/*" + "/build.rs", + "/src/**/*", + "/Cargo.toml", + "/Cargo.lock", + "/LICENSE*", + "/README.md", + "/examples/**/*" ] [workspace.lints.rust] rust_2018_idioms = { level = "warn", priority = -1 } + +non_ascii_idents = "warn" +trivial_numeric_casts = "warn" unnameable_types = "warn" unreachable_pub = "warn" unsafe_op_in_unsafe_fn = "warn" @@ -26,10 +29,17 @@ unused_macro_rules = "warn" unused_qualifications = "warn" [workspace.lints.clippy] +allow_attributes_without_reason = "warn" bool_assert_comparison = "allow" branches_sharing_code = "allow" +byte_char_slices = "allow" # sometimes explicit arrays are better +cast_possible_truncation = "warn" +cast_possible_wrap = "warn" +cast_sign_loss = "warn" checked_conversions = "warn" collapsible_else_if = "allow" +collapsible_match = "allow" +collection_is_never_read = "warn" create_dir = "warn" dbg_macro = "warn" debug_assert_with_mut_call = "warn" @@ -42,9 +52,10 @@ explicit_into_iter_loop = "warn" fallible_impl_from = "warn" filter_map_next = "warn" flat_map_option = "warn" +float_cmp = "warn" float_cmp_const = "warn" fn_params_excessive_bools = "warn" -from_iter_instead_of_collect = "warn" +fn_to_numeric_cast_any = "warn" if_same_then_else = "allow" implicit_clone = "warn" imprecise_flops = "warn" @@ -60,10 +71,12 @@ linkedlist = "warn" lossy_float_literal = "warn" macro_use_imports = "warn" mem_forget = "warn" +mismatching_type_param_order = "warn" mutex_integer = "warn" needless_continue = "allow" needless_for_each = "warn" negative_feature_names = "warn" +partial_pub_fields = "warn" path_buf_push_overwrite = "warn" ptr_as_ptr = "warn" rc_mutex = "warn" @@ -74,13 +87,19 @@ result_large_err = "allow" same_functions_in_if_condition = "warn" self_named_module_files = "warn" semicolon_if_nothing_returned = "warn" +should_panic_without_expect = "warn" str_to_string = "warn" string_add = "warn" string_add_assign = "warn" string_lit_as_bytes = "warn" todo = "warn" trait_duplication_in_bounds = "warn" +undocumented_unsafe_blocks = "warn" uninlined_format_args = "warn" +unnecessary_safety_comment = "warn" +unnecessary_safety_doc = "warn" +unseparated_literal_suffix = "warn" +use_self = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" @@ -116,7 +135,7 @@ pre-release-replacements = [ {file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, - {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/rust-cli/rexpect/compare/{{tag_name}}...HEAD", exactly=1}, + {file="CHANGELOG.md", search="", replace="\n[Unreleased]: {{repository}}/compare/{{tag_name}}...HEAD", exactly=1}, ] [features] diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 8f71f43f..6aa81fe0 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright Individual contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/deny.toml b/deny.toml index 27bf59a8..c617b413 100644 --- a/deny.toml +++ b/deny.toml @@ -97,6 +97,7 @@ allow = [ "OpenSSL", "Zlib", "NCSA", + "CDLA-Permissive-2.0", ] # The confidence threshold for detecting a license from license text. # The higher the value, the more closely the license text must be to the diff --git a/src/error.rs b/src/error.rs index 06ae2798..af8c1c4e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,7 +13,7 @@ pub enum Error { #[error("PipeError")] BrokenPipe, - #[error("Timeout Error: Expected {:?} but got {:?} (after waiting {} ms)", .expected, .got, (.timeout.as_secs() * 1000) as u32 + .timeout.subsec_millis())] + #[error("Timeout Error: Expected {:?} but got {:?} (after waiting {} ms)", .expected, .got, (.timeout.as_secs() * 1000) + .timeout.subsec_millis() as u64)] Timeout { expected: String, got: String, diff --git a/src/lib.rs b/src/lib.rs index cc656a03..23843db9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,10 +7,10 @@ //! //! It's main components (depending on your need you can use either of those) //! -//! - [session](session/index.html): automate stuff in Rust -//! - [reader](reader/index.html): a non-blocking reader with buffering, matching on +//! - [session]: automate stuff in Rust +//! - [reader]: a non-blocking reader with buffering, matching on //! strings/regex/... -//! - [process](process/index.html): spawn a process in a pty +//! - [process]: spawn a process in a pty //! //! # Basic example //! diff --git a/src/process.rs b/src/process.rs index 979bd142..bc50c730 100644 --- a/src/process.rs +++ b/src/process.rs @@ -66,9 +66,9 @@ pub struct PtyProcess { use nix::pty::ptsname_r; #[cfg(target_os = "macos")] -/// ptsname_r is a linux extension but ptsname isn't thread-safe +/// `ptsname_r` is a linux extension but ptsname isn't thread-safe /// instead of using a static mutex this calls ioctl with TIOCPTYGNAME directly -/// based on https://blog.tarq.io/ptsname-on-osx-with-rust/ +/// based on / fn ptsname_r(fd: &PtyMaster) -> nix::Result { use nix::libc::{TIOCPTYGNAME, ioctl}; use std::ffi::CStr; @@ -76,6 +76,7 @@ fn ptsname_r(fd: &PtyMaster) -> nix::Result { // the buffer size on OSX is 128, defined by sys/ttycom.h let mut buf: [i8; 128] = [0; 128]; + #[expect(clippy::undocumented_unsafe_blocks, reason = "TODO")] unsafe { match ioctl(fd.as_raw_fd(), TIOCPTYGNAME as u64, &mut buf) { 0 => { @@ -100,6 +101,7 @@ impl PtyProcess { // on Linux this is the libc function, on OSX this is our implementation of ptsname_r let slave_name = ptsname_r(&master_fd)?; + #[expect(clippy::undocumented_unsafe_blocks, reason = "TODO")] match unsafe { fork()? } { ForkResult::Child => { // Avoid leaking master fd @@ -131,7 +133,7 @@ impl PtyProcess { let _ = command.exec(); Err(Error::Nix(nix::Error::last())) } - ForkResult::Parent { child: child_pid } => Ok(PtyProcess { + ForkResult::Parent { child: child_pid } => Ok(Self { pty: master_fd, child_pid, kill_timeout: None, diff --git a/src/reader.rs b/src/reader.rs index b15feeb4..af174e09 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -54,13 +54,13 @@ impl NBReader { /// /// - `f`: file like object /// - `options`: see [`Options`] - pub fn new(f: R, options: Options) -> NBReader { + pub fn new(f: R, options: Options) -> Self { let (tx, rx) = channel(); // spawn a thread which reads one char and sends it to tx thread::spawn(move || -> Result<(), Error> { let mut reader = BufReader::new(f); - let mut byte = [0u8]; + let mut byte = [0_u8]; let mut in_escape_code = false; loop { @@ -94,7 +94,7 @@ impl NBReader { }); // allocate string with a initial capacity of 1024, so when appending chars // we don't need to reallocate memory often - NBReader { + Self { reader: rx, buffer: String::with_capacity(1024), eof: false, @@ -230,19 +230,19 @@ pub enum ReadUntil { /// /// Returns all bytes in second String, first is left empty EOF, - Any(Vec), + Any(Vec), } impl fmt::Display for ReadUntil { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ReadUntil::String(s) if s == "\n" => write!(f, "\\n (newline)"), - ReadUntil::String(s) if s == "\r" => write!(f, "\\r (carriage return)"), - ReadUntil::String(s) => write!(f, "\"{s}\""), - ReadUntil::Regex(r) => write!(f, "Regex: \"{r}\""), - ReadUntil::NBytes(n) => write!(f, "reading {n} bytes"), - ReadUntil::EOF => write!(f, "EOF (End of File)"), - ReadUntil::Any(v) => { + Self::String(s) if s == "\n" => write!(f, "\\n (newline)"), + Self::String(s) if s == "\r" => write!(f, "\\r (carriage return)"), + Self::String(s) => write!(f, "\"{s}\""), + Self::Regex(r) => write!(f, "Regex: \"{r}\""), + Self::NBytes(n) => write!(f, "reading {n} bytes"), + Self::EOF => write!(f, "EOF (End of File)"), + Self::Any(v) => { for (i, r) in v.iter().enumerate() { if i != 0 { write!(f, ", ")?; @@ -310,7 +310,7 @@ enum PipeError { } #[derive(Debug)] -#[allow(clippy::upper_case_acronyms)] +#[expect(clippy::upper_case_acronyms, reason = "compatibility")] enum PipedChar { Char(u8), EOF, diff --git a/src/session.rs b/src/session.rs index c48ae1e2..888ba0f8 100644 --- a/src/session.rs +++ b/src/session.rs @@ -164,7 +164,6 @@ impl StreamSession { } /// Interact with a process with read/write/signals, etc. -#[allow(dead_code)] pub struct PtySession { process: PtyProcess, stream: StreamSession,