diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 76146e3..d774519 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -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' diff --git a/pre_commit_hooks/scalafix.py b/pre_commit_hooks/scalafix.py new file mode 100644 index 0000000..f9b3ba3 --- /dev/null +++ b/pre_commit_hooks/scalafix.py @@ -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()) diff --git a/pre_commit_hooks/scalafmt.py b/pre_commit_hooks/scalafmt.py index c0e9e29..0607f5c 100644 --- a/pre_commit_hooks/scalafmt.py +++ b/pre_commit_hooks/scalafmt.py @@ -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') + return scala_fmt if __name__ == '__main__': diff --git a/setup.cfg b/setup.cfg index 9e198a3..3e320c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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