Skip to content

Commit

Permalink
More advice from deepsource.io
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Mar 22, 2021
1 parent f55edf4 commit 42851b8
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 27 deletions.
11 changes: 0 additions & 11 deletions cmd/minify/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ func DirFS(dir string) FS {
return dirFS(dir)
}

func containsAny(s, chars string) bool {
for i := 0; i < len(s); i++ {
for j := 0; j < len(chars); j++ {
if s[i] == chars[j] {
return true
}
}
}
return false
}

type dirFS string

func (dir dirFS) Open(name string) (*os.File, error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/minify/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func TestConcat(t *testing.T) {
}

func TestConcatErr(t *testing.T) {
r, err := newConcatFileReader([]string{"err"}, testOpener)
_, err := newConcatFileReader([]string{"err"}, testOpener)
test.T(t, err, test.ErrPlain)

r, err = newConcatFileReader([]string{"test", "err"}, testOpener)
r, err := newConcatFileReader([]string{"test", "err"}, testOpener)
test.T(t, err, nil)

buf := make([]byte, 10)
Expand Down
4 changes: 2 additions & 2 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
if name := attrs[3]; name != nil {
name.AttrVal = parse.TrimWhitespace(name.AttrVal)
if parse.EqualFold(name.AttrVal, []byte("keywords")) {
content.AttrVal = bytes.Replace(content.AttrVal, []byte(", "), []byte(","), -1)
content.AttrVal = bytes.ReplaceAll(content.AttrVal, []byte(", "), []byte(","))
} else if parse.EqualFold(name.AttrVal, []byte("viewport")) {
content.AttrVal = bytes.Replace(content.AttrVal, []byte(" "), []byte(""), -1)
content.AttrVal = bytes.ReplaceAll(content.AttrVal, []byte(" "), []byte(""))
for i := 0; i < len(content.AttrVal); i++ {
if content.AttrVal[i] == '=' && i+2 < len(content.AttrVal) {
i++
Expand Down
2 changes: 0 additions & 2 deletions js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ func (m *jsMinifier) minifyStmt(i js.IStmt) {
m.writeSpaceBeforeIdent()
m.minifyExpr(stmt.Value, js.OpAssign)
m.write(closeParenBytes)
if len(stmt.Body.List) == 1 {
}
m.minifyBlockAsStmt(&stmt.Body, iterationBlock)
case *js.SwitchStmt:
m.write(switchOpenBytes)
Expand Down
5 changes: 0 additions & 5 deletions js/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var (
openBracketBytes = []byte("[")
closeBracketBytes = []byte("]")
openParenBracketBytes = []byte("({")
closeBracketParenBytes = []byte("})")
closeParenOpenBracketBytes = []byte("){")
notBytes = []byte("!")
questionBytes = []byte("?")
Expand All @@ -34,7 +33,6 @@ var (
andBytes = []byte("&&")
orBytes = []byte("||")
optChainBytes = []byte("?.")
nullishBytes = []byte("??")
arrowBytes = []byte("=>")
zeroBytes = []byte("0")
oneBytes = []byte("1")
Expand Down Expand Up @@ -72,8 +70,6 @@ var (
openNewBytes = []byte("(new")
newTargetBytes = []byte("new.target")
importMetaBytes = []byte("import.meta")
varBytes = []byte("var")
varSpaceBytes = []byte("var ")
nanBytes = []byte("NaN")
undefinedBytes = []byte("undefined")
infinityBytes = []byte("Infinity")
Expand All @@ -85,7 +81,6 @@ var (
groupedNotZeroBytes = []byte("(!0)")
notOneBytes = []byte("!1")
groupedNotOneBytes = []byte("(!1)")
useStrictBytes = []byte(`"use strict"`)
debuggerBytes = []byte("debugger")
)

Expand Down
5 changes: 3 additions & 2 deletions minify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,16 @@ func TestHelperProcess(*testing.T) {
os.Exit(1)
return
}
defer w.Close()

b, err := ioutil.ReadFile(in)
if err != nil {
w.WriteString(err.Error())
w.Close()
os.Exit(1)
return
}
_, _ = w.Write(b)
w.Close()
case "dummy/err":
fmt.Fprint(os.Stderr, "error")
os.Exit(1)
Expand All @@ -347,7 +348,7 @@ func ExampleM_Minify_custom() {
if err != nil && err != io.EOF {
return err
}
if _, errws := io.WriteString(w, strings.Replace(line, " ", "", -1)); errws != nil {
if _, errws := io.WriteString(w, strings.ReplaceAll(line, " ", "")); errws != nil {
return errws
}
if err == io.EOF {
Expand Down
3 changes: 0 additions & 3 deletions svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ var (
isBytes = []byte("=")
spaceBytes = []byte(" ")
cdataEndBytes = []byte("]]>")
pathBytes = []byte("<path")
dBytes = []byte("d")
zeroBytes = []byte("0")
n100pBytes = []byte("100%")
cssMimeBytes = []byte("text/css")
noneBytes = []byte("none")
urlBytes = []byte("url(")
Expand Down

0 comments on commit 42851b8

Please sign in to comment.