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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/4148939cc3e5
branches:  trunk
changeset: 374769:4148939cc3e5
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Jan 28 23:21:16 2018 +0000

description:
pkgtools/pkglint: update to 5.5.3

Changes since 5.5.2:

* Fixed lots of bugs regarding autofixing variable assignments in
  continuation lines.
* Fixed checking of MESSAGE files, which also get fixed now.
* In variable assignments, commented assignments are aligned too.
* Fixed a crash when checking an empty patch file.
* The :Q modifier is only checked on predefined variables, to prevent
  the --autofix mode from removing :Q from user-defined variables.
* Fixed lots of bugs in PLIST autofixing: relevant lines had been
  removed, and the sorting was not correct.

diffstat:

 pkgtools/pkglint/Makefile                       |    4 +-
 pkgtools/pkglint/files/autofix.go               |   44 ++++++--
 pkgtools/pkglint/files/autofix_test.go          |   73 ++++++++++----
 pkgtools/pkglint/files/category.go              |    2 +-
 pkgtools/pkglint/files/files.go                 |   30 +++--
 pkgtools/pkglint/files/files_test.go            |   88 ++++++++++++++++++-
 pkgtools/pkglint/files/globaldata.go            |   14 ++-
 pkgtools/pkglint/files/histogram/histogram.go   |   28 ++---
 pkgtools/pkglint/files/linechecker.go           |    2 +-
 pkgtools/pkglint/files/mkline.go                |   73 ++++++++++++--
 pkgtools/pkglint/files/mkline_test.go           |   68 +++++++++++---
 pkgtools/pkglint/files/mklinechecker.go         |    2 +-
 pkgtools/pkglint/files/mklinechecker_test.go    |   31 ++++++
 pkgtools/pkglint/files/mklines.go               |   28 ++++-
 pkgtools/pkglint/files/mklines_varalign_test.go |  115 +++++++++++++++++++++++-
 pkgtools/pkglint/files/patches.go               |    5 +
 pkgtools/pkglint/files/patches_test.go          |   27 +++++
 pkgtools/pkglint/files/pkglint.go               |   34 ++++--
 pkgtools/pkglint/files/pkglint_test.go          |   32 ++++++-
 pkgtools/pkglint/files/plist.go                 |   55 +++++++----
 pkgtools/pkglint/files/plist_test.go            |   44 +++++++++
 21 files changed, 652 insertions(+), 147 deletions(-)

diffs (truncated from 1369 to 300 lines):

diff -r 68c4afcbafd8 -r 4148939cc3e5 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Jan 28 20:10:34 2018 +0000
+++ b/pkgtools/pkglint/Makefile Sun Jan 28 23:21:16 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.527 2018/01/28 13:40:22 rillig Exp $
+# $NetBSD: Makefile,v 1.528 2018/01/28 23:21:16 rillig Exp $
 
-PKGNAME=       pkglint-5.5.2
+PKGNAME=       pkglint-5.5.3
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 68c4afcbafd8 -r 4148939cc3e5 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sun Jan 28 20:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sun Jan 28 23:21:16 2018 +0000
@@ -62,25 +62,42 @@
        }
 }
 
-func (fix *Autofix) ReplaceRegex(from regex.Pattern, to string) {
+// ReplaceRegex replaces the first or all occurrences of the `from` pattern
+// with the fixed string `toText`. Placeholders like `$1` are _not_ expanded.
+// (If you know how to do the expansion correctly, feel free to implement it.)
+func (fix *Autofix) ReplaceRegex(from regex.Pattern, toText string, howOften int) {
        if fix.skip() {
                return
        }
 
+       done := 0
        for _, rawLine := range fix.lines {
                if rawLine.Lineno != 0 {
-                       if replaced := regex.Compile(from).ReplaceAllString(rawLine.textnl, to); replaced != rawLine.textnl {
+                       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
+                       }
+
+                       if replaced := regex.Compile(from).ReplaceAllStringFunc(rawLine.textnl, replace); replaced != rawLine.textnl {
                                if G.opts.PrintAutofix || G.opts.Autofix {
                                        rawLine.textnl = replaced
                                }
-                               fix.Describef(rawLine.Lineno, "Replacing regular expression %q with %q.", from, to)
+                               for _, fromText := range froms {
+                                       fix.Describef(rawLine.Lineno, "Replacing %q with %q.", fromText, toText)
+                               }
                        }
                }
        }
 }
 
 func (fix *Autofix) Realign(mkline MkLine, newWidth int) {
-       if fix.skip() || !mkline.IsMultiline() || !mkline.IsVarassign() {
+       if fix.skip() || !mkline.IsMultiline() || !(mkline.IsVarassign() || mkline.IsCommentedVarassign()) {
                return
        }
 
@@ -90,19 +107,19 @@
        {
                // Interpreting the continuation marker as variable value
                // is cheating, but works well.
-               m, _, _, _, valueAlign, value, _, _ := MatchVarassign(mkline.raw[0].orignl)
+               m, _, _, _, _, valueAlign, value, _, _ := MatchVarassign(mkline.raw[0].orignl)
                if m && value != "\\" {
                        oldWidth = tabWidth(valueAlign)
                }
        }
 
        for _, rawLine := range fix.lines[1:] {
-               _, space := regex.Match1(rawLine.textnl, `^(\s*)`)
-               width := tabWidth(space)
-               if oldWidth == 0 || width < oldWidth {
+               _, comment, space := regex.Match2(rawLine.textnl, `^(#?)([ \t]*)`)
+               width := tabWidth(comment + space)
+               if (oldWidth == 0 || width < oldWidth) && width >= 8 && rawLine.textnl != "\n" {
                        oldWidth = width
                }
-               if !regex.Matches(space, `^\t*\s{0,7}`) {
+               if !regex.Matches(space, `^\t* {0,7}`) {
                        normalized = false
                }
        }
@@ -119,10 +136,11 @@
        }
 
        for _, rawLine := range fix.lines[1:] {
-               _, oldSpace := regex.Match1(rawLine.textnl, `^(\s*)`)
+               _, comment, oldSpace := regex.Match2(rawLine.textnl, `^(#?)([ \t]*)`)
                newWidth := tabWidth(oldSpace) - oldWidth + newWidth
                newSpace := strings.Repeat("\t", newWidth/8) + strings.Repeat(" ", newWidth%8)
-               if replaced := strings.Replace(rawLine.textnl, oldSpace, newSpace, 1); replaced != rawLine.textnl {
+               replaced := strings.Replace(rawLine.textnl, comment+oldSpace, comment+newSpace, 1)
+               if replaced != rawLine.textnl {
                        if G.opts.PrintAutofix || G.opts.Autofix {
                                rawLine.textnl = replaced
                        }
@@ -131,6 +149,8 @@
        }
 }
 
+// InsertBefore prepends a line before the current line.
+// The newline is added internally.
 func (fix *Autofix) InsertBefore(text string) {
        if fix.skip() {
                return
@@ -140,6 +160,8 @@
        fix.Describef(fix.lines[0].Lineno, "Inserting a line %q before this line.", text)
 }
 
+// InsertBefore appends a line after the current line.
+// The newline is added internally.
 func (fix *Autofix) InsertAfter(text string) {
        if fix.skip() {
                return
diff -r 68c4afcbafd8 -r 4148939cc3e5 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sun Jan 28 20:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sun Jan 28 23:21:16 2018 +0000
@@ -13,7 +13,7 @@
 
        fix := lines[1].Autofix()
        fix.Warnf("Something's wrong here.")
-       fix.ReplaceRegex(`.`, "X")
+       fix.ReplaceRegex(`.`, "X", -1)
        fix.Apply()
        SaveAutofixChanges(lines)
 
@@ -24,7 +24,11 @@
                "line3")
        t.CheckOutputLines(
                "WARN: ~/Makefile:2: Something's wrong here.",
-               "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".")
+               "AUTOFIX: ~/Makefile:2: Replacing \"l\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"i\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"n\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"e\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"2\" with \"X\".")
 }
 
 func (s *Suite) Test_Autofix_ReplaceRegex_with_autofix(c *check.C) {
@@ -38,27 +42,32 @@
 
        fix := lines[1].Autofix()
        fix.Warnf("Something's wrong here.")
-       fix.ReplaceRegex(`.`, "X")
+       fix.ReplaceRegex(`.`, "X", 3)
        fix.Apply()
 
+       t.CheckOutputLines(
+               "AUTOFIX: ~/Makefile:2: Replacing \"l\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"i\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"n\" with \"X\".",
+               "-\tline2",
+               "+\tXXXe2")
+
        fix.Warnf("Use Y instead of X.")
        fix.Replace("X", "Y")
        fix.Apply()
 
+       t.CheckOutputLines(
+               "",
+               "AUTOFIX: ~/Makefile:2: Replacing \"X\" with \"Y\".",
+               "-\tline2",
+               "+\tYXXe2")
+
        SaveAutofixChanges(lines)
 
        t.CheckFileLines("Makefile",
                "line1",
-               "YXXXX",
+               "YXXe2",
                "line3")
-       t.CheckOutputLines(
-               "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".",
-               "-\tline2",
-               "+\tXXXXX",
-               "",
-               "AUTOFIX: ~/Makefile:2: Replacing \"X\" with \"Y\".",
-               "-\tline2",
-               "+\tYXXXX")
 }
 
 func (s *Suite) Test_Autofix_ReplaceRegex_with_show_autofix(c *check.C) {
@@ -72,7 +81,7 @@
 
        fix := lines[1].Autofix()
        fix.Warnf("Something's wrong here.")
-       fix.ReplaceRegex(`.`, "X")
+       fix.ReplaceRegex(`.`, "X", -1)
        fix.Apply()
 
        fix.Warnf("Use Y instead of X.")
@@ -83,7 +92,11 @@
 
        t.CheckOutputLines(
                "WARN: ~/Makefile:2: Something's wrong here.",
-               "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"l\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"i\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"n\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"e\" with \"X\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"2\" with \"X\".",
                "-\tline2",
                "+\tXXXXX",
                "",
@@ -108,17 +121,27 @@
 
        fix := mklines.mklines[1].Autofix()
        fix.Warnf("Something's wrong here.")
-       fix.ReplaceRegex(`.`, "X")
+       fix.ReplaceRegex(`...`, "XXX", -1)
+       fix.Apply()
+
+       fix = mklines.mklines[2].Autofix()
+       fix.Warnf("Something's wrong here.")
+       fix.ReplaceRegex(`...`, "XXX", 1)
        fix.Apply()
 
        SaveAutofixChanges(mklines.lines)
 
+       t.CheckOutputLines(
+               "AUTOFIX: ~/Makefile:2: Replacing \"lin\" with \"XXX\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"e2 \" with \"XXX\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \":= \" with \"XXX\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"val\" with \"XXX\".",
+               "AUTOFIX: ~/Makefile:2: Replacing \"ue2\" with \"XXX\".",
+               "AUTOFIX: ~/Makefile:3: Replacing \"lin\" with \"XXX\".")
        t.CheckFileLines("Makefile",
                "line1 := value1",
                "XXXXXXXXXXXXXXX",
-               "line3 := value3")
-       t.CheckOutputLines(
-               "AUTOFIX: ~/Makefile:2: Replacing regular expression \".\" with \"X\".")
+               "XXXe3 := value3")
 }
 
 func (s *Suite) Test_Autofix_multiple_modifications(c *check.C) {
@@ -134,14 +157,14 @@
        {
                fix := line.Autofix()
                fix.Warnf("Silent-Magic-Diagnostic")
-               fix.ReplaceRegex(`(.)(.*)(.)`, "$3$2$1")
+               fix.ReplaceRegex(`(.)(.*)(.)`, "lriginao", 1) // XXX: the replacement should be "$3$2$1"
                fix.Apply()
        }
 
        c.Check(line.autofix, check.NotNil)
        c.Check(line.raw, check.DeepEquals, t.NewRawLines(1, "original\n", "lriginao\n"))
        t.CheckOutputLines(
-               "AUTOFIX: fname:1: Replacing regular expression \"(.)(.*)(.)\" with \"$3$2$1\".")
+               "AUTOFIX: fname:1: Replacing \"original\" with \"lriginao\".")
 
        {
                fix := line.Autofix()
@@ -304,7 +327,7 @@
 
        fix := lines[1].Autofix()
        fix.Warnf("Something's wrong here.")
-       fix.ReplaceRegex(`.`, "X")
+       fix.ReplaceRegex(`.`, "X", -1)
        fix.Apply()
 
        fix.Warnf("The XXX marks are usually not fixed, use TODO instead.")
@@ -315,7 +338,11 @@
 
        t.CheckOutputLines(
                "WARN: Makefile:2: Something's wrong here.",
-               "AUTOFIX: Makefile:2: Replacing regular expression \".\" with \"X\".",
+               "AUTOFIX: Makefile:2: Replacing \"l\" with \"X\".",
+               "AUTOFIX: Makefile:2: Replacing \"i\" with \"X\".",
+               "AUTOFIX: Makefile:2: Replacing \"n\" with \"X\".",
+               "AUTOFIX: Makefile:2: Replacing \"e\" with \"X\".",
+               "AUTOFIX: Makefile:2: Replacing \"2\" with \"X\".",
                "-\tline2",
                "+\tXXXXX",
                "",
@@ -333,7 +360,7 @@
 
        fix := line.Autofix()
        fix.Warnf("All-uppercase words should not be used at all.")
-       fix.ReplaceRegex(`\b[A-Z]{3,}\b`, "---censored---")
+       fix.ReplaceRegex(`\b[A-Z]{3,}\b`, "---censored---", -1)
        fix.Apply()
 
        // No output since there was no all-uppercase word in the text.
diff -r 68c4afcbafd8 -r 4148939cc3e5 pkgtools/pkglint/files/category.go
--- a/pkgtools/pkglint/files/category.go        Sun Jan 28 20:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/category.go        Sun Jan 28 23:21:16 2018 +0000
@@ -41,7 +41,7 @@
        // collect the SUBDIRs in the Makefile and in the file system.
 
        fSubdirs := getSubdirs(G.CurrentDir)
-       sort.Sort(sort.StringSlice(fSubdirs))
+       sort.Strings(fSubdirs)
        var mSubdirs []subdir
 



Home | Main Index | Thread Index | Old Index