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

No functions in specified types #61

Closed MartinSStewart closed 3 years ago

MartinSStewart commented 4 years ago

What the rule should do: The rule will be provided a list of types and check if any of those types contains a function. Any type referenced by those types must not contain functions either. This is a stopgap solution until Elm supports an equatable typeclass which will automatically enforce this behavior.

Example of things the rule would report:

module Main exposing (..)

type alias Model = {
    a : Int -> Int
}

Model will be marked as an error (assuming we've configured the rule to check for Main.Model).

module Main

import Image

type Msg
    = NoOp
    | LoadedImage Image

Msg will be marked as an error (assuming we've configured the rule to check for Main.Msg) because Image (from justgook/elm-image) contains a function. This is largely what this rule is intended for, sparing the user from having to go through the internally defined types in packages checking if there's a function in some unexpected place.

I am looking for:

sparksp commented 4 years ago

Although we can't currently check the source of dependencies, a first pass of this rule could be written that's only aware of what's in your project. The question then is whether there's value in being able to do this if you can't check dependencies?

You could also have a blacklist; this may not be so useful for solo projects, but larger teams may benefit from this.

MartinSStewart commented 4 years ago

In the 4-5 times I've accidentally added a function to my model/msg type, it's always been due to a package storing a function in some unexpected place. For that reason I don't think there's much value in only checking user code.

A black list could work for larger teams but it would still require someone to go through packages and find the types that need to be blacklisted. It seems like too much effort to be worthwhile.