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

Dont redundantly scalafmt on compile #1135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdedetrich
Copy link
Contributor

@mdedetrich mdedetrich commented Aug 29, 2021

This opts for checking scalafmt when a PR is opened rather than doing it on compile. This can be considered a subjective change however here is my personal reasoning

  • Doing format on compile significantly impacts IDE/editor performance when working on the codebase. Since editors/IDE's index/track source files, its more ideal to do this once then every time you compile (especially for a language like Scala where you do frequently compile just to check your code is correct). Furthemore some editors such as Intellij can sometimes report file conflicts when a formatted file is quickly edited.
  • Doing a double check of both formatting and checking on compile can be considered redundant. In terms of practicality you don't really care that much if a PR in progress is not formatted, you only want to make sure that code is formatted in the final step before merging.

Note that the PR removes using scalafmt in ci.yaml and instead creates it as a separate pipeline that uses scalafmt-native. This has the following advantages

  • scalafmt-native is significantly faster than standard scalafmt in sbt (I haven't seen it ever take longer than 10 seconds on massive codebases)
  • it runs in parallel to the main compile/test rather than sequentially. For the same reason it also doesn't block the build/test if your code is formatted (it only blocks the merging of the PR). This gives you quick feedback that the code isn't formatted.

Note that I have submitted this kind of scalafmt checking on numerous Scala projects and there haven't been any issues.

- name: Check project is formatted
uses: jrouly/scalafmt-native-action@v1
with:
version: '3.0.1'
Copy link
Contributor Author

@mdedetrich mdedetrich Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific github action will automatically work when a new scalafmt version comes out, i.e. you are not blocked when a new scalafmt is released due to the maintainer having to manually release a new version of the plugin.

@mdedetrich mdedetrich force-pushed the check-scalafmt-on-pr-insead-of-compile branch from e2709f9 to 8230f0a Compare August 29, 2021 17:35
@mdedetrich mdedetrich changed the title Check scalafmt on compile instead of PR Dont redundantly scalafmt on compile Aug 29, 2021
@mdedetrich mdedetrich force-pushed the check-scalafmt-on-pr-insead-of-compile branch from 8230f0a to d0c8228 Compare August 29, 2021 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant