DOI-USGS / dataRetrieval

This R package is designed to obtain USGS or EPA water quality sample data, streamflow data, and metadata directly from web services.
https://doi-usgs.github.io/dataRetrieval/
Other
256 stars 85 forks source link

GitHub Actions to Automatically Style and Lint PRs #637

Closed elbeejay closed 1 year ago

elbeejay commented 1 year ago

Thought Process and Summary

I've thought a bit about how to best accomplish some standard styling and linting for this package. After exploring a few different avenues, I think what makes the most sense is to have a GitHub Action that does the following:

  1. Automatically style feature branches (using styler) when pull requests are opened by pushing a commit to the feature branch itself. This eases the burden on contributors styling their own code either while writing it or by running styler locally, and ensures consistent style as new contributions are made. This strategy also avoids automated style commits from being made directly on the main branch, which seems wise just in-case the style changes do something unexpected.
  2. Run lintr after styling the code and annotate the GitHub Action associated with the pull request. The linter captures some things that are not strictly code style, such as instances when variables are assigned and not used. Again, by doing this to the feature branch in the PR, changes can be caught and considered prior to merging into main

This PR

This PR establishes a .lintr style file which controls some aspects of the linting. In particular, we are not enforcing the following through the linter:

This PR also establishes a new GitHub Actions .yaml file called style-and-lint.yaml which is run when a PR is opened to the main branch and involves changes to files containing R code. This action does the processes summarized above:

Impact of automatic styling

The first run of the automated styling is going to impact a lot of code. I've run the styler locally on the repository and pushed it up to my branch using-lintr so a diff can be compared between that feature branch and the current main branch if desired. I've looked through some of the diff, and the changes are, as far as I can tell, entirely cosmetic and involve spacing, " vs ' quotes, and things of that nature. I ran lintr locally on the stylized package as well and got a handful of suggestions that fell into the following categories:

I did not take any action to address any of those linter suggestions because I suspect the choices made in dataRetrieval are often deliberately made. I think making any of those changes would require some extra care, which I view as beyond the scope of this simple automated styling and linting PR.


I'm of course open to discussion and altering this approach. Some alternative processes I considered and dismissed were: