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.23



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5c4169baba58
branches:  trunk
changeset: 339232:5c4169baba58
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Sep 08 22:47:47 2019 +0000

description:
pkgtools/pkglint: update to 5.7.23

Changes since 5.7.22:

* Added a warning for lines that look empty but are actually follow-up
  lines from a previous line.

* Added notes for unusual placement of the continuation backslash. It
  should always be preceded by a single space or tab, or be in column
  73.

* Improved check for needlessly complicated !empty(PKGPATH:Mcat/pkg)
  that is transformed into the simpler ${PKGPATH} == cat/pkg, even if
  the package name contains hyphens, dots, plus or slashes.

* Added check for the _VARGROUPS section since that section contains
  many redundancies that can easily be checked. For example, in
  mk/compiler/gcc.mk the _VARGROUPS section is 67 lines long and
  contains far more than 100 variables. It's tedious to manually check
  this file for internal consistency. That's better left to pkglint.

* The empty variable is no longer flagged as "used but not defined".
  It appears in expressions like ${:Ustring}.

* When --source is combined with --explain, don't unnecessarily
  repeat the source code for a single line if there are several
  diagnostics. Instead, even omit the empty line between the diagnostics
  for the same line.

diffstat:

 pkgtools/pkglint/Makefile                    |     4 +-
 pkgtools/pkglint/PLIST                       |     4 +-
 pkgtools/pkglint/files/autofix.go            |    22 +-
 pkgtools/pkglint/files/autofix_test.go       |     2 -
 pkgtools/pkglint/files/category_test.go      |    25 +
 pkgtools/pkglint/files/lines.go              |     6 +-
 pkgtools/pkglint/files/lines_test.go         |     1 +
 pkgtools/pkglint/files/logging.go            |    46 +-
 pkgtools/pkglint/files/logging_test.go       |   144 ++-
 pkgtools/pkglint/files/mkline_test.go        |    29 +-
 pkgtools/pkglint/files/mklinechecker.go      |   100 +-
 pkgtools/pkglint/files/mklinechecker_test.go |    20 +
 pkgtools/pkglint/files/mklines.go            |     3 +
 pkgtools/pkglint/files/mkparser.go           |     6 +-
 pkgtools/pkglint/files/mkparser_test.go      |    21 +-
 pkgtools/pkglint/files/package.go            |     5 +-
 pkgtools/pkglint/files/package_test.go       |    39 +-
 pkgtools/pkglint/files/pkglint.go            |     1 +
 pkgtools/pkglint/files/pkglint_test.go       |     2 +-
 pkgtools/pkglint/files/pkgsrc.go             |     9 +
 pkgtools/pkglint/files/shell.go              |     1 +
 pkgtools/pkglint/files/tools.go              |     2 +
 pkgtools/pkglint/files/util.go               |    38 +-
 pkgtools/pkglint/files/util_test.go          |     9 +
 pkgtools/pkglint/files/varalignblock.go      |   606 +++++---
 pkgtools/pkglint/files/varalignblock_test.go |  1772 +++++++++++++++----------
 pkgtools/pkglint/files/vardefs.go            |    14 +-
 pkgtools/pkglint/files/vargroups.go          |   246 +++
 pkgtools/pkglint/files/vargroups_test.go     |   142 ++
 29 files changed, 2230 insertions(+), 1089 deletions(-)

diffs (truncated from 5545 to 300 lines):

diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sun Sep 08 22:47:47 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.595 2019/08/25 21:47:11 rillig Exp $
+# $NetBSD: Makefile,v 1.596 2019/09/08 22:47:47 rillig Exp $
 
-PKGNAME=       pkglint-5.7.22
+PKGNAME=       pkglint-5.7.23
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/PLIST
--- a/pkgtools/pkglint/PLIST    Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/PLIST    Sun Sep 08 22:47:47 2019 +0000
@@ -1,4 +1,4 @@
-@comment $NetBSD: PLIST,v 1.13 2019/07/14 21:25:47 rillig Exp $
+@comment $NetBSD: PLIST,v 1.14 2019/09/08 22:47:47 rillig Exp $
 bin/pkglint
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint.a
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/getopt.a
@@ -116,6 +116,8 @@
 gopkg/src/netbsd.org/pkglint/varalignblock_test.go
 gopkg/src/netbsd.org/pkglint/vardefs.go
 gopkg/src/netbsd.org/pkglint/vardefs_test.go
