mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Added loaderon-hooks logic
This commit is contained in:
parent
0b70e285e3
commit
0a66e6635d
23 changed files with 612 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pre_commit_logic.util.template_methods.file_checker_template_method import FileCheckerTemplateMethod
|
||||
from pre_commit_logic.util.file_helpers import read_file_line
|
||||
|
||||
|
||||
class XMLEncodingChecker(FileCheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
super(XMLEncodingChecker, self)._add_arguments_to_parser()
|
||||
self.parser.add_argument('-e', '--encoding', help='Desired encoding.')
|
||||
|
||||
def _check_file(self):
|
||||
first_line = read_file_line(self.filename)
|
||||
desired_encoding = self.args.encoding.rstrip()
|
||||
first_line = first_line.rstrip('\n')
|
||||
if first_line != desired_encoding:
|
||||
self.inform_check_failure(
|
||||
'El archivo {} no comienza con la línea "{}" (verifica también espacios en blanco)'.format(
|
||||
self.filename,
|
||||
desired_encoding
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
return XMLEncodingChecker(argv).run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue