aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2017-07-15 01:07:13 +0000
committerZac Medico <zmedico@gentoo.org>2018-03-29 20:51:19 -0700
commit717f46dff518503282f9440f1ed39fbe7698dcee (patch)
tree16a7e8a88a9d176f3f794e8369b29d33f874a8f4
parentrepoman: New linechecks module, useless (diff)
downloadportage-717f46dff518503282f9440f1ed39fbe7698dcee.tar.gz
portage-717f46dff518503282f9440f1ed39fbe7698dcee.tar.bz2
portage-717f46dff518503282f9440f1ed39fbe7698dcee.zip
repoman: New linechecks module, whitespace
-rw-r--r--repoman/pym/repoman/modules/linechecks/whitespace/__init__.py27
-rw-r--r--repoman/pym/repoman/modules/linechecks/whitespace/blank.py25
-rw-r--r--repoman/pym/repoman/modules/linechecks/whitespace/whitespace.py21
3 files changed, 73 insertions, 0 deletions
diff --git a/repoman/pym/repoman/modules/linechecks/whitespace/__init__.py b/repoman/pym/repoman/modules/linechecks/whitespace/__init__.py
new file mode 100644
index 000000000..ded690ed7
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/whitespace/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Whitespace plug-in module for repoman LineChecks.
+Performs checks for useless whitespace in ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+ 'name': 'do',
+ 'description': doc,
+ 'provides':{
+ 'whitespace-check': {
+ 'name': "whitespace",
+ 'sourcefile': "whitespace",
+ 'class': "EbuildWhitespace",
+ 'description': doc,
+ },
+ 'blankline-check': {
+ 'name': "blankline",
+ 'sourcefile': "blank",
+ 'class': "EbuildBlankLine",
+ 'description': doc,
+ },
+ }
+}
+
diff --git a/repoman/pym/repoman/modules/linechecks/whitespace/blank.py b/repoman/pym/repoman/modules/linechecks/whitespace/blank.py
new file mode 100644
index 000000000..2ab4097a3
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/whitespace/blank.py
@@ -0,0 +1,25 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildBlankLine(LineCheck):
+ repoman_check_name = 'ebuild.minorsyn'
+ ignore_comment = False
+ blank_line = re.compile(r'^$')
+
+ def new(self, pkg):
+ self.line_is_blank = False
+
+ def check(self, num, line):
+ if self.line_is_blank and self.blank_line.match(line):
+ return 'Useless blank line on line: %d'
+ if self.blank_line.match(line):
+ self.line_is_blank = True
+ else:
+ self.line_is_blank = False
+
+ def end(self):
+ if self.line_is_blank:
+ yield 'Useless blank line on last line'
diff --git a/repoman/pym/repoman/modules/linechecks/whitespace/whitespace.py b/repoman/pym/repoman/modules/linechecks/whitespace/whitespace.py
new file mode 100644
index 000000000..556b2ab81
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/whitespace/whitespace.py
@@ -0,0 +1,21 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildWhitespace(LineCheck):
+ """Ensure ebuilds have proper whitespacing"""
+
+ repoman_check_name = 'ebuild.minorsyn'
+
+ ignore_line = re.compile(r'(^$)|(^(\t)*#)')
+ ignore_comment = False
+ leading_spaces = re.compile(r'^[\S\t]')
+ trailing_whitespace = re.compile(r'.*([\S]$)')
+
+ def check(self, num, line):
+ if self.leading_spaces.match(line) is None:
+ return self.errors['LEADING_SPACES_ERROR']
+ if self.trailing_whitespace.match(line) is None:
+ return self.errors['TRAILING_WHITESPACE_ERROR']