[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-8-g1144b47



The following commit has been merged in the master branch:
commit 1144b47acd967552ff9c094a581de8f710c541b8
Author: Niels Thykier <niels@thykier.net>
Date:   Tue Jul 10 16:33:50 2012 +0200

    c/source-cpy: Check for common misspelled field names
    
    Use "Levenshtein edit distance" to detect misspelled field names in
    DEP-5 copyright files.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/source-copyright b/checks/source-copyright
index fea9e44..916dadd 100644
--- a/checks/source-copyright
+++ b/checks/source-copyright
@@ -23,6 +23,8 @@ package Lintian::source_copyright;
 use strict;
 use warnings;
 
+use Text::Levenshtein qw(distance);
+
 use Lintian::Relation::Version qw(versions_compare);
 use Lintian::Tags qw(tag);
 use Lintian::Util qw(parse_dpkg_control slurp_entire_file fail);
@@ -167,8 +169,8 @@ if (@dep5) {
     my $i = 0;
     for my $para (@dep5) {
         $i++;
-        my $license = $para->{'license'};
-        my $files = $para->{'files'};
+        my $license = get_field ($para, 'license');
+        my $files = get_field ($para, 'files');
         if (defined $license and not defined $files) {
             # Standalone license paragraph
             if (not $license =~ m/\n/) {
@@ -190,7 +192,7 @@ if (@dep5) {
             else {
                 tag 'missing-field-in-dep5-copyright', "license (paragraph at line $lines[$i])";
             }
-            if (not defined $para->{'copyright'}) {
+            if (not defined get_field ($para, 'copyright')) {
                 tag 'missing-field-in-dep5-copyright', "copyright (paragraph at line $lines[$i])";
             }
         }
@@ -224,6 +226,19 @@ sub split_licenses {
     return map "\L$_", (split /\s++(?:and|or)\s++/);
 }
 
+sub get_field {
+    my ($para, $field) = @_;
+    return $para->{$field} if exists $para->{$field};
+    # Fall back to a "likely misspelling" of the field.
+    foreach my $f (sort keys %$para) {
+        if (distance ($field, $f) < 3) {
+            tag 'field-name-typo-in-dep5-copyright', $f, '->', $field;
+            return $para->{$f};
+        }
+    }
+    return;
+}
+
 1;
 
 # Local Variables:
diff --git a/checks/source-copyright.desc b/checks/source-copyright.desc
index 4a6ff26..d6c98f8 100644
--- a/checks/source-copyright.desc
+++ b/checks/source-copyright.desc
@@ -132,3 +132,16 @@ Certainty: possible
 Ref: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 Info: The machine-readable copyright file contains a paragraph that is neither
  a standalone license paragraph nor a files paragraph.
+
+Tag: field-name-typo-in-dep5-copyright
+Severity: normal
+Certainty: possible
+Info: The listed field name is a likely misspelling of one of the documented
+ DEP-5 fields.
+ .
+ Lintian will continue by using the "misspelled" variant, but other parsers
+ are unlikely to do so.
+ .
+ Implementation detail: The typo is detected by using "Levenshtein
+ edit distance".  Therefore, if the typo involve several characters,
+ Lintian may not detect it.
diff --git a/debian/changelog b/debian/changelog
index 576e830..ae6b29b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 lintian (2.5.11) UNRELEASED; urgency=low
 
   * Summary of tag changes:
+    + Added:
+      - field-name-typo-in-dep5-copyright
     + Removed:
       - data.tar.xz-member-without-dpkg-pre-depends
 
@@ -17,10 +19,16 @@ lintian (2.5.11) UNRELEASED; urgency=low
       setting MANROFFSEQ to the empty string when calling man.
     + [CW,NT] Pass -Tutf8 -Z to man to skip an unused part of
       the groff pipeline.
+  * checks/source-copyright{,.desc}:
+    + [NT] Check for possible misspellings of known field
+      names.  (Closes: #678639)
 
   * data/doc-base/sections:
     + [NT] Update section list.  (Closes: #678650)
 
+  * debian/control:
+    + [NT] Add (Build-)Depends on libtext-levenshtein-perl.
+
  -- Niels Thykier <niels@thykier.net>  Tue, 10 Jul 2012 13:21:56 +0200
 
 lintian (2.5.10) unstable; urgency=low
diff --git a/debian/control b/debian/control
index 1265b43..c02c378 100644
--- a/debian/control
+++ b/debian/control
@@ -39,6 +39,7 @@ Build-Depends: binutils,
                libtest-pod-perl,
                libtest-strict-perl,
                libtest-synopsis-perl,
+               libtext-levenshtein-perl,
                libtext-template-perl,
                libtimedate-perl,
                liburi-perl,
@@ -78,6 +79,7 @@ Depends: binutils,
          libemail-valid-perl,
          libipc-run-perl,
          libparse-debianchangelog-perl,
+         libtext-levenshtein-perl,
          libtimedate-perl,
          liburi-perl,
          man-db,
diff --git a/t/COVERAGE b/t/COVERAGE
index 7aef2b5..7005c28 100644
--- a/t/COVERAGE
+++ b/t/COVERAGE
@@ -1,5 +1,5 @@
-Last generated 2012-04-23
-Coverage: 811/964 (84.13%), w. legacy tests: 916/964 (95.02%)
+Last generated 2012-07-10
+Coverage: 812/965 (84.15%), w. legacy tests: 917/965 (95.03%)
 
 The following tags are not tested by the test suite:
 
diff --git a/t/tests/source-copyright-unversioned-uri/debian/debian/copyright b/t/tests/source-copyright-typo-field/debian/debian/copyright
similarity index 85%
copy from t/tests/source-copyright-unversioned-uri/debian/debian/copyright
copy to t/tests/source-copyright-typo-field/debian/debian/copyright
index cf66541..d9c4158 100644
--- a/t/tests/source-copyright-unversioned-uri/debian/debian/copyright
+++ b/t/tests/source-copyright-typo-field/debian/debian/copyright
@@ -1,11 +1,11 @@
-Format: http://dep.debian.net/deps/dep5/
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 Upstream-Name: Doohickey
 Upstream-Contact: J. Random Hacker <j.r.hacker@example.com>
 Source: http://examples.com/doohickey/source/
 
-Files: *
-Copyright: 2011 J. Random Hacker <j.r.hacker@example.com>
-License: GPL-2
+File: *
+Copyrigth: © 2011 J. Random Hacker <j.r.hacker@example.com>
+Licens: GPL-2
  This package 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; version 2 dated June, 1991.
diff --git a/t/tests/source-copyright-typo-field/desc b/t/tests/source-copyright-typo-field/desc
new file mode 100644
index 0000000..bf75453
--- /dev/null
+++ b/t/tests/source-copyright-typo-field/desc
@@ -0,0 +1,5 @@
+Testname: source-copyright-typo-field
+Sequence: 6000
+Version: 1.0
+Description: Test for typo in DEP-5 field name
+Test-For: field-name-typo-in-dep5-copyright
diff --git a/t/tests/source-copyright-typo-field/tags b/t/tests/source-copyright-typo-field/tags
new file mode 100644
index 0000000..6e55e63
--- /dev/null
+++ b/t/tests/source-copyright-typo-field/tags
@@ -0,0 +1,3 @@
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright copyrigth -> copyright
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright file -> files
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright licens -> license

-- 
Debian package checker


Reply to: