From edc4845414d1afc58ec374519f125d49094ba3e1 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Thu, 4 Nov 2021 15:07:58 +0300 Subject: [PATCH] runes: update preferWriteByte --- checkers/rules/rules.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/checkers/rules/rules.go b/checkers/rules/rules.go index 188ac3c66..c0c839f12 100644 --- a/checkers/rules/rules.go +++ b/checkers/rules/rules.go @@ -329,14 +329,15 @@ func assignOp(m dsl.Matcher) { m.Match(`$x = $x &^ $y`).Where(m["x"].Pure).Report("replace `$$` with `$x &^= $y`") } -//doc:summary Detects WriteRune calls with byte literal argument and reports to use WriteByte instead -//doc:tags performance experimental +//doc:summary Detects WriteRune calls with rune literal argument that is single byte and reports to use WriteByte instead +//doc:tags performance experimental opionated //doc:before w.WriteRune('\n') //doc:after w.WriteByte('\n') func preferWriteByte(m dsl.Matcher) { + const runeSelf = 0x80 // utf8.RuneSelf m.Match(`$w.WriteRune($c)`).Where( - m["w"].Type.Implements("io.ByteWriter") && (m["c"].Const && m["c"].Value.Int() < 256), - ).Report(`consider replacing $$ with $w.WriteByte($c)`) + m["w"].Type.Implements("io.ByteWriter") && (m["c"].Const && m["c"].Value.Int() < 0x80), + ).Report(`consider writing single byte rune $$ with $w.WriteByte($c)`) } //doc:summary Detects fmt.Sprint(f/ln) calls which can be replaced with fmt.Fprint(f/ln)