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

Added new hook for scalafix #8

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@
pass_filenames: false
always_run: true
minimum_pre_commit_version: '0.19.0'
- id: sbt-scalafix
name: scalafix linting check
stages: [commit,push]
language: python_venv
entry: scalafix
pass_filenames: false
always_run: true
minimum_pre_commit_version: '0.3.6'
18 changes: 18 additions & 0 deletions pre_commit_hooks/scalafix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pre_commit_hooks.runner import run_sbt_command
from colorama import init as colorama_init, Fore

TASK_SCALAFIX = 'scalafixAll --check'
MISSING_PLUGIN_CHECK_STRING = 'Not a valid key: scalafixAll'
MISSING_PLUGIN_ERROR_MSG = f'{Fore.RED}ERROR: scalafix SBT plugin not present! See {Fore.BLUE}https://scalacenter.github.io/scalafix/docs/users/installation.html{Fore.RED} for installation instructions.'


def main(argv=None):
colorama_init()

scala_fix = run_sbt_command(f'; clean; {TASK_SCALAFIX}', MISSING_PLUGIN_CHECK_STRING, MISSING_PLUGIN_ERROR_MSG)
run_sbt_command("compile")
return scala_fix


if __name__ == '__main__':
exit(main())
4 changes: 3 additions & 1 deletion pre_commit_hooks/scalafmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def main(argv=None):
colorama_init()

return run_sbt_command(f'; clean ; {TASK_SCALAFMT}', MISSING_PLUGIN_CHECK_STRING, MISSING_PLUGIN_ERROR_MSG)
scala_fmt = run_sbt_command(f'; clean; {TASK_SCALAFMT}', MISSING_PLUGIN_CHECK_STRING, MISSING_PLUGIN_ERROR_MSG)
run_sbt_command('compile')
Copy link

Choose a reason for hiding this comment

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

Why compile here?

return scala_fmt


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ python_requires = >=3.6
console_scripts =
sbt-wartremover = pre_commit_hooks.sbt_wartremover:main
scalafmt = pre_commit_hooks.scalafmt:main
scalafix = pre_commit_hooks.scalafix:main
sbt-fatal-warnings = pre_commit_hooks.sbt_fatal_warnings:main