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.2
details: https://anonhg.NetBSD.org/pkgsrc/rev/40769a5e5ec8
branches: trunk
changeset: 374683:40769a5e5ec8
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Jan 27 18:50:36 2018 +0000
description:
pkgtools/pkglint: Update to 5.5.2
Changes since 5.5.1:
* Fixed command line parsing for the --only option.
* Improved alignment of variable values in Makefiles.
* Code cleanup: better abstraction in the tests.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/autofix.go | 128 ++-
pkgtools/pkglint/files/autofix_test.go | 228 +++--
pkgtools/pkglint/files/buildlink3_test.go | 121 +-
pkgtools/pkglint/files/category_test.go | 78 +-
pkgtools/pkglint/files/check_test.go | 320 +++++---
pkgtools/pkglint/files/distinfo.go | 7 +-
pkgtools/pkglint/files/distinfo_test.go | 108 +-
pkgtools/pkglint/files/files.go | 3 -
pkgtools/pkglint/files/files_test.go | 5 +-
pkgtools/pkglint/files/getopt/getopt.go | 2 +-
pkgtools/pkglint/files/getopt/getopt_test.go | 14 +-
pkgtools/pkglint/files/globaldata_test.go | 95 +-
pkgtools/pkglint/files/licenses_test.go | 24 +-
pkgtools/pkglint/files/line.go | 16 +-
pkgtools/pkglint/files/linechecker_test.go | 25 +-
pkgtools/pkglint/files/logging.go | 2 +-
pkgtools/pkglint/files/logging_test.go | 75 +-
pkgtools/pkglint/files/mkline.go | 44 +-
pkgtools/pkglint/files/mkline_test.go | 450 ++++++-----
pkgtools/pkglint/files/mklinechecker_test.go | 229 +++--
pkgtools/pkglint/files/mklines.go | 249 ++++--
pkgtools/pkglint/files/mklines_test.go | 400 ++++------
pkgtools/pkglint/files/mklines_varalign_test.go | 872 ++++++++++++++++++++++++
pkgtools/pkglint/files/mkparser_test.go | 33 +-
pkgtools/pkglint/files/mkshwalker_test.go | 1 +
pkgtools/pkglint/files/package.go | 5 +-
pkgtools/pkglint/files/package_test.go | 209 +++--
pkgtools/pkglint/files/parser_test.go | 2 +
pkgtools/pkglint/files/patches_test.go | 230 +++---
pkgtools/pkglint/files/pkglint.go | 8 +-
pkgtools/pkglint/files/pkglint_test.go | 121 ++-
pkgtools/pkglint/files/plist.go | 2 +-
pkgtools/pkglint/files/plist_test.go | 221 +++--
pkgtools/pkglint/files/shell_test.go | 273 ++++---
pkgtools/pkglint/files/shtokenizer_test.go | 14 +-
pkgtools/pkglint/files/substcontext_test.go | 103 +-
pkgtools/pkglint/files/toplevel_test.go | 39 +-
pkgtools/pkglint/files/tree_test.go | 4 +-
pkgtools/pkglint/files/util.go | 14 +-
pkgtools/pkglint/files/util_test.go | 49 +-
pkgtools/pkglint/files/vardefs.go | 3 +
pkgtools/pkglint/files/vartypecheck_test.go | 404 ++++++----
43 files changed, 3327 insertions(+), 1907 deletions(-)
diffs (truncated from 8821 to 300 lines):
diff -r 5ec69ff2f9c2 -r 40769a5e5ec8 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Jan 27 18:24:16 2018 +0000
+++ b/pkgtools/pkglint/Makefile Sat Jan 27 18:50:36 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.525 2018/01/13 23:56:14 rillig Exp $
+# $NetBSD: Makefile,v 1.526 2018/01/27 18:50:36 rillig Exp $
-PKGNAME= pkglint-5.5.1
+PKGNAME= pkglint-5.5.2
DISTFILES= # none
CATEGORIES= pkgtools
diff -r 5ec69ff2f9c2 -r 40769a5e5ec8 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sat Jan 27 18:24:16 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sat Jan 27 18:50:36 2018 +0000
@@ -6,6 +6,7 @@
"netbsd.org/pkglint/regex"
"netbsd.org/pkglint/trace"
"os"
+ "strconv"
"strings"
)
@@ -15,16 +16,20 @@
// until they are written to disk by SaveAutofixChanges.
type Autofix struct {
line Line
- linesBefore []string // Newly inserted lines, including \n
- lines []*RawLine // Original lines, available for diff
- linesAfter []string // Newly inserted lines, including \n
- modified bool // Modified in memory, but not necessarily written back to disk
- descrFormat string // Human-readable description of the latest modification
- descrArgs []interface{} //
- level *LogLevel //
- diagFormat string // Is printed only if it couldn't be fixed automatically
- diagArgs []interface{} //
- explanation []string // Is printed together with the diagnostic
+ linesBefore []string // Newly inserted lines, including \n
+ lines []*RawLine // Original lines, available for diff
+ linesAfter []string // Newly inserted lines, including \n
+ modified bool // Modified in memory, but not necessarily written back to disk
+ actions []autofixAction // Human-readable description of the actual autofix actions
+ level *LogLevel //
+ diagFormat string // Is printed only if it couldn't be fixed automatically
+ diagArgs []interface{} //
+ explanation []string // Is printed together with the diagnostic
+}
+
+type autofixAction struct {
+ description string
+ lineno int
}
func NewAutofix(line Line) *Autofix {
@@ -34,17 +39,24 @@
}
func (fix *Autofix) Replace(from string, to string) {
+ fix.ReplaceAfter("", from, to)
+}
+
+// ReplaceAfter replaces the text "prefix+from" with "prefix+to",
+// but in the diagnostic, only the replacement of "from" with "to"
+// is mentioned.
+func (fix *Autofix) ReplaceAfter(prefix, from string, to string) {
if fix.skip() {
return
}
for _, rawLine := range fix.lines {
if rawLine.Lineno != 0 {
- if replaced := strings.Replace(rawLine.textnl, from, to, 1); replaced != rawLine.textnl {
+ if replaced := strings.Replace(rawLine.textnl, prefix+from, prefix+to, 1); replaced != rawLine.textnl {
if G.opts.PrintAutofix || G.opts.Autofix {
rawLine.textnl = replaced
}
- fix.Describef("Replacing %q with %q.", from, to)
+ fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
}
}
}
@@ -61,19 +73,71 @@
if G.opts.PrintAutofix || G.opts.Autofix {
rawLine.textnl = replaced
}
- fix.Describef("Replacing regular expression %q with %q.", from, to)
+ fix.Describef(rawLine.Lineno, "Replacing regular expression %q with %q.", from, to)
}
}
}
}
+func (fix *Autofix) Realign(mkline MkLine, newWidth int) {
+ if fix.skip() || !mkline.IsMultiline() || !mkline.IsVarassign() {
+ return
+ }
+
+ normalized := true // Whether all indentation is tabs, followed by spaces.
+ oldWidth := 0 // The minimum required indentation in the original lines.
+
+ {
+ // Interpreting the continuation marker as variable value
+ // is cheating, but works well.
+ 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 {
+ oldWidth = width
+ }
+ if !regex.Matches(space, `^\t*\s{0,7}`) {
+ normalized = false
+ }
+ }
+
+ if normalized && newWidth == oldWidth {
+ return
+ }
+
+ // Continuation lines with the minimal unambiguous indentation
+ // attempt to keep the indentation as small as possible, so don't
+ // realign them.
+ if oldWidth == 8 {
+ return
+ }
+
+ for _, rawLine := range fix.lines[1:] {
+ _, oldSpace := regex.Match1(rawLine.textnl, `^(\s*)`)
+ 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 {
+ if G.opts.PrintAutofix || G.opts.Autofix {
+ rawLine.textnl = replaced
+ }
+ fix.Describef(rawLine.Lineno, "Replacing indentation %q with %q.", oldSpace, newSpace)
+ }
+ }
+}
+
func (fix *Autofix) InsertBefore(text string) {
if fix.skip() {
return
}
fix.linesBefore = append(fix.linesBefore, text+"\n")
- fix.Describef("Inserting a line %q before this line.", text)
+ fix.Describef(fix.lines[0].Lineno, "Inserting a line %q before this line.", text)
}
func (fix *Autofix) InsertAfter(text string) {
@@ -82,7 +146,7 @@
}
fix.linesAfter = append(fix.linesAfter, text+"\n")
- fix.Describef("Inserting a line %q after this line.", text)
+ fix.Describef(fix.lines[len(fix.lines)-1].Lineno, "Inserting a line %q after this line.", text)
}
func (fix *Autofix) Delete() {
@@ -91,34 +155,40 @@
}
for _, line := range fix.lines {
+ fix.Describef(line.Lineno, "Deleting this line.")
line.textnl = ""
}
- fix.Describef("Deleting this line.")
}
-func (fix *Autofix) Describef(format string, args ...interface{}) {
- fix.descrFormat = format
- fix.descrArgs = args
+// Describef remembers a description of the actual fix
+// for logging it later when Apply is called.
+// There may be multiple fixes in one pass.
+func (fix *Autofix) Describef(lineno int, format string, args ...interface{}) {
+ fix.actions = append(fix.actions, autofixAction{fmt.Sprintf(format, args...), lineno})
}
+// Notef remembers the note for logging it later when Apply is called.
func (fix *Autofix) Notef(format string, args ...interface{}) {
fix.level = llNote
fix.diagFormat = format
fix.diagArgs = args
}
+// Notef remembers the warning for logging it later when Apply is called.
func (fix *Autofix) Warnf(format string, args ...interface{}) {
fix.level = llWarn
fix.diagFormat = format
fix.diagArgs = args
}
+// Notef remembers the error for logging it later when Apply is called.
func (fix *Autofix) Errorf(format string, args ...interface{}) {
fix.level = llError
fix.diagFormat = format
fix.diagArgs = args
}
+// Explain remembers the explanation for logging it later when Apply is called.
func (fix *Autofix) Explain(explanation ...string) {
fix.explanation = explanation
}
@@ -134,17 +204,19 @@
return
}
- if shallBeLogged(fix.diagFormat) && fix.descrFormat != "" {
- logDiagnostic := fix.level != nil && fix.diagFormat != "Silent-Magic-Diagnostic" && !G.opts.Autofix
+ if shallBeLogged(fix.diagFormat) {
+ logDiagnostic := fix.level != nil && fix.diagFormat != "Silent-Magic-Diagnostic" &&
+ !(G.opts.Autofix && !G.opts.PrintAutofix) && len(fix.actions) > 0
if logDiagnostic {
msg := fmt.Sprintf(fix.diagFormat, fix.diagArgs...)
logs(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
}
- logRepair := G.opts.Autofix || G.opts.PrintAutofix
+ logRepair := len(fix.actions) > 0 && (G.opts.Autofix || G.opts.PrintAutofix)
if logRepair {
- msg := fmt.Sprintf(fix.descrFormat, fix.descrArgs...)
- logs(llAutofix, line.Filename, line.Linenos(), "", msg)
+ for _, action := range fix.actions {
+ logs(llAutofix, line.Filename, strconv.Itoa(action.lineno), "", action.description)
+ }
}
if logDiagnostic || logRepair {
@@ -157,10 +229,9 @@
}
}
- fix.modified = fix.modified || fix.descrFormat != ""
+ fix.modified = fix.modified || len(fix.actions) > 0
- fix.descrFormat = ""
- fix.descrArgs = nil
+ fix.actions = nil
fix.level = nil
fix.diagFormat = ""
fix.diagArgs = nil
@@ -168,6 +239,7 @@
}
func (fix *Autofix) skip() bool {
+ // This check is necessary for the --only command line option.
if fix.diagFormat == "" {
panic("Autofix: The diagnostic must be given before the action.")
}
@@ -230,8 +302,6 @@
NewLineWhole(fname).Errorf("Cannot overwrite with auto-fixed content.")
continue
}
- msg := "Has been auto-fixed. Please re-run pkglint."
- logs(llAutofix, fname, "", msg, msg)
autofixed = true
}
return
diff -r 5ec69ff2f9c2 -r 40769a5e5ec8 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go Sat Jan 27 18:24:16 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go Sat Jan 27 18:50:36 2018 +0000
@@ -3,13 +3,13 @@
import "gopkg.in/check.v1"
func (s *Suite) Test_Autofix_ReplaceRegex(c *check.C) {
- s.Init(c)
- s.UseCommandLine("--show-autofix")
- fname := s.CreateTmpFile("Makefile", ""+
- "line1\n"+
- "line2\n"+
- "line3\n")
- lines := LoadExistingLines(fname, true)
+ t := s.Init(c)
+
+ t.SetupCommandLine("--show-autofix")
+ lines := t.SetupFileLines("Makefile",
+ "line1",
+ "line2",
+ "line3")
fix := lines[1].Autofix()
fix.Warnf("Something's wrong here.")
@@ -18,20 +18,23 @@
SaveAutofixChanges(lines)
c.Check(lines[1].raw[0].textnl, equals, "XXXXX\n")
- c.Check(s.LoadTmpFile("Makefile"), equals, "line1\nline2\nline3\n")
- s.CheckOutputLines(
+ t.CheckFileLines("Makefile",
+ "line1",
+ "line2",
+ "line3")
+ t.CheckOutputLines(
"WARN: ~/Makefile:2: Something's wrong here.",
Home |
Main Index |
Thread Index |
Old Index