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

Run scalafmt in CI and in pre-commit hook #1710

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Commits on Oct 25, 2024

  1. Run scalafmt in CI

    Now that this repo is using prettier to check formatting in CI, why not
    also check scala formatting? This commit adds a check in CI that runs
    scalafmt via an sbt plugin, copying the approach from
    guardian/datawrapper-import#12
    
    I’ll also add a pre-commit hook shortly, and format the existing code.
    I’ll probably choose a formatting style that uses tabs for indentation,
    to be consistent with the frontend code (and given the accessibility
    motivations for using tabs for indentation).
    emdash-ie committed Oct 25, 2024
    Configuration menu
    Copy the full SHA
    bc94ddd View commit details
    Browse the repository at this point in the history
  2. Add .scalafmt.conf

    Scalafmt needs this file in order to run! These are the minimal config
    values required.
    
    Unfortunately, it looks like scalafmt doesn’t support using tabs for
    indentation: we’ll go with spaces for now but I’ll raise an issue with
    them requesting a config for using tabs. I reckon there are strong
    accessibility arguments in favour of tabs, so I’m hopeful I can convince
    them.
    emdash-ie committed Oct 25, 2024
    Configuration menu
    Copy the full SHA
    6cf11c6 View commit details
    Browse the repository at this point in the history
  3. Run scalafmt on everything

    emdash-ie committed Oct 25, 2024
    Configuration menu
    Copy the full SHA
    96296b5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    241199e View commit details
    Browse the repository at this point in the history
  5. Update pre-commit hook to check scala formatting

    This commit updates the pre-commit hook to run scalafmt the same way it
    already runs prettier. Apart from the exit code tweak, this basically
    involved copying the pre-commit hook from
    guardian/datawrapper-import#12
    
    As with the prettier part of the hook, this should only run the
    formatter on files with staged changes that don’t have unstaged changes,
    and for any with both that fail formatting it should just report an
    error and exit.
    
    (I’ve also replaced the word “clobbering” with “overwriting”, because I
    think it’s a less obscure phrasing.)
    emdash-ie committed Oct 25, 2024
    Configuration menu
    Copy the full SHA
    cf7464c View commit details
    Browse the repository at this point in the history