This document explains a some of the differences between elm-review
and ESLint
Documentation for each:
elm-review documentation: https://package.elm-lang.org/packages/jfmengels/elm-review/latest/
ESLint documentation: https://eslint.org/
rope: Branch [Leaf [],Branch [Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Branch [Branch [Branch [Branch [Leaf [],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf []]]],Leaf []]]],Leaf [],Branch [Leaf [],Leaf []],Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Branch [Leaf [],Branch [Leaf [],Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf [],Leaf [],Leaf [],Leaf []]],Branch [Leaf [],Leaf [],Leaf [],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf [],Branch [Leaf [],Leaf []],Branch [Leaf [],Branch [Leaf [],Branch [Branch [Leaf [],Leaf [],Leaf []],Leaf []],Leaf []]],Leaf []]],Branch [Leaf [],Leaf [] |
/* Corresponds to the following Elm code | |
map fn list = | |
case list of | |
[] -> [] | |
x :: xs -> | |
fn x :: map fn xs | |
*/ |
module NoMissingTypeConstructor exposing (rule) | |
import Dict exposing (Dict) | |
import Elm.Syntax.Declaration as Declaration exposing (Declaration) | |
import Elm.Syntax.Expression as Expression exposing (Expression) | |
import Elm.Syntax.ModuleName exposing (ModuleName) | |
import Elm.Syntax.Node as Node exposing (Node) | |
import Elm.Syntax.Type exposing (Type) | |
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) | |
import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable) |
removeRange : Node TypeAnnotation -> Node TypeAnnotation | |
removeRange (Node _ value) = | |
Node Range.emptyRange | |
(case value of | |
TypeAnnotation.FunctionTypeAnnotation input output -> | |
TypeAnnotation.FunctionTypeAnnotation (removeRange input) (removeRange output) | |
TypeAnnotation.Typed (Node _ nameNode) params -> | |
TypeAnnotation.Typed (Node Range.emptyRange nameNode) (List.map removeRange params) |
This document explains a some of the differences between elm-review
and ESLint
Documentation for each:
elm-review documentation: https://package.elm-lang.org/packages/jfmengels/elm-review/latest/
ESLint documentation: https://eslint.org/
module NoMissingVariants exposing (rule) | |
import Dict exposing (Dict) | |
import Elm.Syntax.Declaration as Declaration exposing (Declaration) | |
import Elm.Syntax.Expression as Expression exposing (Expression) | |
import Elm.Syntax.Node as Node exposing (Node) | |
import Elm.Syntax.Type exposing (Type) | |
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) | |
import Review.Rule as Rule exposing (Error, Rule) | |
import Set exposing (Set) |
Imagine you try to design "factories". You have factories that can build Diesel cars, and factories that can build any kind of car (Diesel and Gas, but other kinds of cars could exist). Let's say you want the user to be able to create their customized car factory, for which you provide an API, like
I have a module Factory which defines a Factory and a Car type, all opaque. I provide two functions createCarFactory
and createDieselCarFactory
, where the first one takes a use-provided function that can return a list of any cars (and they can be mixed), and the second one can only generate Diesel cars.
I want the garantee as the module author, that users won't be able to provide functions that create cars other than diesel cars in the createDieselCarFactory
, while still allowing to create any kind of car with the createCarFactory
function.
I want the type system to be the one to complain if these guarantees are not respected by the user.
module NoMissingTypeConstructor exposing (rule) | |
import Dict exposing (Dict) | |
import Elm.Syntax.Declaration as Declaration exposing (Declaration) | |
import Elm.Syntax.Expression as Expression exposing (Expression) | |
import Elm.Syntax.Node as Node exposing (Node) | |
import Elm.Syntax.Type exposing (Type) | |
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) | |
import Review.Rule as Rule exposing (Error, Rule) | |
import Set exposing (Set) |