blob: 69223b1f668df7f9f84b18ffdbb1ddba677eaf09 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Lorenz Bruncb2dcf62021-11-22 22:57:34 +01004// Package noioutil contains a Go analysis pass designed to prevent use of the
5// deprecated ioutil package for which a tree-wide migration was already done.
6package noioutil
7
8import (
Lorenz Bruncb2dcf62021-11-22 22:57:34 +01009 "strconv"
Lorenz Bruncb2dcf62021-11-22 22:57:34 +010010
11 "golang.org/x/tools/go/analysis"
Serge Bazanski8bd2ab12021-12-17 17:32:16 +010012
13 alib "source.monogon.dev/build/analysis/lib"
Lorenz Bruncb2dcf62021-11-22 22:57:34 +010014)
15
16var Analyzer = &analysis.Analyzer{
17 Name: "noioutil",
18 Doc: "noioutil checks for imports of the deprecated ioutil package",
19 Run: run,
20}
21
22func run(p *analysis.Pass) (interface{}, error) {
23 for _, file := range p.Files {
Serge Bazanski8bd2ab12021-12-17 17:32:16 +010024 if alib.IsGeneratedFile(file) {
Lorenz Bruncb2dcf62021-11-22 22:57:34 +010025 continue
26 }
27 for _, i := range file.Imports {
28 importPath, err := strconv.Unquote(i.Path.Value)
29 if err != nil {
30 continue
31 }
32 if importPath == "io/ioutil" {
33 p.Report(analysis.Diagnostic{
34 Pos: i.Path.ValuePos,
35 End: i.Path.End(),
36 Message: "File imports the deprecated io/ioutil package. See https://pkg.go.dev/io/ioutil for replacements.",
37 })
38 }
39 }
40 }
41
42 return nil, nil
43}