Functions to create and read data about the project's dependencies.
You may need to use use this module if you want
elm-review
run in a new environmentYou 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.
name : Dependency -> String
Get the name of the dependency.
elmJson : Dependency -> Elm.Project.Project
Get the contents of the project's elm.json
file.
modules : Dependency -> List Elm.Docs.Module
Get the list of modules contained in the dependency.
create : String -> Elm.Project.Project -> List Elm.Docs.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": {}
}
"""