Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoModuleOnExposedName fix can introduce name collision #36

Open
MartinSStewart opened this issue Oct 20, 2020 · 6 comments
Open

NoModuleOnExposedName fix can introduce name collision #36

MartinSStewart opened this issue Oct 20, 2020 · 6 comments
Labels
bug Something isn't working NoModuleOnExposedNames Relates to the NoModuleOnExposedNames rule

Comments

@MartinSStewart
Copy link

MartinSStewart commented Oct 20, 2020

In the following rule, NoModuleOnExposedName will suggest a fix by replacing convert : Color -> Element.Color with convert : Color -> Color which will lead to a compile error. It should instead suggest removing Color from exposing or not suggest any fix in this case.

import Element exposing (Color)

type Color = Red | Green | Blue

convert : Color -> Element.Color
convert color =
    ...

Edit: I think the correct behavior would be to not show an error at all. Consider this case:

import Subcomponent exposing (Msg(..))

type Msg = A | B

foo : Subcomponent.Msg
foo = 
   MsgVariantInSubComponent

Subcomponent.Msg can't be changed to Msg due to a name collision but exposing (Msg(..)) can't be removed either because of MsgVariantInSubComponent.

@sparksp
Copy link
Owner

sparksp commented Oct 21, 2020

Ooo that's an interesting case there. I don't think this rule should be responsible for fixing your exposing (that's for another rule in this package perhaps) but I'll certainly take a look to remove the auto-fix in this case.

@sparksp sparksp added the bug Something isn't working label Oct 21, 2020
@MartinSStewart
Copy link
Author

To be clear, I think the second example shouldn't be an error at all due to there being no good way to fix it. I agree the first example should just not have an auto-fix though.

@sparksp
Copy link
Owner

sparksp commented Oct 21, 2020

There are a number of 'good' ways the second can be fixed... the author could choose not to expose the Subcomponent's Msg variants and fully qualify all their subcomponent use or they could choose to rename the local Msg type so there's no shadowing.

What happens if the author decides to add MsgVariantInSubComponent to a local type or import it again from another module? The compiler will then complain about a type mismatch, the author will need to prefix the module name, and the exposing becomes further pointless.

Personally, I'm not a fan of imports exposing type constructors because it makes it much harder (even than normal imports) to figure out where things are coming from.

@jfmengels
Copy link

I agree with @sparksp that there are multiple ways to fix the issue, qualified imports of the constructors being one of them.

But I think that the original example as it is is just fine too and that there is not a lot of ways the situation can be improved upon without potentially a lot of (manual) renaming. I therefore think the rule should not report an error in the case where the imported type is the same as a local type (and probably the same thing for values?).

@MartinSStewart
Copy link
Author

MartinSStewart commented Oct 21, 2020

@sparksp Fair enough, I guess I'm okay with it showing an error but not an auto-fix in the second example as well. That said, if it is an error and you're feeling particularly motivated, maybe NoModuleOnExposedName could detect this situation and suggest to the user to not have Msg(..) and instead provide qualified names to the Msg variants.

@mthadley
Copy link

Ran into this situation as well, today.

Seems like folks have settled on "Don't report an error" in this case. Has anyone made any progress on adding that behavior to the rule?

@sparksp sparksp added the NoModuleOnExposedNames Relates to the NoModuleOnExposedNames rule label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working NoModuleOnExposedNames Relates to the NoModuleOnExposedNames rule
Projects
None yet
Development

No branches or pull requests

4 participants