mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
30 lines
1,020 B
Python
30 lines
1,020 B
Python
# -*- 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())
|