Added a check for unused imports

This commit is contained in:
Eduard Urbach 2024-07-31 11:55:21 +02:00
parent 9ea99c97c4
commit 2d905c1ac0
Signed by: eduard
GPG key ID: 49226B848C78F6C8
14 changed files with 138 additions and 31 deletions

View file

@ -26,11 +26,14 @@ func (s *Scanner) scanFile(path string, pkg string) error {
tokens := token.Tokenize(contents)
file := &fs.File{
Path: path,
Bytes: contents,
Tokens: tokens,
Path: path,
Bytes: contents,
Tokens: tokens,
Package: pkg,
}
s.files <- file
var (
i = 0
groupLevel = 0
@ -50,8 +53,20 @@ func (s *Scanner) scanFile(path string, pkg string) error {
}
packageName := tokens[i].Text(contents)
s.queueDirectory(filepath.Join(config.Library, packageName), packageName)
if file.Imports == nil {
file.Imports = map[string]*fs.Import{}
}
fullPath := filepath.Join(config.Library, packageName)
file.Imports[packageName] = &fs.Import{
Path: packageName,
FullPath: fullPath,
Position: tokens[i].Position,
}
s.queueDirectory(fullPath, packageName)
i++
if tokens[i].Kind != token.NewLine && tokens[i].Kind != token.EOF {