diff --git a/qutebrowser/__main__.py b/qutebrowser/__main__.py index ba6cd01b9..064a64281 100644 --- a/qutebrowser/__main__.py +++ b/qutebrowser/__main__.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 43360c42f..08b58f708 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -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) # diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index f84ba1f5c..baf1b7f66 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -1,5 +1,7 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + # Copyright 2014 Florian Bruhin (The Compiler) -# + # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify diff --git a/qutebrowser/test/config/test_conftypes.py b/qutebrowser/test/config/test_conftypes.py index f9ffd6f30..174bd9a12 100644 --- a/qutebrowser/test/config/test_conftypes.py +++ b/qutebrowser/test/config/test_conftypes.py @@ -1,5 +1,6 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) -# + # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify diff --git a/qutebrowser/test/utils/test_debug.py b/qutebrowser/test/utils/test_debug.py index c4fb64c9c..975f1c81e 100644 --- a/qutebrowser/test/utils/test_debug.py +++ b/qutebrowser/test/utils/test_debug.py @@ -1,4 +1,6 @@ # Copyright 2014 Florian Bruhin (The Compiler) +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + # # This file is part of qutebrowser. # diff --git a/scripts/cleanup.py b/scripts/cleanup.py index 5119237e0..5a257c732 100755 --- a/scripts/cleanup.py +++ b/scripts/cleanup.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) diff --git a/scripts/freeze.py b/scripts/freeze.py index e53b97316..09541c465 100755 --- a/scripts/freeze.py +++ b/scripts/freeze.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) diff --git a/scripts/generate_doc.py b/scripts/generate_doc.py index 1078b2757..9846d63dd 100755 --- a/scripts/generate_doc.py +++ b/scripts/generate_doc.py @@ -1,7 +1,8 @@ #!/usr/bin/python3 +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) -# + # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify diff --git a/scripts/minimal_webkit_testbrowser.py b/scripts/minimal_webkit_testbrowser.py index 4f758d90d..0cbafaaee 100755 --- a/scripts/minimal_webkit_testbrowser.py +++ b/scripts/minimal_webkit_testbrowser.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) diff --git a/scripts/pylint_checkers/crlf.py b/scripts/pylint_checkers/crlf.py index c3ed1c166..80f5c200f 100644 --- a/scripts/pylint_checkers/crlf.py +++ b/scripts/pylint_checkers/crlf.py @@ -1,3 +1,21 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# 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 . + """Checker for CRLF in files.""" from pylint.interfaces import IRawChecker diff --git a/scripts/pylint_checkers/modeline.py b/scripts/pylint_checkers/modeline.py new file mode 100644 index 000000000..960ec4465 --- /dev/null +++ b/scripts/pylint_checkers/modeline.py @@ -0,0 +1,62 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# 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 . + +"""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)) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index a61a7e72b..01dac33b3 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) @@ -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 diff --git a/scripts/run_profile.py b/scripts/run_profile.py index 4b89fd7e6..6e3dcb389 100755 --- a/scripts/run_profile.py +++ b/scripts/run_profile.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler) diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py index e15d5441b..0684021a1 100644 --- a/scripts/setupcommon.py +++ b/scripts/setupcommon.py @@ -1,5 +1,7 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + # Copyright 2014 Florian Bruhin (The Compiler) -# + # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify diff --git a/scripts/update_3rdparty.py b/scripts/update_3rdparty.py index f570c3f9f..b63a69cd9 100755 --- a/scripts/update_3rdparty.py +++ b/scripts/update_3rdparty.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # Copyright 2014 Florian Bruhin (The Compiler)