mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-26 03:04:48 +03:00
Document the Review.Project.Dependency module
This commit is contained in:
parent
c141fdb1ae
commit
416357b236
@ -8,9 +8,13 @@ module Review.Project exposing
|
|||||||
{-| Represents the contents of the project to be analyzed. This information will
|
{-| Represents the contents of the project to be analyzed. This information will
|
||||||
then be fed to the review rules.
|
then be fed to the review rules.
|
||||||
|
|
||||||
Looking at this module is useful if you try to make `elm-review` run in a new environment,
|
You may need to use use this module if you want
|
||||||
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.
|
- to create test cases where the project is in a certain configuration
|
||||||
|
- 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 project information (like the `elm.json`, dependencies, ...).
|
||||||
|
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
|
@ -1,17 +1,31 @@
|
|||||||
module Review.Project.Dependency exposing
|
module Review.Project.Dependency exposing
|
||||||
( Dependency, create
|
( Dependency
|
||||||
, name, elmJson, modules
|
, name, elmJson, modules
|
||||||
|
, create
|
||||||
)
|
)
|
||||||
|
|
||||||
{-| TODO Documentation
|
{-| Functions to create and read data about the project's dependencies.
|
||||||
|
|
||||||
@docs Dependency, create
|
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.
|
||||||
|
|
||||||
|
@docs Dependency
|
||||||
|
|
||||||
|
|
||||||
# Access
|
# Access
|
||||||
|
|
||||||
@docs name, elmJson, modules
|
@docs name, elmJson, modules
|
||||||
|
|
||||||
|
|
||||||
|
# Create
|
||||||
|
|
||||||
|
@docs create
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
import Elm.Docs
|
import Elm.Docs
|
||||||
@ -22,7 +36,7 @@ import Elm.Project
|
|||||||
-- DEFINITION
|
-- DEFINITION
|
||||||
|
|
||||||
|
|
||||||
{-| TODO Documentation
|
{-| Represents a dependency of the project.
|
||||||
-}
|
-}
|
||||||
type Dependency
|
type Dependency
|
||||||
= Dependency
|
= Dependency
|
||||||
@ -32,7 +46,78 @@ type Dependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{-| TODO Documentation
|
{-| 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.withDependency
|
||||||
|
|
||||||
|
dependency : String -> Dependency
|
||||||
|
dependency license =
|
||||||
|
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": {}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
-}
|
-}
|
||||||
create : String -> Elm.Project.Project -> List Elm.Docs.Module -> Dependency
|
create : String -> Elm.Project.Project -> List Elm.Docs.Module -> Dependency
|
||||||
create name_ elmJson_ modules_ =
|
create name_ elmJson_ modules_ =
|
||||||
@ -47,22 +132,24 @@ create name_ elmJson_ modules_ =
|
|||||||
-- ACCESS
|
-- ACCESS
|
||||||
|
|
||||||
|
|
||||||
{-| TODO Documentation
|
{-| Get the name of the dependency.
|
||||||
-}
|
-}
|
||||||
name : Dependency -> String
|
name : Dependency -> String
|
||||||
name (Dependency dependency) =
|
name (Dependency dependency) =
|
||||||
dependency.name
|
dependency.name
|
||||||
|
|
||||||
|
|
||||||
{-| TODO Documentation
|
{-| Get the [contents of the project's `elm.json`](https://package.elm-lang.org/packages/elm/project-metadata-utils/1.0.1/Elm-Project#Project)
|
||||||
-}
|
file.
|
||||||
modules : Dependency -> List Elm.Docs.Module
|
|
||||||
modules (Dependency dependency) =
|
|
||||||
dependency.modules
|
|
||||||
|
|
||||||
|
|
||||||
{-| TODO Documentation
|
|
||||||
-}
|
-}
|
||||||
elmJson : Dependency -> Elm.Project.Project
|
elmJson : Dependency -> Elm.Project.Project
|
||||||
elmJson (Dependency dependency) =
|
elmJson (Dependency dependency) =
|
||||||
dependency.elmJson
|
dependency.elmJson
|
||||||
|
|
||||||
|
|
||||||
|
{-| Get the list of [modules](https://package.elm-lang.org/packages/elm/project-metadata-utils/1.0.1/Elm-Docs#Module)
|
||||||
|
contained in the dependency.
|
||||||
|
-}
|
||||||
|
modules : Dependency -> List Elm.Docs.Module
|
||||||
|
modules (Dependency dependency) =
|
||||||
|
dependency.modules
|
||||||
|
Loading…
Reference in New Issue
Block a user