From 20097e45e63022c5480dea7ccb3db8712288b828 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 4 Sep 2024 18:27:41 -0400 Subject: [PATCH 1/3] all: fix printf(var) mistakes detected by latest printf checker The CodeWriter.WriteComment method is odd. It calls fmt.Sprintf on its arguments so the caller doesn't need to, but isn't named something like WriteCommentf as I'd expect. I tried renaming it, but it became a bigger change than I wanted. Leaving that for a future CL - this one just fixes clear mistakes to fix the build. For golang/go#69267. Change-Id: Ifba42d4512696194fbf21d6c8d3da76440b1ce9e Reviewed-on: https://go-review.googlesource.com/c/text/+/610676 Reviewed-by: Tim King Reviewed-by: Ian Lance Taylor Auto-Submit: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- collate/build/builder_test.go | 2 +- collate/build/trie_test.go | 2 +- internal/cldrtree/generate.go | 2 +- internal/gen/code.go | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/collate/build/builder_test.go b/collate/build/builder_test.go index ff0aba3ae..0e022ecb9 100644 --- a/collate/build/builder_test.go +++ b/collate/build/builder_test.go @@ -65,7 +65,7 @@ func newBuilder(t *testing.T, ducet []ducetElem) *Builder { ces = append(ces, ce.w) } if err := b.Add([]rune(e.str), ces, nil); err != nil { - t.Errorf(err.Error()) + t.Error(err) } } b.t = &table{} diff --git a/collate/build/trie_test.go b/collate/build/trie_test.go index 4d4f6e4d1..5109e0915 100644 --- a/collate/build/trie_test.go +++ b/collate/build/trie_test.go @@ -29,7 +29,7 @@ func makeTestTrie(t *testing.T) trie { idx.addTrie(n) tr, err := idx.generate() if err != nil { - t.Errorf(err.Error()) + t.Error(err) } return *tr } diff --git a/internal/cldrtree/generate.go b/internal/cldrtree/generate.go index 0f0b5f3be..bdd77ce83 100644 --- a/internal/cldrtree/generate.go +++ b/internal/cldrtree/generate.go @@ -21,7 +21,7 @@ func generate(b *Builder, t *Tree, w *gen.CodeWriter) error { fmt.Fprintf(w, "var tree = &cldrtree.Tree{locales, indices, buckets}\n\n") - w.WriteComment("Path values:\n" + b.stats()) + w.WriteComment("Path values:\n%s", b.stats()) fmt.Fprintln(w) // Generate enum types. diff --git a/internal/gen/code.go b/internal/gen/code.go index 75435c9bd..fa4002b4c 100644 --- a/internal/gen/code.go +++ b/internal/gen/code.go @@ -342,8 +342,7 @@ func (w *CodeWriter) writeSlice(x interface{}, isArray bool) { if !reflect.DeepEqual(zero, x) { line := fmt.Sprintf("%#v,\n", x) line = line[strings.IndexByte(line, '{'):] - w.printf("%d: ", i) - w.printf(line) + w.printf("%d: %s", i, line) } } case reflect.Array: From 38a95c2d4a4bd3b96a28705c9a2d47874067ec6d Mon Sep 17 00:00:00 2001 From: cuishuang Date: Mon, 9 Sep 2024 15:09:38 +0800 Subject: [PATCH 2/3] all: fix some comments Change-Id: I6ba7a9de50acfa522d96609abead28d207ab4f81 Reviewed-on: https://go-review.googlesource.com/c/text/+/611795 Reviewed-by: Dmitri Shuralyov Reviewed-by: Tim King Auto-Submit: Tim King Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- collate/build/colelem.go | 2 +- internal/catmsg/codec.go | 2 +- internal/colltab/collelem.go | 2 +- message/pipeline/pipeline.go | 2 +- unicode/norm/maketables.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/collate/build/colelem.go b/collate/build/colelem.go index 1aaa062c5..f51faa1a1 100644 --- a/collate/build/colelem.go +++ b/collate/build/colelem.go @@ -139,7 +139,7 @@ const ( maxPrimary = illegalOffset + 1 ) -// implicitPrimary returns the primary weight for the a rune +// implicitPrimary returns the primary weight for the given rune // for which there is no entry for the rune in the collation table. // We take a different approach from the one specified in // https://unicode.org/reports/tr10/#Implicit_Weights, diff --git a/internal/catmsg/codec.go b/internal/catmsg/codec.go index 49c9fc978..547802b0f 100644 --- a/internal/catmsg/codec.go +++ b/internal/catmsg/codec.go @@ -257,7 +257,7 @@ func (d *Decoder) setError(err error) { // Language returns the language in which the message is being rendered. // // The destination language may be a child language of the language used for -// encoding. For instance, a decoding language of "pt-PT"" is consistent with an +// encoding. For instance, a decoding language of "pt-PT" is consistent with an // encoding language of "pt". func (d *Decoder) Language() language.Tag { return d.tag } diff --git a/internal/colltab/collelem.go b/internal/colltab/collelem.go index 0c23c8a48..bdcae9b13 100644 --- a/internal/colltab/collelem.go +++ b/internal/colltab/collelem.go @@ -354,7 +354,7 @@ const ( maxPrimary = illegalOffset + 1 ) -// implicitPrimary returns the primary weight for the a rune +// implicitPrimary returns the primary weight for the given rune // for which there is no entry for the rune in the collation table. // We take a different approach from the one specified in // https://unicode.org/reports/tr10/#Implicit_Weights, diff --git a/message/pipeline/pipeline.go b/message/pipeline/pipeline.go index 34f15f8ab..2b07e38b6 100644 --- a/message/pipeline/pipeline.go +++ b/message/pipeline/pipeline.go @@ -58,7 +58,7 @@ type Config struct { // 1. From the Language field in the file. // 2. If not present, from a valid language tag in the filename, separated // by dots (e.g. "en-US.json" or "incoming.pt_PT.xmb"). - // 3. If not present, from a the closest subdirectory in which the file + // 3. If not present, from the closest subdirectory in which the file // is contained that parses as a valid language tag. TranslationsPattern string diff --git a/unicode/norm/maketables.go b/unicode/norm/maketables.go index 76534da20..09d40135c 100644 --- a/unicode/norm/maketables.go +++ b/unicode/norm/maketables.go @@ -235,7 +235,7 @@ func loadUnicodeData() { } } -// compactCCC converts the sparse set of CCC values to a continguous one, +// compactCCC converts the sparse set of CCC values to a contiguous one, // reducing the number of bits needed from 8 to 6. func compactCCC() { m := make(map[uint8]uint8) From 3043346206dbc748052ef6e130f428f895cd3760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Thu, 19 Sep 2024 16:19:56 +0200 Subject: [PATCH 3/3] x/text: Correct examples in number/doc Playground example: https://go.dev/play/p/9cuRyaNveO8 Change-Id: I2fbc3fec0f3755eb3d11b47edfb2201d66fc622d Reviewed-on: https://go-review.googlesource.com/c/text/+/614395 LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Marcel van Lohuizen Reviewed-by: Ian Lance Taylor Reviewed-by: Carlos Amedee --- number/doc.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/number/doc.go b/number/doc.go index 876623086..1999bc8f5 100644 --- a/number/doc.go +++ b/number/doc.go @@ -11,16 +11,15 @@ // // p := message.NewPrinter(language.English) // -// p.Printf("%v bottles of beer on the wall.", number.Decimal(1234)) +// p.Printf("%v bottles of beer on the wall.\n", number.Decimal(1234)) // // Prints: 1,234 bottles of beer on the wall. // -// p.Printf("%v of gophers lose too much fur", number.Percent(0.12)) +// p.Printf("%v of gophers lose too much fur.\n", number.Percent(0.12)) // // Prints: 12% of gophers lose too much fur. // -// p := message.NewPrinter(language.Dutch) -// -// p.Printf("There are %v bikes per household.", number.Decimal(1.2)) -// // Prints: Er zijn 1,2 fietsen per huishouden. +// p = message.NewPrinter(language.Dutch) +// p.Printf("There are %v bikes per household.\n", number.Decimal(1.2)) +// // Prints: There are 1,2 bikes per household. // // The width and scale specified in the formatting directives override the // configuration of the formatter.