pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint pkgtools/pkglint: update to 5.7.0



details:   https://anonhg.NetBSD.org/pkgsrc/rev/7f1e5a3b8387
branches:  trunk
changeset: 319830:7f1e5a3b8387
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Feb 21 22:49:03 2019 +0000

description:
pkgtools/pkglint: update to 5.7.0

Changes since 5.6.12:

* Many of the -C and -W command line options have been removed since
  they are not used in practice. The -Wall and -Call options continue
  to work though; these are the only options mentioned in the pkgsrc
  guide.

* When a PLIST file contains redundant libtool libraries (.la and the
  corresponding .so), there is only a single warning per file.

* Warnings about the package COMMENT are now strictly ordered from left
  to right.

* The hashes for all distfiles must now contain the SHA512 hash. This
  hash has been added to many distfiles in 2015. It's time now to
  enforce it on all other distfiles as well.

* Makefile fragments that are included inside an .elif exists(...)
  are not reported as missing.

* The check for redundant variables and accidentally overwritten
  variables has been improved. Now the warning occurs at the later
  definition. This especially applies to cases where a file is included
  and after that, some of its variables are overridden. Variables in
  unrelated files are no longer marked as redundant.

* When a package contains multiple definitions of a single variable
  (typical for Makefile.common), the later definition overrides the
  earlier definition. That way, the location of DISTINFO_FILE and
  PATCHDIR is resolved correctly.

diffstat:

 pkgtools/pkglint/Makefile                     |    4 +-
 pkgtools/pkglint/files/alternatives_test.go   |   20 +
 pkgtools/pkglint/files/autofix.go             |   77 +++---
 pkgtools/pkglint/files/autofix_test.go        |  262 ++++++++++++++++++++++++
 pkgtools/pkglint/files/buildlink3.go          |    3 +-
 pkgtools/pkglint/files/buildlink3_test.go     |  186 +++++++++++++++++
 pkgtools/pkglint/files/category.go            |    2 +-
 pkgtools/pkglint/files/category_test.go       |  138 +++++++++++++
 pkgtools/pkglint/files/check_test.go          |   18 +-
 pkgtools/pkglint/files/distinfo.go            |   51 +---
 pkgtools/pkglint/files/distinfo_test.go       |   91 ++++++++-
 pkgtools/pkglint/files/files.go               |    2 +-
 pkgtools/pkglint/files/getopt/getopt.go       |   37 +++
 pkgtools/pkglint/files/licenses.go            |    4 +-
 pkgtools/pkglint/files/line.go                |   17 +-
 pkgtools/pkglint/files/line_test.go           |   17 +
 pkgtools/pkglint/files/linelexer.go           |   23 +-
 pkgtools/pkglint/files/linelexer_test.go      |   15 +
 pkgtools/pkglint/files/lines_test.go          |   11 +
 pkgtools/pkglint/files/logging.go             |   15 +-
 pkgtools/pkglint/files/logging_test.go        |   75 ++++++-
 pkgtools/pkglint/files/mkline.go              |  100 +++++---
 pkgtools/pkglint/files/mkline_test.go         |  196 +++++++++++++++++-
 pkgtools/pkglint/files/mklinechecker.go       |   24 +-
 pkgtools/pkglint/files/mklinechecker_test.go  |  276 ++++++++++++++++++++++---
 pkgtools/pkglint/files/mklines.go             |    7 +-
 pkgtools/pkglint/files/mklines_test.go        |  101 ++------
 pkgtools/pkglint/files/mkparser.go            |   14 +-
 pkgtools/pkglint/files/mkparser_test.go       |   19 +-
 pkgtools/pkglint/files/mktypes.go             |    5 +-
 pkgtools/pkglint/files/options.go             |   30 +-
 pkgtools/pkglint/files/options_test.go        |   41 +++
 pkgtools/pkglint/files/package.go             |   58 +++-
 pkgtools/pkglint/files/package_test.go        |  118 ++++++++---
 pkgtools/pkglint/files/patches.go             |    2 +-
 pkgtools/pkglint/files/pkglint.0              |   60 +----
 pkgtools/pkglint/files/pkglint.1              |   56 +----
 pkgtools/pkglint/files/pkglint.go             |  120 +++--------
 pkgtools/pkglint/files/pkglint_test.go        |   38 +--
 pkgtools/pkglint/files/pkgsrc.go              |   28 +-
 pkgtools/pkglint/files/pkgsrc_test.go         |   44 ++++
 pkgtools/pkglint/files/plist.go               |   26 +-
 pkgtools/pkglint/files/plist_test.go          |   24 +-
 pkgtools/pkglint/files/shell_test.go          |   22 +-
 pkgtools/pkglint/files/substcontext_test.go   |   31 +-
 pkgtools/pkglint/files/textproc/lexer.go      |    1 +
 pkgtools/pkglint/files/textproc/lexer_test.go |   12 +
 pkgtools/pkglint/files/toplevel.go            |    4 +-
 pkgtools/pkglint/files/trace/tracing.go       |   26 ++-
 pkgtools/pkglint/files/util.go                |  192 ++++++++++++++---
 pkgtools/pkglint/files/util_test.go           |   67 ++++++-
 pkgtools/pkglint/files/vartypecheck.go        |   16 +-
 pkgtools/pkglint/files/vartypecheck_test.go   |   11 +-
 53 files changed, 2151 insertions(+), 686 deletions(-)

