version 1.36, 2018/12/02 23:12:43 |
version 1.37, 2018/12/17 00:15:39 |
|
|
package main |
package pkglint |
|
|
import ( |
import ( |
"strings" |
"strings" |
Line 349 func (mklines *MkLinesImpl) collectDocum |
|
Line 349 func (mklines *MkLinesImpl) collectDocum |
|
commentLines := 0 |
commentLines := 0 |
relevant := true |
relevant := true |
|
|
|
// TODO: Correctly interpret declarations like "package-settable variables:" and |
|
// TODO: "user-settable variables", as well as "default: ...", "allowed: ...", |
|
// TODO: "list of" and other types. |
|
|
finish := func() { |
finish := func() { |
if commentLines >= 3 && relevant { |
if commentLines >= 3 && relevant { |
for varname, mkline := range scope.used { |
for varname, mkline := range scope.used { |
|
mklines.vars.Define(varname, mkline) |
mklines.vars.Use(varname, mkline) |
mklines.vars.Use(varname, mkline) |
} |
} |
} |
} |
Line 379 func (mklines *MkLinesImpl) collectDocum |
|
Line 384 func (mklines *MkLinesImpl) collectDocum |
|
} |
} |
parser.lexer.SkipByte(':') |
parser.lexer.SkipByte(':') |
|
|
varbase := varnameBase(varname) |
varcanon := varnameCanon(varname) |
if varbase == strings.ToUpper(varbase) && matches(varbase, `[A-Z]`) && parser.EOF() { |
if varcanon == strings.ToUpper(varcanon) && matches(varcanon, `[A-Z]`) && parser.EOF() { |
scope.Use(varname, mkline) |
scope.Define(varcanon, mkline) |
|
scope.Use(varcanon, mkline) |
} |
} |
|
|
if 1 < len(words) && words[1] == "Copyright" { |
if 1 < len(words) && words[1] == "Copyright" { |
Line 420 func (mklines *MkLinesImpl) CheckRedunda |
|
Line 426 func (mklines *MkLinesImpl) CheckRedunda |
|
old.Warnf("Variable %s is overwritten in %s.", new.Varname(), old.RefTo(new)) |
old.Warnf("Variable %s is overwritten in %s.", new.Varname(), old.RefTo(new)) |
G.Explain( |
G.Explain( |
"The variable definition in this line does not have an effect since", |
"The variable definition in this line does not have an effect since", |
"it is overwritten elsewhere. This typically happens because of a", |
"it is overwritten elsewhere.", |
"typo (writing = instead of +=) or because the line that overwrites", |
"This typically happens because of a typo (writing = instead of +=)", |
|
"or because the line that overwrites", |
"is in another file that is used by several packages.") |
"is in another file that is used by several packages.") |
} |
} |
} |
} |
Line 429 func (mklines *MkLinesImpl) CheckRedunda |
|
Line 436 func (mklines *MkLinesImpl) CheckRedunda |
|
mklines.ForEach(scope.Handle) |
mklines.ForEach(scope.Handle) |
} |
} |
|
|
|
// CheckForUsedComment checks that this file (a Makefile.common) has the given |
|
// relativeName in one of the "# used by" comments at the beginning of the file. |
func (mklines *MkLinesImpl) CheckForUsedComment(relativeName string) { |
func (mklines *MkLinesImpl) CheckForUsedComment(relativeName string) { |
lines := mklines.lines |
lines := mklines.lines |
if lines.Len() < 3 { |
if lines.Len() < 3 { |
Line 447 func (mklines *MkLinesImpl) CheckForUsed |
|
Line 456 func (mklines *MkLinesImpl) CheckForUsed |
|
i++ |
i++ |
} |
} |
|
|
|
// TODO: Sort the comments. |
|
// TODO: Discuss whether these comments are actually helpful. |
|
|
fix := lines.Lines[i].Autofix() |
fix := lines.Lines[i].Autofix() |
fix.Warnf("Please add a line %q here.", expected) |
fix.Warnf("Please add a line %q here.", expected) |
fix.Explain( |
fix.Explain( |
"Since Makefile.common files usually don't have any comments and", |
"Since Makefile.common files usually don't have any comments and", |
"therefore not a clearly defined interface, they should at least", |
"therefore not a clearly defined purpose, they should at least", |
"contain references to all files that include them, so that it is", |
"contain references to all files that include them, so that it is", |
"easier to see what effects future changes may have.", |
"easier to see what effects future changes may have.", |
"", |
"", |
"If there are more than five packages that use a Makefile.common,", |
"If there are more than five packages that use a Makefile.common,", |
"you should think about giving it a proper name (maybe plugin.mk) and", |
"that file should have a clearly defined and documented purpose,", |
"documenting its interface.") |
"and the filename should reflect that purpose.", |
|
"Typical names are module.mk, plugin.mk or version.mk.") |
fix.InsertBefore(expected) |
fix.InsertBefore(expected) |
fix.Apply() |
fix.Apply() |
|
|