julz / importas

linter to enforce consistent import aliases
Apache License 2.0
14 stars 12 forks source link

Rule Order #12

Open Snowman7785 opened 1 year ago

Snowman7785 commented 1 year ago

Would it be possible to get the order of the rules respected internally? With the rules being put into a map, the order is different from run to run. When utilizing the regexp rules, it would be helpful to be able to rely on the order so you can get progressively broader in the rules.

codyaray commented 1 year ago

💯 I'm running into this non-deterministic behavior as well.

I'm using this via https://golangci-lint.run and have a configuration like

  importas:
    alias:
      - pkg: github.com/go-kit/log
        alias: kitlog
      - pkg: github.com/foo/bar/scheduler/(v[\w\d]+)
        alias: sched$1
      - pkg: github.com/foo/bar.*/(\w+)/(v[\w\d]+)
        alias: $1$2

unfortunately I randomly see errors like

grpcclient/clients_scheduler.go:8:2: import "github.com/foo/bar/scheduler/v1" imported as "schedv1" but must be "schedulerv1" according to config (importas)
        schedv1 "github.com/foo/bar/scheduler/v1"

In these cases, the last rule in the order is taking precedence, when my intention was for the first rule to match and take precedence.

thanks!

grosser commented 12 hours ago

fix https://github.com/julz/importas/pull/24