[namcap,3/4] nonuniquesources: Also warn on common filenames not overriding name to be unique

Message ID 20190527034922.27316-4-jamespharvey20@gmail.com
State New
Headers show
Series
  • Add a rule against common filenames in source() without overridden name
Related show

Commit Message

Eli Schwartz via arch-projects May 27, 2019, 3:49 a.m. UTC
Filenames in source() are required to be unique.  A common violation of
this is from commonly named files (i.e. LICENSE) that aren't part of an
upstream tarball.

Warn if a source file doesn't have an overriding name, and has a
commonly used name, ignoring extension and case.

Signed-off-by: James P. Harvey <jamespharvey20@gmail.com>
---
 Namcap/rules/nonuniquesources.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Patch

diff --git a/Namcap/rules/nonuniquesources.py b/Namcap/rules/nonuniquesources.py
index a16f56e..8d8afcd 100644
--- a/Namcap/rules/nonuniquesources.py
+++ b/Namcap/rules/nonuniquesources.py
@@ -26,9 +26,27 @@  from Namcap.ruleclass import PkgbuildRule
 class nonuniquesources(PkgbuildRule):
 	name = "nonuniquesources"
 	description = "Verifies the downloaded sources have a unique filename"
+
 	def analyze(self, pkginfo, tar):
+		filename_begins_upper_case = [
+			"AUTHORS",
+			"CHANGELOG",
+			"CONTRIBUTING",
+			"COPYING",
+			"COPYRIGHT",
+			"HACKING",
+			"HISTORY",
+			"LICENSE",
+			"NEWS",
+			"README",
+			"TODO"
+		]
+
 		for source_file in pkginfo["source"]:
-			if '::' not in source_file and re.match(r'^[vV]?(([0-9]){8}|([0-9]+\.?)+)\.', os.path.basename(source_file)):
-				self.warnings.append(("non-unique-source-name %s", os.path.basename(source_file)))
+			if '::' not in source_file:
+				basename = os.path.basename(source_file)
+				if re.match(r'^[vV]?(([0-9]){8}|([0-9]+\.?)+)\.', basename) \
+						or basename.upper().split('.')[0] in filename_begins_upper_case:
+					self.warnings.append(("non-unique-source-name %s", basename))
 
 # vim: set ts=4 sw=4 noet: