summaryrefslogtreecommitdiff
path: root/.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py
diff options
context:
space:
mode:
authorVito Graffagnino <vito@graffagnino.xyz>2020-09-08 18:10:49 +0100
committerVito Graffagnino <vito@graffagnino.xyz>2020-09-08 18:10:49 +0100
commit3b0142cedcde39e4c2097ecd916a870a3ced5ec6 (patch)
tree2116c49a845dfc0945778f2aa3e2118d72be428b /.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py
parent8cc927e930d5b6aafe3e9862a61e81705479a1b4 (diff)
Added the relevent parts of the .config directory. Alss add ssh config
Diffstat (limited to '.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py')
-rw-r--r--.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py b/.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py
new file mode 100644
index 0000000..429974c
--- /dev/null
+++ b/.config/qutebrowser/scripts/dev/pylint_checkers/qute_pylint/modeline.py
@@ -0,0 +1,63 @@
+# Copyright 2014-2018 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
+import contextlib
+
+from pylint import interfaces, checkers
+
+
+class ModelineChecker(checkers.BaseChecker):
+
+ """Check for vim modelines in files."""
+
+ __implements__ = interfaces.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
+ with contextlib.closing(node.stream()) as stream:
+ for (lineno, line) in enumerate(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 '
+ b'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))