-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip linters early if affected package is not imported
Skip the ioreadall, slowg and timeafter linters early if the respective packages they check for (i.e. io, slog/log, golang.org/x/exp/slog and time) is not imported by the package that is currently analyzed. This should reduce linter run time a bit on packages that don't import any of the checked packages. Signed-off-by: Tobias Klauser <[email protected]>
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
// Package analysisutil defines helper functions used by more than one linters. | ||
package analysisutil | ||
|
||
import "go/types" | ||
|
||
// ImportsPackage reports whether path is imported by pkg. | ||
// | ||
// Copied from | ||
// golang.org/x/tools/go/analysis/passes/internal/analysisutil.Imports | ||
func ImportsPackage(pkg *types.Package, path string) bool { | ||
for _, imp := range pkg.Imports() { | ||
if imp.Path() == path { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters