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 19.4.8



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d5369dd80a48
branches:  trunk
changeset: 411562:d5369dd80a48
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Feb 15 13:48:40 2020 +0000

description:
pkgtools/pkglint: update to 19.4.8

Changes since 19.4.7:

The diagnostic for homepages using FTP is simpler now.

When running pkglint recursively on the top-level directory, the
inter-package checks (distfile hashes, unused licenses) are enabled
implicitly. This way, the only effect of the -Cglobal option is now
whether the pkgsrc infrastructure files are checked as well.

The check for removed packages that have not been recorded in
doc/CHANGES prints the correct lines when pkglint is run with the
--source option.

Fatal technical errors are no longer treated as diagnostics since they
are none. That was an early conceptual mistake, but since these fatal
error didn't happen often, it didn't matter.

In diagnostics, when referring to other lines, the previously used words
before/after have been replaced with above/below to avoid any confusion
whether space or time is meant.

In CONF_FILES, spaces and quotes are allowed.
See https://gnats.netbsd.org/42191.

Fixed unintended side-effects when running pkglint --autofix --only.
Before, all fixes were applied to the file, whether or not they matched
the --only option.

Fixed resolution of relative paths of the form ../../category/package
when they appeared in an infrastructure file.

Lots of refactorings and housekeeping, as usual.

diffstat:

 pkgtools/pkglint/Makefile                      |    4 +-
 pkgtools/pkglint/files/autofix.go              |  133 +++++++------
 pkgtools/pkglint/files/autofix_test.go         |  119 ++++++------
 pkgtools/pkglint/files/buildlink3.go           |    2 +-
 pkgtools/pkglint/files/buildlink3_test.go      |    2 +-
 pkgtools/pkglint/files/category.go             |    4 +-
 pkgtools/pkglint/files/category_test.go        |   14 +-
 pkgtools/pkglint/files/check_test.go           |   41 +---
 pkgtools/pkglint/files/distinfo.go             |    4 +-
 pkgtools/pkglint/files/distinfo_test.go        |   16 +-
 pkgtools/pkglint/files/files.go                |   28 +-
 pkgtools/pkglint/files/homepage.go             |   39 ++-
 pkgtools/pkglint/files/homepage_test.go        |  132 ++++++++-----
 pkgtools/pkglint/files/line.go                 |  145 ++++++++-------
 pkgtools/pkglint/files/line_test.go            |   55 ++---
 pkgtools/pkglint/files/linechecker.go          |    2 +-
 pkgtools/pkglint/files/lines.go                |    4 +-
 pkgtools/pkglint/files/lines_test.go           |    6 +-
 pkgtools/pkglint/files/lineslexer.go           |    8 +-
 pkgtools/pkglint/files/lineslexer_test.go      |    4 +-
 pkgtools/pkglint/files/logging.go              |   79 ++++----
 pkgtools/pkglint/files/logging_test.go         |  118 ++++++++++--
 pkgtools/pkglint/files/mkassignchecker.go      |   18 +-
 pkgtools/pkglint/files/mkassignchecker_test.go |   19 ++
 pkgtools/pkglint/files/mkcondchecker_test.go   |    2 +-
 pkgtools/pkglint/files/mkline.go               |   10 +-
 pkgtools/pkglint/files/mklinechecker.go        |   29 +-
 pkgtools/pkglint/files/mklineparser.go         |    2 +-
 pkgtools/pkglint/files/mklines.go              |    4 +-
 pkgtools/pkglint/files/mklines_test.go         |    8 +-
 pkgtools/pkglint/files/mkshparser_test.go      |    2 +-
 pkgtools/pkglint/files/mkvarusechecker.go      |    6 +-
 pkgtools/pkglint/files/package.go              |   28 +-
 pkgtools/pkglint/files/package_test.go         |   12 +-
 pkgtools/pkglint/files/patches.go              |    4 +-
 pkgtools/pkglint/files/patches_test.go         |    8 +-
 pkgtools/pkglint/files/path.go                 |   30 +--
 pkgtools/pkglint/files/path_test.go            |   63 +-----
 pkgtools/pkglint/files/pkglint.go              |  230 ++++++++++++------------
 pkgtools/pkglint/files/pkglint_test.go         |   10 +-
 pkgtools/pkglint/files/pkgsrc.go               |   28 ++-
 pkgtools/pkglint/files/pkgsrc_test.go          |   18 +-
 pkgtools/pkglint/files/plist.go                |   10 +-
 pkgtools/pkglint/files/redundantscope.go       |    6 +-
 pkgtools/pkglint/files/redundantscope_test.go  |    2 +-
 pkgtools/pkglint/files/shell.go                |   27 +-
 pkgtools/pkglint/files/toplevel.go             |    6 +-
 pkgtools/pkglint/files/toplevel_test.go        |    3 +-
 pkgtools/pkglint/files/util.go                 |   70 +++----
 pkgtools/pkglint/files/util_test.go            |   13 +-
 pkgtools/pkglint/files/var.go                  |    2 +-
 pkgtools/pkglint/files/varalignblock.go        |    8 +-
 pkgtools/pkglint/files/varalignblock_test.go   |   28 +-
 pkgtools/pkglint/files/vardefs.go              |    9 +-
 pkgtools/pkglint/files/vartype.go              |    1 +
 pkgtools/pkglint/files/vartypecheck.go         |   29 ++-
 pkgtools/pkglint/files/vartypecheck_test.go    |   62 ++++++-
 57 files changed, 947 insertions(+), 819 deletions(-)

diffs (truncated from 4184 to 300 lines):

diff -r 707ba44e0507 -r d5369dd80a48 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Feb 15 13:39:32 2020 +0000
+++ b/pkgtools/pkglint/Makefile Sat Feb 15 13:48:40 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.630 2020/02/05 04:09:00 rillig Exp $
+# $NetBSD: Makefile,v 1.631 2020/02/15 13:48:40 rillig Exp $
 
-PKGNAME=       pkglint-19.4.7
+PKGNAME=       pkglint-19.4.8
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 707ba44e0507 -r d5369dd80a48 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sat Feb 15 13:39:32 2020 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sat Feb 15 13:48:40 2020 +0000
@@ -17,9 +17,10 @@
 // The modifications are kept in memory only,
 // until they are written to disk by SaveAutofixChanges.
 type Autofix struct {
-       line        *Line
-       linesBefore []string // Newly inserted lines, including \n
-       linesAfter  []string // Newly inserted lines, including \n
+       line  *Line
+       above []string // Newly inserted lines, including \n
+       texts []string // Modified lines, including \n
+       below []string // Newly inserted lines, including \n
        // Whether an actual fix has been applied to the text of the raw lines
        modified bool
 
@@ -61,7 +62,11 @@
 const autofixFormat = "AutofixFormat"
 
 func NewAutofix(line *Line) *Autofix {
-       return &Autofix{line: line}
+       texts := make([]string, len(line.raw))
+       for i, rawLine := range line.raw {
+               texts[i] = rawLine.orignl
+       }
+       return &Autofix{line, nil, texts, nil, false, autofixShortTerm{}}
 }
 
 // Errorf remembers the error for logging it later when Apply is called.
@@ -108,31 +113,33 @@
        prefixTo := prefix + to
 
        n := 0
-       for _, rawLine := range fix.line.raw {
-               n += strings.Count(rawLine.textnl, prefixFrom)
+       for _, text := range fix.texts {
+               n += strings.Count(text, prefixFrom)
        }
        if n != 1 {
                return
        }
 
-       for _, rawLine := range fix.line.raw {
-               ok, replaced := replaceOnce(rawLine.textnl, prefixFrom, prefixTo)
-               if ok {
-                       if G.Logger.IsAutofix() {
-                               rawLine.textnl = replaced
+       for rawIndex, text := range fix.texts {
+               ok, replaced := replaceOnce(text, prefixFrom, prefixTo)
+               if !ok {
+                       continue
+               }
+
+               if G.Logger.IsAutofix() {
+                       fix.texts[rawIndex] = replaced
 
-                               // Fix the parsed text as well.
-                               // This is only approximate and won't work in some edge cases
-                               // that involve escaped comments or replacements across line breaks.
-                               //
-                               // TODO: Do this properly by parsing the whole line again,
-                               //  and ideally everything that depends on the parsed line.
-                               //  This probably requires a generic notification mechanism.
-                               _, fix.line.Text = replaceOnce(fix.line.Text, prefixFrom, prefixTo)
-                       }
-                       fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
-                       return
+                       // Fix the parsed text as well.
+                       // This is only approximate and won't work in some edge cases
+                       // that involve escaped comments or replacements across line breaks.
+                       //
+                       // TODO: Do this properly by parsing the whole line again,
+                       //  and ideally everything that depends on the parsed line.
+                       //  This probably requires a generic notification mechanism.
+                       _, fix.line.Text = replaceOnce(fix.line.Text, prefixFrom, prefixTo)
                }
+               fix.Describef(rawIndex, "Replacing %q with %q.", from, to)
+               return
        }
 }
 
@@ -142,13 +149,17 @@
        assert(from != to)
        fix.assertRealLine()
 
-       rawLine := fix.line.raw[rawIndex]
-       assert(textIndex < len(rawLine.textnl))
-       assert(hasPrefix(rawLine.textnl[textIndex:], from))
+       if fix.skip() {
+               return
+       }
 
-       replaced := rawLine.textnl[:textIndex] + to + rawLine.textnl[textIndex+len(from):]
+       text := fix.texts[rawIndex]
+       assert(textIndex < len(text))
+       assert(hasPrefix(text[textIndex:], from))
 
-       rawLine.textnl = replaced
+       replaced := text[:textIndex] + to + text[textIndex+len(from):]
+
+       fix.texts[rawIndex] = replaced
 
        // Fix the parsed text as well.
        // This is only approximate and won't work in some edge cases
@@ -159,38 +170,35 @@
        //  This probably requires a generic notification mechanism.
        _, fix.line.Text = replaceOnce(fix.line.Text, from, to)
 
-       if fix.skip() {
-               return
-       }
-       fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
+       fix.Describef(rawIndex, "Replacing %q with %q.", from, to)
 }
 
-// InsertBefore prepends a line before the current line.
+// InsertAbove prepends a line above the current line.
 // The newline is added internally.
-func (fix *Autofix) InsertBefore(text string) {
+func (fix *Autofix) InsertAbove(text string) {
        fix.assertRealLine()
        if fix.skip() {
                return
        }
 
-       fix.linesBefore = append(fix.linesBefore, text+"\n")
-       fix.Describef(fix.line.raw[0].Lineno, "Inserting a line %q before this line.", text)
+       fix.above = append(fix.above, text+"\n")
+       fix.Describef(0, "Inserting a line %q above this line.", text)
 }
 
-// InsertAfter appends a line after the current line.
+// InsertBelow appends a line below the current line.
 // The newline is added internally.
-func (fix *Autofix) InsertAfter(text string) {
+func (fix *Autofix) InsertBelow(text string) {
        fix.assertRealLine()
        if fix.skip() {
                return
        }
 
-       fix.linesAfter = append(fix.linesAfter, text+"\n")
-       fix.Describef(fix.line.raw[len(fix.line.raw)-1].Lineno, "Inserting a line %q after this line.", text)
+       fix.below = append(fix.below, text+"\n")
+       fix.Describef(len(fix.line.raw)-1, "Inserting a line %q below this line.", text)
 }
 
 // Delete removes the current line completely.
-// It can be combined with InsertAfter or InsertBefore to
+// It can be combined with InsertBelow or InsertAbove to
 // replace the complete line with some different text.
 func (fix *Autofix) Delete() {
        fix.assertRealLine()
@@ -198,9 +206,9 @@
                return
        }
 
-       for _, line := range fix.line.raw {
-               line.textnl = ""
-               fix.Describef(line.Lineno, "Deleting this line.")
+       for rawIndex := range fix.texts {
+               fix.texts[rawIndex] = ""
+               fix.Describef(rawIndex, "Deleting this line.")
        }
 }
 
@@ -210,7 +218,7 @@
 // The fixer function must check whether it can actually fix something,
 // and if so, call Describef to describe the actual fix.
 //
-// If autofix is false, the the fix should be applied, as far as only
+// If autofix is false, the fix should be applied, as far as only
 // in-memory data structures are effected, and these are not written
 // back to disk. No externally observable modification must be done.
 // For example, changing the text of Line.raw is appropriate,
@@ -237,8 +245,10 @@
 // Describef can be called from within an Autofix.Custom call to remember a
 // description of the actual fix for logging it later when Apply is called.
 // Describef may be called multiple times before calling Apply.
-func (fix *Autofix) Describef(lineno int, format string, args ...interface{}) {
-       fix.actions = append(fix.actions, autofixAction{sprintf(format, args...), lineno})
+func (fix *Autofix) Describef(rawIndex int, format string, args ...interface{}) {
+       msg := sprintf(format, args...)
+       lineno := fix.line.Location.Lineno(rawIndex)
+       fix.actions = append(fix.actions, autofixAction{msg, lineno})
 }
 
 // Apply does the actual work that has been prepared by previous calls to
@@ -297,10 +307,10 @@
        if logDiagnostic {
                linenos := fix.affectedLinenos()
                msg := sprintf(fix.diagFormat, fix.diagArgs...)
-               if !logFix && G.Logger.FirstTime(line.Filename, linenos, msg) {
+               if !logFix && G.Logger.FirstTime(line.Filename(), linenos, msg) {
                        G.Logger.writeSource(line)
                }
-               G.Logger.Logf(fix.level, line.Filename, linenos, fix.diagFormat, msg)
+               G.Logger.Logf(fix.level, line.Filename(), linenos, fix.diagFormat, msg)
        }
 
        if logFix {
@@ -309,7 +319,7 @@
                        if action.lineno != 0 {
                                lineno = strconv.Itoa(action.lineno)
                        }
-                       G.Logger.Logf(AutofixLogLevel, line.Filename, lineno, autofixFormat, action.description)
+                       G.Logger.Logf(AutofixLogLevel, line.Filename(), lineno, autofixFormat, action.description)
                }
                G.Logger.writeSource(line)
        }
@@ -375,7 +385,7 @@
 func (fix *Autofix) assertRealLine() {
        // Some Line objects do not correspond to real lines of a file.
        // These cannot be fixed since they are neither part of Lines nor of MkLines.
-       assert(fix.line.firstLine >= 1)
+       assert(fix.line.Location.lineno >= 1)
 }
 
 // SaveAutofixChanges writes the given lines back into their files,
@@ -392,11 +402,11 @@
        // Fast lane for the case that nothing is written back to disk.
        if !G.Logger.Opts.Autofix {
                for _, line := range lines.Lines {
-                       if line.autofix != nil && line.autofix.modified {
+                       if line.fix != nil && line.fix.modified {
                                G.Logger.autofixAvailable = true
                                if G.Logger.Opts.ShowAutofix {
                                        // Only in this case can the loaded lines be modified.
-                                       G.fileCache.Evict(line.Filename)
+                                       G.fileCache.Evict(line.Filename())
                                }
                        }
                }
@@ -420,22 +430,21 @@
        changes := make(map[CurrPath][]string)
        changed := make(map[CurrPath]bool)
        for _, line := range lines.Lines {
-               chlines := changes[line.Filename]
-               if fix := line.autofix; fix != nil {
+               filename := line.Filename()
+               chlines := changes[filename]
+               if fix := line.fix; fix != nil {
                        if fix.modified {
-                               changed[line.Filename] = true
+                               changed[filename] = true
                        }
-                       chlines = append(chlines, fix.linesBefore...)
-                       for _, raw := range line.raw {
-                               chlines = append(chlines, raw.textnl)
-                       }
-                       chlines = append(chlines, fix.linesAfter...)
+                       chlines = append(chlines, fix.above...)
+                       chlines = append(chlines, fix.texts...)
+                       chlines = append(chlines, fix.below...)
                } else {
                        for _, raw := range line.raw {
-                               chlines = append(chlines, raw.textnl)
+                               chlines = append(chlines, raw.orignl)
                        }
                }
-               changes[line.Filename] = chlines
+               changes[filename] = chlines
        }
 
        for filename := range changed {
diff -r 707ba44e0507 -r d5369dd80a48 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sat Feb 15 13:39:32 2020 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sat Feb 15 13:48:40 2020 +0000
@@ -19,8 +19,8 @@
        fix := line.Autofix()
        fix.Warnf("Row should be replaced with line.")
        fix.Replace("row", "line")
-       fix.InsertBefore("above")
-       fix.InsertAfter("below")
+       fix.InsertAbove("above")
+       fix.InsertBelow("below")
        fix.Delete()
        fix.Apply()
 
@@ -46,8 +46,8 @@
        fix := line.Autofix()
        fix.Warnf("Row should be replaced with line.")
        fix.ReplaceAfter("", "# row", "# line")
-       fix.InsertBefore("above")
-       fix.InsertAfter("below")
+       fix.InsertAbove("above")
+       fix.InsertBelow("below")



Home | Main Index | Thread Index | Old Index