Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See if styler could be used to automatically format content (and PRs) #359

Open
fmichonneau opened this issue Jan 31, 2018 · 3 comments
Open
Assignees
Labels
help wanted Looking for Contributors type:template and tools Issue about template and tools

Comments

@fmichonneau
Copy link
Member

https://github.com/r-lib/styler

it would reduce nitpicking on contributions while maintaining consistent formatting across the lesson

@fmichonneau fmichonneau self-assigned this Jan 31, 2018
@fmichonneau fmichonneau added status:need-contributor type:template and tools Issue about template and tools and removed technical labels Mar 9, 2018
@fmichonneau fmichonneau added help wanted Looking for Contributors and removed help wanted Looking for Contributors status:need-contributor labels Apr 9, 2018
@ErinBecker ErinBecker added this to the June 2019 Release milestone May 14, 2019
@katrinleinweber
Copy link
Contributor

Also, implementing this would support git-novice/09-conflict's advice to "use code style tools".

@Teebusch
Copy link
Contributor

Teebusch commented Dec 3, 2020

I believe there is now a github action template for auto-styling pull requests: https://github.com/r-lib/actions/tree/master/examples#commands-workflow
It can be added to the repository with usethis::use_github_action_pr_commands(open = TRUE)

@Teebusch
Copy link
Contributor

Teebusch commented Jul 8, 2021

I've modified the workflow from the example a bit. I believe, we need something like this -- it automatically styles the .Rmd and .R files for each new PR. At least, that's what I think it does. I haven't tested it...

# github/workflows/format-r-code.yml

name: format-r-code
on: [pull_request]
jobs:
  style:
    runs-on: macOS-latest
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v2
      - uses: r-lib/actions/pr-fetch@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
      - uses: r-lib/actions/setup-r@v1
      - name: Install dependencies
        run: Rscript -e 'install.packages("styler")'
      - name: Style
        run: Rscript -e 'styler::style_dir(filetype = c("R", "Rmd"))'
      - name: commit
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Actions"
          git add \*.R
          git add \*.Rmd
          git commit -m 'Style'
      - uses: r-lib/actions/pr-push@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

(reference for style_dir() function)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Looking for Contributors type:template and tools Issue about template and tools
Projects
None yet
Development

No branches or pull requests

4 participants