+gopkg/src/netbsd.org/pkglint/vargroups.go
+gopkg/src/netbsd.org/pkglint/vargroups_test.go
 gopkg/src/netbsd.org/pkglint/vartype.go
 gopkg/src/netbsd.org/pkglint/vartype_test.go
 gopkg/src/netbsd.org/pkglint/vartypecheck.go
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sun Sep 08 22:47:47 2019 +0000
@@ -127,7 +127,7 @@
 
 // ReplaceAt replaces the text "from" with "to", a single time.
 // But only if the text at the given position is indeed "from".
-func (fix *Autofix) ReplaceAt(rawIndex int, column int, from string, to string) {
+func (fix *Autofix) ReplaceAt(rawIndex int, textIndex int, from string, to string) {
        assert(from != to)
        fix.assertRealLine()
 
@@ -136,11 +136,11 @@
        }
 
        rawLine := fix.line.raw[rawIndex]
-       if column >= len(rawLine.textnl) || !hasPrefix(rawLine.textnl[column:], from) {
+       if textIndex >= len(rawLine.textnl) || !hasPrefix(rawLine.textnl[textIndex:], from) {
                return
        }
 
-       replaced := rawLine.textnl[:column] + to + rawLine.textnl[column+len(from):]
+       replaced := rawLine.textnl[:textIndex] + to + rawLine.textnl[textIndex+len(from):]
 
        if G.Logger.IsAutofix() {
                rawLine.textnl = replaced
@@ -328,7 +328,6 @@
                        fix.modified = true
                }
 
-               // Reduce number of calls to runtime.writeBarrier.
                fix.autofixShortTerm = autofixShortTerm{}
        }
 
@@ -364,20 +363,11 @@
                        }
                        G.Logger.Logf(AutofixLogLevel, line.Filename, lineno, AutofixFormat, action.description)
                }
+               G.Logger.showSource(line)
        }
 
-       if logDiagnostic || logFix {
-               if logFix {
-                       G.Logger.showSource(line)
-               }
-               if logDiagnostic && len(fix.explanation) > 0 {
-                       line.Explain(fix.explanation...)
-               }
-               if G.Logger.Opts.ShowSource {
-                       if !(G.Logger.Opts.Explain && logDiagnostic && len(fix.explanation) > 0) {
-                               G.Logger.out.Separate()
-                       }
-               }
+       if logDiagnostic && len(fix.explanation) > 0 {
+               line.Explain(fix.explanation...)
        }
 
        reset()
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sun Sep 08 22:47:47 2019 +0000
@@ -966,8 +966,6 @@
        t.CheckOutputLines(
                ">\ttext",
                "WARN: README.txt:123: A warning with autofix.",
-               "",
-               ">\ttext",
                "NOTE: README.txt:123: A note without fix.")
 }
 
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go   Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/category_test.go   Sun Sep 08 22:47:47 2019 +0000
@@ -343,3 +343,28 @@
        t.CheckOutputLines(
                "ERROR: ~/category/Makefile: Cannot be read.")
 }
+
+func (s *Suite) Test_CheckdirCategory__case_mismatch(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpPkgsrc()
+       t.CreateFileLines("mk/misc/category.mk")
+       t.CreateFileLines("category/p5-Net-DNS/Makefile")
+       t.CreateFileLines("category/Makefile",
+               MkCvsID,
+               "",
+               "COMMENT=\tCategory comment",
+               "",
+               "SUBDIR+=\tp5-net-dns",
+               "",
+               ".include \"../mk/misc/category.mk\"")
+       t.FinishSetUp()
+
+       G.Check(t.File("category"))
+
+       t.CheckOutputLines(
+               "ERROR: ~/category/Makefile:5: \"p5-Net-DNS\" "+
+                       "exists in the file system but not in the Makefile.",
+               "ERROR: ~/category/Makefile:5: \"p5-net-dns\" "+
+                       "exists in the Makefile but not in the file system.")
+}
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/lines.go
--- a/pkgtools/pkglint/files/lines.go   Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/lines.go   Sun Sep 08 22:47:47 2019 +0000
@@ -42,7 +42,11 @@
        line := ls.Lines[index]
        if m, expanded := line.IsCvsID(prefixRe); m {
 
-               if G.Testing && G.Wip && expanded {
+               // This check is considered experimental because it produces a few
+               // thousand notes and doesn't really affect the functionality of
+               // the packages. The worst thing that might happen is that a file
+               // looks older than it really is.
+               if G.Experimental && G.Wip && expanded {
                        fix := line.Autofix()
                        fix.Notef("Expected exactly %q.", suggestedPrefix+"$"+"NetBSD$")
                        fix.Explain(
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/lines_test.go
--- a/pkgtools/pkglint/files/lines_test.go      Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/lines_test.go      Sun Sep 08 22:47:47 2019 +0000
@@ -30,6 +30,7 @@
 func (s *Suite) Test_Lines_CheckCvsID__wip(c *check.C) {
        t := s.Init(c)
 
+       G.Experimental = true
        t.SetUpPkgsrc()
        t.SetUpPackage("wip/package")
        t.CreateFileLines("wip/package/file1.mk",
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/logging.go
--- a/pkgtools/pkglint/files/logging.go Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/logging.go Sun Sep 08 22:47:47 2019 +0000
@@ -16,6 +16,7 @@
 
        suppressDiag bool
        suppressExpl bool
+       prevLine     *Line
 
        logged    Once
        explained Once
@@ -98,8 +99,16 @@
                return
        }
 
+       // The explanation should fit nicely on a screen that is 80
+       // characters wide. The explanation is indented using a tab, and
+       // there should be a little margin at the right. The resulting
+       // number comes remarkably close to the line width recommended
+       // by typographers, which is 66.
+       const explanationWidth = 80 - 8 - 4
+
+       l.prevLine = nil
        l.out.Separate()
-       wrapped := wrap(68, explanation...)
+       wrapped := wrap(explanationWidth, explanation...)
        for _, explanationLine := range wrapped {
                if explanationLine != "" {
                        l.out.Write("\t")
@@ -114,6 +123,10 @@
                return
        }
 
+       if l.Opts.ShowSource {
+               l.out.Separate()
+       }
+
        if l.errors != 0 || l.warnings != 0 {
                num := func(n int, singular, plural string) string {
                        if n == 0 {
@@ -187,12 +200,13 @@
        }
 
        if l.Opts.ShowSource {
+               if !l.IsAutofix() && line != l.prevLine && level != Fatal {
+                       l.out.Separate()
+               }
                l.showSource(line)
-               l.Logf(level, filename, linenos, format, msg)
-               l.out.Separate()
-       } else {
-               l.Logf(level, filename, linenos, format, msg)
        }
+
+       l.Logf(level, filename, linenos, format, msg)
 }
 
 func (l *Logger) showSource(line *Line) {
@@ -200,6 +214,13 @@
                return
        }
 
+       if !l.IsAutofix() {
+               if line == l.prevLine {
+                       return
+               }
+               l.prevLine = line
+       }
+
        out := l.out
        writeLine := func(prefix, line string) {
                out.Write(prefix)
@@ -229,6 +250,9 @@
                }
        }
 
+       if !l.IsAutofix() {
+               l.out.Separate()
+       }
        if line.autofix != nil {
                for _, before := range line.autofix.linesBefore {
                        writeLine("+\t", before)
@@ -240,6 +264,9 @@
        } else {
                printDiff(line.raw)
        }
+       if l.IsAutofix() {
+               l.out.Separate()
+       }
 }
 
 func (l *Logger) Logf(level *LogLevel, filename, lineno, format, msg string) {
@@ -324,7 +351,7 @@
 }
 
 func NewSeparatorWriter(out io.Writer) *SeparatorWriter {
-       return &SeparatorWriter{out: out}
+       return &SeparatorWriter{out: out, state: 3}
 }
 
 func (wr *SeparatorWriter) WriteLine(text string) {
@@ -339,11 +366,10 @@
 }
 
 // Separate remembers to output an empty line before the next character.
-// If the writer is currently in the middle of a line, that line is terminated immediately.
+//
+// The writer must not be in the middle of a line.
 func (wr *SeparatorWriter) Separate() {
-       if wr.state == 1 {
-               wr.write('\n')
-       }
+       assert(wr.state != 1)
        if wr.state < 2 {
                wr.state = 2
        }
diff -r 7650519742bf -r 5c4169baba58 pkgtools/pkglint/files/logging_test.go
--- a/pkgtools/pkglint/files/logging_test.go    Sun Sep 08 21:01:57 2019 +0000
+++ b/pkgtools/pkglint/files/logging_test.go    Sun Sep 08 22:47:47 2019 +0000
@@ -206,9 +206,107 @@
                "",
                ">\tThe third line",
                "WARN: ~/DESCR:3: Dummy warning.",
+               "WARN: ~/DESCR:3: Using \"third\" is deprecated.")
+}
+
+func (s *Suite) Test_Logger__show_source_with_explanation(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("--source", "--explain")
+       lines := t.SetUpFileLines("DESCR",
+               "The first line",
+               "The second line",
+               "The third line")
+
+       fix := lines.Lines[1].Autofix()
+       fix.Warnf("Using \"second\" is deprecated.")
+       fix.Explain("Explanation 1.")
+       fix.Replace("second", "silver medal")
+       fix.Apply()
+



Home | Main Index | Thread Index | Old Index