commit:     340283538afc734790341c78a09742bcd0fc1009
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:06:38 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 30 03:51:19 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=34028353

repoman: New linechecks module, useless

 .../repoman/modules/linechecks/useless/__init__.py | 27 ++++++++++++++++++++++
 .../pym/repoman/modules/linechecks/useless/cd.py   | 24 +++++++++++++++++++
 .../repoman/modules/linechecks/useless/dodoc.py    | 16 +++++++++++++
 3 files changed, 67 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/useless/__init__.py 
b/repoman/pym/repoman/modules/linechecks/useless/__init__.py
new file mode 100644
index 000000000..acc4479f5
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/useless/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Useless plug-in module for repoman LineChecks.
+Performs checks for useless operations on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+       'name': 'do',
+       'description': doc,
+       'provides':{
+               'uselesscds-check': {
+                       'name': "uselesscds",
+                       'sourcefile': "cd",
+                       'class': "EbuildUselessCdS",
+                       'description': doc,
+               },
+               'uselessdodoc-check': {
+                       'name': "uselessdodoc",
+                       'sourcefile': "dodoc",
+                       'class': "EbuildUselessDodoc",
+                       'description': doc,
+               },
+       }
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/useless/cd.py 
b/repoman/pym/repoman/modules/linechecks/useless/cd.py
new file mode 100644
index 000000000..3daa04451
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/useless/cd.py
@@ -0,0 +1,24 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildUselessCdS(LineCheck):
+       """Check for redundant cd ${S} statements"""
+       repoman_check_name = 'ebuild.minorsyn'
+       _src_phases = r'^\s*src_(prepare|configure|compile|install|test)\s*\(\)'
+       method_re = re.compile(_src_phases)
+       cds_re = re.compile(r'^\s*cd\s+("\$(\{S\}|S)"|\$(\{S\}|S))\s')
+
+       def __init__(self, errors):
+               self.errors = errors
+               self.check_next_line = False
+
+       def check(self, num, line):
+               if self.check_next_line:
+                       self.check_next_line = False
+                       if self.cds_re.match(line):
+                               return self.errors['REDUNDANT_CD_S_ERROR']
+               elif self.method_re.match(line):
+                       self.check_next_line = True

diff --git a/repoman/pym/repoman/modules/linechecks/useless/dodoc.py 
b/repoman/pym/repoman/modules/linechecks/useless/dodoc.py
new file mode 100644
index 000000000..502bfbea8
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/useless/dodoc.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildUselessDodoc(LineCheck):
+       """Check ebuild for useless files in dodoc arguments."""
+       repoman_check_name = 'ebuild.minorsyn'
+       uselessdodoc_re = re.compile(
+               
r'^\s*dodoc(\s+|\s+.*\s+)(ABOUT-NLS|COPYING|LICENCE|LICENSE)($|\s)')
+
+       def check(self, num, line):
+               match = self.uselessdodoc_re.match(line)
+               if match:
+                       return "Useless dodoc '%s'" % (match.group(2), ) + " on 
line: %d"

Reply via email to