Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Rust Fix

Release

Auto-fix Rust code with cargo fmt and clippy.

What it does

StepCommandDescription
1cargo fmtFormat code
2cargo clippy --fixApply clippy autofixes

Before / After Examples

Unused Import

// Beforeuse std::io::Read;// After// (unused import removed automatically)

Missing Derive

// BeforestructConfig{name:String}// After#[derive(Debug)]structConfig{name:String}

Formatting

// Beforefnfoo(){let x=1;}// Afterfnfoo(){let x = 1;}

Clippy Autofixes (examples)

  • redundant_field_names → removes duplicate field names
  • redundant_static_lifetime → removes unnecessary 'static
  • unnecessary_cast → removes unnecessary casts
  • unused_variables → prefixes with _

Workflow Setup

# .github/workflows/rust-auto-fix.ymlname: Rust Auto-Fix Boton:
issue_comment:
types: [created]jobs:
rust-auto-fix-request:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/rust-fix')runs-on: ubuntu-latestpermissions:
contents: readpull-requests: writesteps:
- name: Check fix typeid: checkrun: | comment="${{ github.event.comment.body }}" fixes="" if [[ "$comment" == *"/rust-fix all"* ]]; then fixes="all" elif [[ "$comment" == *"/rust-fix clippy"* ]]; then fixes="clippy" elif [[ "$comment" == *"/rust-fix fmt"* ]]; then fixes="fmt" fi echo "fixes=$fixes" >> $GITHUB_OUTPUT - name: Confirm requestif: steps.check.outputs.fixes != ''uses: actions/github-script@v7with:
script: | await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `Applying: ${{ steps.check.outputs.fixes }}` });rust-auto-fix-execute:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/confirm')runs-on: ubuntu-latestpermissions:
contents: writepull-requests: writesteps:
- uses: actions/checkout@v6with:
token: ${{ secrets.GITHUB_TOKEN }}fetch-depth: 0
- name: Checkout PRrun: gh pr checkout ${{ github.event.issue.number }}env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Apply fixuses: libnudget/rust-fix@v1with:
fixes: all

Trigger Commands

# Comment on PR
/rust-fix fmt # Format only
/rust-fix clippy # Clippy fixes only
/rust-fix all # Both (default)
/confirm # Execute after request

Inputs

InputDescriptionDefaultOptions
fixesType of fixes to applyallfmt, clippy, all

Flow

1. User comments: /rust-fix clippy
→ Bot replies: Applying: clippy
2. User comments: /confirm
→ Workflow runs:
- cargo fmt
- cargo clippy --fix
- git commit & push

Notes

  • Clippy fixes are limited to lints with #[clippy::fix] attribute
  • Not all clippy warnings have autofixes (e.g., needless_range_loop)
  • Workflow requires workflow_dispatch: inputs: for manual triggers

License

MIT

About

Applies Rust code fixes.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors