Setup gitlint for developers to write well formatted commit messages. Note: .gitlint, gitlint-rules.py and lint-commits are taken directly from zulip/zulip with minor changes.
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
#! /usr/bin/env python3
 | 
						|
 | 
						|
import argparse
 | 
						|
import sys
 | 
						|
 | 
						|
from zulint.command import add_default_linter_arguments, LinterConfig
 | 
						|
 | 
						|
from custom_check import python_rules, non_py_rules
 | 
						|
 | 
						|
EXCLUDED_FILES = [
 | 
						|
    # This is an external file that doesn't comply with our codestyle
 | 
						|
    'zulip/integrations/perforce/git_p4.py',
 | 
						|
]
 | 
						|
 | 
						|
def run() -> None:
 | 
						|
    parser = argparse.ArgumentParser()
 | 
						|
    add_default_linter_arguments(parser)
 | 
						|
    parser.add_argument('--no-gitlint', action='store_true', help='Disable gitlint')
 | 
						|
    args = parser.parse_args()
 | 
						|
 | 
						|
    linter_config = LinterConfig(args)
 | 
						|
 | 
						|
    by_lang = linter_config.list_files(file_types=['py', 'sh', 'json', 'md', 'txt'],
 | 
						|
                                       exclude=EXCLUDED_FILES)
 | 
						|
 | 
						|
    linter_config.external_linter('mypy', [sys.executable, 'tools/run-mypy'], ['py'], pass_targets=False,
 | 
						|
                                  description="Static type checker for Python (config: mypy.ini)")
 | 
						|
    linter_config.external_linter('flake8', ['flake8'], ['py'],
 | 
						|
                                  description="Standard Python linter (config: .flake8)")
 | 
						|
 | 
						|
    if not args.no_gitlint:
 | 
						|
        linter_config.external_linter('gitlint', ['tools/lint-commits'],
 | 
						|
                                      description="Git Lint for commit messages")
 | 
						|
 | 
						|
    @linter_config.lint
 | 
						|
    def custom_py() -> int:
 | 
						|
        """Runs custom checks for python files (config: tools/linter_lib/custom_check.py)"""
 | 
						|
        failed = python_rules.check(by_lang, verbose=args.verbose)
 | 
						|
        return 1 if failed else 0
 | 
						|
 | 
						|
    @linter_config.lint
 | 
						|
    def custom_nonpy() -> int:
 | 
						|
        """Runs custom checks for non-python files (config: tools/linter_lib/custom_check.py)"""
 | 
						|
        failed = False
 | 
						|
        for rule in non_py_rules:
 | 
						|
            failed = failed or rule.check(by_lang, verbose=args.verbose)
 | 
						|
        return 1 if failed else 0
 | 
						|
 | 
						|
    linter_config.do_lint()
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    run()
 |