diffs (truncated from 4748 to 300 lines):

diff -r e4b0917a7fdd -r 7f1e5a3b8387 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Thu Feb 21 18:52:31 2019 +0000
+++ b/pkgtools/pkglint/Makefile Thu Feb 21 22:49:03 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.566 2019/01/26 16:31:33 rillig Exp $
+# $NetBSD: Makefile,v 1.567 2019/02/21 22:49:03 rillig Exp $
 
-PKGNAME=       pkglint-5.6.12
+PKGNAME=       pkglint-5.7.0
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r e4b0917a7fdd -r 7f1e5a3b8387 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Thu Feb 21 18:52:31 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Thu Feb 21 22:49:03 2019 +0000
@@ -59,3 +59,23 @@
        t.CheckOutputLines(
                "ERROR: ALTERNATIVES: Must not be empty.")
 }
+
+func (s *Suite) Test_CheckFileAlternatives__ALTERNATIVES_SRC(c *check.C) {
+       t := s.Init(c)
+
+       // It's a strange situation, having an ALTERNATIVES file defined by
+       // the package but then referring to another package's file by means
+       // of ALTERNATIVES_SRC. As of February 2019 I don't remember if I
+       // really had this case in mind when I initially wrote the code in
+       // CheckFileAlternatives.
+       t.SetUpPackage("category/package",
+               "ALTERNATIVES_SRC=\talts")
+       t.CreateFileLines("category/package/ALTERNATIVES",
+               "bin/pgm @PREFIX@/bin/gnu-program",
+               "bin/pgm @PREFIX@/bin/nb-program")
+       G.Pkgsrc.LoadInfrastructure()
+
+       G.Check(t.File("category/package"))
+
+       t.CheckOutputEmpty()
+}
diff -r e4b0917a7fdd -r 7f1e5a3b8387 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Thu Feb 21 18:52:31 2019 +0000
+++ b/pkgtools/pkglint/files/autofix.go Thu Feb 21 22:49:03 2019 +0000
@@ -96,15 +96,13 @@
        }
 
        for _, rawLine := range fix.line.raw {
-               if rawLine.Lineno != 0 {
-                       replaced := strings.Replace(rawLine.textnl, prefix+from, prefix+to, 1)
-                       if replaced != rawLine.textnl {
-                               if G.Logger.IsAutofix() {
-                                       rawLine.textnl = replaced
-                               }
-                               fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
-                               return
+               replaced := strings.Replace(rawLine.textnl, prefix+from, prefix+to, 1)
+               if replaced != rawLine.textnl {
+                       if G.Logger.IsAutofix() {
+                               rawLine.textnl = replaced
                        }
+                       fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
+                       return
                }
        }
 }
@@ -122,26 +120,24 @@
 
        done := 0
        for _, rawLine := range fix.line.raw {
-               if rawLine.Lineno != 0 {
-                       var froms []string // The strings that have actually changed
+               var froms []string // The strings that have actually changed
 
-                       replace := func(fromText string) string {
-                               if howOften >= 0 && done >= howOften {
-                                       return fromText
-                               }
-                               froms = append(froms, fromText)
-                               done++
-                               return toText
+               replace := func(fromText string) string {
+                       if howOften >= 0 && done >= howOften {
+                               return fromText
                        }
+                       froms = append(froms, fromText)
+                       done++
+                       return toText
+               }
 
-                       replaced := replaceAllFunc(rawLine.textnl, from, replace)
-                       if replaced != rawLine.textnl {
-                               if G.Logger.IsAutofix() {
-                                       rawLine.textnl = replaced
-                               }
-                               for _, fromText := range froms {
-                                       fix.Describef(rawLine.Lineno, "Replacing %q with %q.", fromText, toText)
-                               }
+               replaced := replaceAllFunc(rawLine.textnl, from, replace)
+               if replaced != rawLine.textnl {
+                       if G.Logger.IsAutofix() {
+                               rawLine.textnl = replaced
+                       }
+                       for _, fromText := range froms {
+                               fix.Describef(rawLine.Lineno, "Replacing %q with %q.", fromText, toText)
                        }
                }
        }
@@ -231,9 +227,10 @@
 }
 
 // Anyway has the effect of showing the diagnostic even when nothing can
-// be fixed automatically.
+// be fixed automatically, but only if neither --show-autofix nor
+// --autofix mode is given.
 func (fix *Autofix) Anyway() {
-       fix.anyway = true
+       fix.anyway = !G.Logger.IsAutofix()
 }
 
 // Apply does the actual work.
@@ -262,21 +259,25 @@
                fix.autofixShortTerm = autofixShortTerm{}
        }
 
-       if !G.Logger.Relevant(fix.diagFormat) || !fix.anyway && len(fix.actions) == 0 {
+       if !(G.Logger.Relevant(fix.diagFormat) && (len(fix.actions) > 0 || fix.anyway)) {
                reset()
                return
        }
 
-       logDiagnostic := (G.Logger.Opts.ShowAutofix || !G.Logger.Opts.Autofix) &&
-               fix.diagFormat != SilentAutofixFormat
+       logDiagnostic := true
+       switch {
+       case fix.diagFormat == SilentAutofixFormat:
+               logDiagnostic = false
+       case G.Logger.Opts.Autofix && !G.Logger.Opts.ShowAutofix:
+               logDiagnostic = false
+       }
+
        logFix := G.Logger.IsAutofix()
 
        if logDiagnostic {
                msg := sprintf(fix.diagFormat, fix.diagArgs...)
-               if !logFix {
-                       if fix.diagFormat == AutofixFormat || G.Logger.FirstTime(line.Filename, line.Linenos(), msg) {
-                               line.showSource(G.out)
-                       }
+               if !logFix && G.Logger.FirstTime(line.Filename, line.Linenos(), msg) {
+                       line.showSource(G.out)
                }
                G.Logf(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
        }
@@ -299,7 +300,7 @@
                        G.Explain(fix.explanation...)
                }
                if G.Logger.Opts.ShowSource {
-                       if !G.Logger.Opts.Explain || !logDiagnostic || len(fix.explanation) == 0 {
+                       if !(G.Logger.Opts.Explain && logDiagnostic && len(fix.explanation) > 0) {
                                G.out.Separate()
                        }
                }
@@ -327,8 +328,8 @@
        {
                // Parsing the continuation marker as variable value is cheating but works well.
                text := strings.TrimSuffix(mkline.raw[0].orignl, "\n")
-               m, _, _, _, _, valueAlign, value, _, _ := MatchVarassign(text)
-               if m && value != "\\" {
+               _, _, _, _, _, valueAlign, value, _, _ := MatchVarassign(text)
+               if value != "\\" {
                        oldWidth = tabWidth(valueAlign)
                }
        }
@@ -336,7 +337,7 @@
        for _, rawLine := range fix.line.raw[1:] {
                _, comment, space := match2(rawLine.textnl, `^(#?)([ \t]*)`)
                width := tabWidth(comment + space)
-               if (oldWidth == 0 || width < oldWidth) && width >= 8 && rawLine.textnl != "\n" {
+               if (oldWidth == 0 || width < oldWidth) && width >= 8 {
                        oldWidth = width
                }
                if !matches(space, `^\t* {0,7}$`) {
diff -r e4b0917a7fdd -r 7f1e5a3b8387 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Thu Feb 21 18:52:31 2019 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Thu Feb 21 22:49:03 2019 +0000
@@ -210,6 +210,35 @@
                "+\tYXXXX")
 }
 
+// When an autofix replaces text, it does not touch those
+// lines that have been inserted before since these are
+// usually already correct.
+func (s *Suite) Test_Autofix_ReplaceAfter__after_inserting_a_line(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("--show-autofix")
+       line := t.NewLine("filename", 5, "initial text")
+
+       fix := line.Autofix()
+       fix.Notef("Inserting a line.")
+       fix.InsertBefore("line before")
+       fix.InsertAfter("line after")
+       fix.Apply()
+
+       fix.Notef("Replacing text.")
+       fix.Replace("l", "L")
+       fix.ReplaceRegex(`i`, "I", 1)
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "NOTE: filename:5: Inserting a line.",
+               "AUTOFIX: filename:5: Inserting a line \"line before\" before this line.",
+               "AUTOFIX: filename:5: Inserting a line \"line after\" after this line.",
+               "NOTE: filename:5: Replacing text.",
+               "AUTOFIX: filename:5: Replacing \"l\" with \"L\".",
+               "AUTOFIX: filename:5: Replacing \"i\" with \"I\".")
+}
+
 func (s *Suite) Test_SaveAutofixChanges(c *check.C) {
        t := s.Init(c)
 
@@ -627,6 +656,35 @@
                "+\tTODO")
 }
 
+// With the default command line options, this warning is printed.
+// With the --show-autofix option this warning is NOT printed since it
+// cannot be fixed automatically.
+func (s *Suite) Test_Autofix_Anyway__options(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("--show-autofix")
+
+       line := t.NewLine("filename", 3, "")
+       fix := line.Autofix()
+
+       fix.Warnf("This autofix doesn't match.")
+       fix.Replace("doesn't match", "")
+       fix.Anyway()
+       fix.Apply()
+
+       t.CheckOutputEmpty()
+
+       t.SetUpCommandLine()
+
+       fix.Warnf("This autofix doesn't match.")
+       fix.Replace("doesn't match", "")
+       fix.Anyway()
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "WARN: filename:3: This autofix doesn't match.")
+}
+
 // If an Autofix doesn't do anything, it must not log any diagnostics.
 func (s *Suite) Test_Autofix__noop_replace(c *check.C) {
        t := s.Init(c)
@@ -809,6 +867,210 @@
                "NOTE: README.txt:123: A note without fix.")
 }
 
+func (s *Suite) Test_Autofix_Anyway__autofix_option(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("--autofix")
+       line := t.NewLine("filename", 5, "text")
+
+       fix := line.Autofix()
+       fix.Notef("This line is quite short.")
+       fix.Replace("not found", "needle")
+       fix.Anyway()
+       fix.Apply()
+
+       // The replacement text is not found, therefore the note should not be logged.
+       // Because of fix.Anyway, the note should be logged anyway.
+       // But because of the --autofix option, the note should not be logged.
+       // Therefore, in the end nothing is shown in this case.
+       t.CheckOutputEmpty()
+}
+
+func (s *Suite) Test_Autofix_Anyway__autofix_and_show_autofix_options(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("--autofix", "--show-autofix")
+       line := t.NewLine("filename", 5, "text")
+
+       fix := line.Autofix()
+       fix.Notef("This line is quite short.")
+       fix.Replace("not found", "needle")
+       fix.Anyway()
+       fix.Apply()
+
+       // The replacement text is not found, therefore the note should not be logged.
+       // Because of fix.Anyway, the note should be logged anyway.
+       // But because of the --autofix option, the note should not be logged.
+       // Even if the --show-autofix option is explicitly given, the note should not be logged.
+       // Therefore, in the end nothing is shown in this case.
+       t.CheckOutputEmpty()
+}
+
+// The --autofix option normally suppresses the diagnostics and just logs



Home | Main Index | Thread Index | Old Index