Skip to content

Import shadowing should not react to names like "v2" from imports like "math/rand/v2" #1435

@autarch

Description

@autarch

Describe the bug

If you have an import like "math/rand/v2" and a variable named v2, revive will flag this as shadowing the import, even though the import ends up named rand, not v2.

To Reproduce

I made a repo that demonstrates the issue at https://github.com/autarch/revive-test

The config just looks like this:

enableAllRules = true

The code in main.go is this:

// main is a test package.
package main

import (
	"fmt"
	"math/rand/v2"
)

func main() {
	v2 := "foo"
	fmt.Println(v2)
	fmt.Println(rand.Int())
}

Expected behavior

I would not expect revive to flag any issues with this code. But using the latest revive, I get this:

$> revive -version
version 1.11.0
$> revive -config ./revive.toml ./main.go
./main.go:10:2: The name 'v2' shadows an import name

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions