Use pylint to check modelines and fix them.

This commit is contained in:
Florian Bruhin 2014-08-06 23:51:44 +02:00
parent be21296b38
commit c7ee655750
15 changed files with 95 additions and 18 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,4 +1,4 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#

View File

@ -1,5 +1,7 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,6 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,6 @@
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
#
# This file is part of qutebrowser.
#

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,7 +1,8 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,3 +1,21 @@
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Checker for CRLF in files."""
from pylint.interfaces import IRawChecker

View File

@ -0,0 +1,62 @@
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Checker for vim modelines in files."""
import os.path
from pylint.interfaces import IRawChecker
from pylint.checkers import BaseChecker
class ModelineChecker(BaseChecker):
"""Check for vim modelines in files."""
__implements__ = IRawChecker
name = 'modeline'
msgs = {'W9002': ('Does not have vim modeline', 'modeline-missing', None),
'W9003': ('Modeline is invalid', 'invalid-modeline', None),
'W9004': ('Modeline position is wrong', 'modeline-position', None)}
options = ()
priority = -1
def process_module(self, node):
"""Process the module."""
if os.path.basename(os.path.splitext(node.file)[0]) == '__init__':
return
max_lineno = 1
for (lineno, line) in enumerate(node.file_stream):
if lineno == 1 and line.startswith(b'#!'):
max_lineno += 1
continue
elif line.startswith(b'# vim:'):
if lineno > max_lineno:
self.add_message('modeline-position', line=lineno)
if (line.rstrip() !=
b'# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:'):
self.add_message('invalid-modeline', line=lineno)
break
else:
self.add_message('modeline-missing', line=1)
def register(linter):
"""Register the checker."""
linter.register_checker(ModelineChecker(linter))

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
@ -69,7 +68,8 @@ options = {
'pylint': ['--output-format=colorized', '--reports=no',
'--rcfile=.pylintrc',
'--load-plugins=pylint_checkers.config,'
'pylint_checkers.crlf'],
'pylint_checkers.crlf,'
'pylint_checkers.modeline'],
'flake8': ['--config=.flake8'],
},
}
@ -195,7 +195,6 @@ def check_line(target):
def _check_file(fn):
"""Check a single file for CRLFs, conflict markers and weird whitespace."""
has_modeline = False
ok = True
with open(fn, 'rb') as f:
for line in f:
@ -206,10 +205,6 @@ def _check_file(fn):
fn.endswith('debug.py') or fn.endswith('run_checks.py')):
print("Found set_trace in {}".format(fn))
ok = False
elif line.startswith(b'# vim:'):
has_modeline = True
if not has_modeline:
ok = False
return ok

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>

View File

@ -1,5 +1,7 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>