jfmengels / elm-review

Analyzes Elm projects, to help find mistakes before your users find them.
https://package.elm-lang.org/packages/jfmengels/elm-review/latest/
Other
252 stars 13 forks source link

`removeRange`, `replaceRangeBy` with negative range duplicates that range #163

Open lue-bird opened 1 year ago

lue-bird commented 1 year ago

Describe the bug When the start Location is later in the document than end,

SSCCE (Short Self-Contained Correct Example) https://github.com/lue-bird/elm-review-sscce-negative-range

Expected behavior On the one hand it's good that you will notice that you've switched up start and end by having it duplicated; this exact behavior seems unintentional, though.

Possible alternatives are

Additional context Found this bug by accidentally messing up start and end locations.

jfmengels commented 1 year ago

I've noticed this problem as well before, and agree that this should not be the behavior. It's pretty cool to be able to duplicate code but I think it's rarely going to be useful the way it is now :sweat_smile:

Whenever we try to apply fixes, it is either going to be successful or create a Problem, and that is our way of reporting issues. And I agree that that should be the way forward. Adding a new variant there would be a semver breaking change unfortunately (which I don't want to happen right now). So either we find a workaround, or we create a ProblemV2 and a FixResultV2 types.

Maybe I should have a | OtherProblem String variant in order to be able to create future kinds of problems without a braking change.

We could also ignore this fix altogether, but I think that is going to be confusing. I think we should probably go for the duplicate types for ProblemV2.

lue-bird commented 1 year ago

Yeah I'm sure we can find more edge-cases like this one in the future, with negative locations or non-existent locations etc, so adding an | OtherProblem String variant as well seems future-proof. When some day v3 would come, all the found cases can then be explicitly added if it makes sense.