From: Johannes Sixt Date: Fri, 26 Feb 2021 08:03:45 GMT Subject: Re: [PATCH v3 32/35] userdiff golang: add a rule to match "package" Message-ID: <6905d873-2cba-638b-bbfe-e652a16cd65c@kdbg.org> In-Reply-To: <20210224195129.4004-33-avarab@gmail.com> Am 24.02.21 um 20:51 schrieb Ævar Arnfjörð Bjarmason: > Improve the "golang" built-in pattern to match "package" lines, as > they weren't matched before changing e.g. the imports would commonly > result in an empty hunk header, now we'll instead show the package > name. > > I used https://blog.golang.org/package-names as a guide here, but > e.g. "foo_bar" is still valid syntax, so let's let it pass but veer on > the side of not having false positives. > > Signed-off-by: Ævar Arnfjörð Bjarmason > --- > t/t4018/golang | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ > userdiff.c | 2 ++ > 2 files changed, 51 insertions(+) > > diff --git a/t/t4018/golang b/t/t4018/golang > index 252b6049da4..38f254cd269 100644 > --- a/t/t4018/golang > +++ b/t/t4018/golang > @@ -1,3 +1,52 @@ > +t4018 description: package > +t4018 header: package main > +package main > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is selective -- ALLCAPS > +t4018 header: package main > +package ALLCAPS > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is selective -- CamelCase > +t4018 header: package main > +package CamelCase > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is selective -- 123 > +t4018 header: package main > +package 123 > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is not overly selective -- x509 > +t4018 header: package x509 > +package x509 > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is not overly selective -- underbars > +t4018 header: package not_conventional > +package not_conventional > + > +import "fmt" > +// ChangeMe > + > +t4018 description: package regex is not overly selective -- camelCase > +t4018 header: package camelCase > +package camelCase > + > +import "fmt" > +// ChangeMe > + > t4018 description: complex function > t4018 header: func (t *Test) RIGHT(a Type) (Type, error) { > type Test struct { > diff --git a/userdiff.c b/userdiff.c > index 704af241e44..bbbbfa33e0a 100644 > --- a/userdiff.c > +++ b/userdiff.c > @@ -128,6 +128,8 @@ IPATTERN("fountain", > /* -- */ > "[^ \t-]+"), > PATTERNS("golang", > + /* Packages */ > + "^(package[ \t][a-z][A-Za-z0-9_]+)[ \t]*\n" Just a single whitespace character is permitted between the keyword and the name? > /* Functions */ > "^(func[ \t].*)\n" > /* Structs and interfaces */ >