Skip to content

Commit

Permalink
Merge pull request #506 from dataquest-dev/pre_commit
Browse files Browse the repository at this point in the history
use checkstyle before commit
  • Loading branch information
vidiecan authored Feb 2, 2024
2 parents 93978f8 + a623f9a commit f4dff5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: mvn-checkstyle
verbose: true
entry: python scripts/pre-commit/checkstyle.py
name: Runs maven checkstyle
language: python
files: \.(java)$
23 changes: 23 additions & 0 deletions scripts/pre-commit/checkstyle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import logging
import subprocess

_logger = logging.getLogger()
logging.basicConfig(format='%(message)s', level=logging.DEBUG)


if __name__ == '__main__':
files = [x for x in sys.argv[1:] if x.lower().endswith('java')]
_logger.info(f'Found [{len(files)}] files from [{len(sys.argv) - 1}] input files')

cmd = "mvn checkstyle:check"

try:
with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, text=True) as process:
for line in process.stdout:
print(line, end='')
except Exception as e:
_logger.critical(f'Error: {repr(e)}, ret code: {e.returncode}')

# for filename in files:
# pass

0 comments on commit f4dff5d

Please sign in to comment.