jfmengels/elm-review/2.9.2

NOTE: the latest version is 2.16.6

Review.Project.Dependency

Functions to create and read data about the project's dependencies.

You may need to use use this module if you want

  • to create test cases where the project has specific dependencies
  • to make elm-review run in a new environment

You can safely ignore this module if you just want to write a review rule that does not look at the project's dependencies.

Represents a dependency of the project.

Access

name : Dependency -> String

Get the name of the dependency.

modules : Dependency -> List Module

Get the list of modules contained in the dependency.

Creation

create : String -> Project -> List Module -> Dependency

Create a dependency.

You will need to use this if you try to make elm-review run in a new environment, but you can safely ignore it if you just want to write a review rule or run it in existing environments like the CLI tool.

You could something like the following to create a test project in your tests.

import Elm.Docs
import Elm.Project
import Elm.Type as Type
import Json.Decode as Decode
import Review.Project as Project exposing (Project)
import Review.Project.Dependency as Dependency exposing (Dependency)


testProject : Project
testProject =
    Project.new
        |> Project.addDependency dependency


dependency : Dependency
dependency =
    Dependency.create
        "author/dependency"
        (createElmJson rawElmJson)
        modules


modules : List Elm.Docs.Module
modules =
    [ { name = "Foo"
      , comment = ""
      , unions = []
      , aliases = []
      , values =
            [ { name = "someFunction"
              , comment = ""
              , tipe = Type.Lambda (Type.Var "a") (Type.Var "b")
              }
            ]
      , binops = []
      }
    ]


createElmJson : String -> Elm.Project.Project
createElmJson rawElmJson =
    case Decode.decodeString Elm.Project.decoder rawElmJson of
        Ok elmJson ->
            elmJson


        Err _ ->
            Debug.todo "Invalid elm.json contents in tests"


rawElmJson : String
rawElmJson =
    """
{
  "type": "package",
  "name": "author/dependency",
  "summary": "Summary",
  "license": "MIT",
  "version": "1.0.0",
  "exposed-modules": [
    "Foo"
  ],
  "elm-version": "0.19.0 <= v < 0.20.0",
  "dependencies": {
    "elm/core": "1.0.0 <= v < 2.0.0"
  },
  "test-dependencies": {}
}
"""