Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions cli/gen-package/elm.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
{
"type": "application",
"source-directories": ["src", "codegen", "../../src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"Chadtech/elm-bool-extra": "2.4.2",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/project-metadata-utils": "1.0.2",
"elm-community/maybe-extra": "5.2.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.4",
"the-sett/elm-pretty-printer": "3.0.0"
"type": "application",
"source-directories": [
"src",
"codegen",
"../../src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/core": "1.0.5",
"elm/json": "1.1.3",
"elm/project-metadata-utils": "1.0.2",
"elmcraft/core-extra": "2.2.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.4",
"the-sett/elm-pretty-printer": "3.0.0"
},
"indirect": {
"elm/parser": "1.1.0",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.3.0",
"miniBill/elm-unicode": "1.0.2",
"stil4m/structured-writer": "1.0.3"
}
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.3.0",
"miniBill/elm-unicode": "1.0.2",
"stil4m/structured-writer": "1.0.3"
"test-dependencies": {
"direct": {
"elm-explorations/test": "2.2.0",
"miniBill/elm-diff": "1.1.0",
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"avh4/elm-color": "1.0.0",
"elm/bytes": "1.0.8",
"elm/html": "1.0.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
41 changes: 41 additions & 0 deletions cli/gen-package/review/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/core": "1.0.5",
"elm/json": "1.1.4",
"elm/project-metadata-utils": "1.0.2",
"jfmengels/elm-review": "2.15.3",
"jfmengels/elm-review-code-style": "1.2.0",
"jfmengels/elm-review-common": "1.3.3",
"jfmengels/elm-review-debug": "1.0.8",
"jfmengels/elm-review-documentation": "2.0.4",
"jfmengels/elm-review-simplify": "2.1.9",
"jfmengels/elm-review-unused": "1.2.4",
"stil4m/elm-syntax": "7.3.9"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/html": "1.0.0",
"elm/parser": "1.1.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.4",
"elm-explorations/test": "2.2.0",
"pzp1997/assoc-list": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/structured-writer": "1.0.3"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "2.2.0"
},
"indirect": {}
}
}
68 changes: 68 additions & 0 deletions cli/gen-package/review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module ReviewConfig exposing (config)

{-| Do not rename the ReviewConfig module or the config function, because
`elm-review` will look for these.

To add packages that contain rules, add them to this review project using

`elm install author/packagename`

when inside the directory containing this file.

-}

import Docs.NoMissing exposing (exposedModules, onlyExposed)
import Docs.ReviewAtDocs
import Docs.ReviewLinksAndSections
import Docs.UpToDateReadmeLinks
import NoConfusingPrefixOperator
import NoDebug.Log
import NoDebug.TodoOrToString
import NoExposingEverything
import NoImportingEverything
import NoMissingTypeAnnotation
import NoMissingTypeAnnotationInLetIn
import NoMissingTypeExpose
import NoPrematureLetComputation
import NoSimpleLetBody
import NoUnused.CustomTypeConstructorArgs
import NoUnused.CustomTypeConstructors
import NoUnused.Dependencies
import NoUnused.Exports
import NoUnused.Parameters
import NoUnused.Patterns
import NoUnused.Variables
import Review.Rule as Rule exposing (Rule)
import Simplify


config : List Rule
config =
[ NoUnused.Dependencies.rule
, Docs.NoMissing.rule
{ document = onlyExposed
, from = exposedModules
}
, Docs.ReviewLinksAndSections.rule
, Docs.ReviewAtDocs.rule
, Docs.UpToDateReadmeLinks.rule
, NoConfusingPrefixOperator.rule
, NoDebug.Log.rule
, NoDebug.TodoOrToString.rule
|> Rule.ignoreErrorsForDirectories [ "tests/" ]
, NoExposingEverything.rule
, NoImportingEverything.rule []
, NoMissingTypeAnnotation.rule
, NoMissingTypeAnnotationInLetIn.rule
, NoMissingTypeExpose.rule
, NoSimpleLetBody.rule
, NoPrematureLetComputation.rule
, NoUnused.CustomTypeConstructors.rule []
, NoUnused.CustomTypeConstructorArgs.rule
, NoUnused.Exports.rule
, NoUnused.Parameters.rule
, NoUnused.Patterns.rule
, NoUnused.Variables.rule
, Simplify.rule Simplify.defaults
]
|> List.map (Rule.ignoreErrorsForDirectories [ "..", "codegen/Gen" ])
8 changes: 8 additions & 0 deletions cli/gen-package/review/suppressed/NoUnused.Exports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"automatically created by": "elm-review suppress",
"learn more": "elm-review suppress --help",
"suppressions": [
{ "count": 1, "filePath": "src/Elm/Gen.elm" }
]
}
8 changes: 8 additions & 0 deletions cli/gen-package/review/suppressed/NoUnused.Variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"automatically created by": "elm-review suppress",
"learn more": "elm-review suppress --help",
"suppressions": [
{ "count": 4, "filePath": "src/Generate.elm" }
]
}
82 changes: 42 additions & 40 deletions cli/gen-package/src/DocsFromSource.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ toModuleNameAndExposed { moduleName, exposingList } =
( Node.value moduleName, All )

Node _ (Elm.Syntax.Exposing.Explicit exposedVals) ->
( Node.value moduleName, Explicit (List.map (exposeValue << Node.value) exposedVals) )
( Node.value moduleName, Explicit (List.map (\(Node _ exposedVal) -> exposeValue exposedVal) exposedVals) )


exposeValue : Elm.Syntax.Exposing.TopLevelExpose -> ExposedValue
exposeValue val =
case val of
Elm.Syntax.Exposing.InfixExpose str ->
Expand All @@ -75,6 +76,7 @@ exposeValue val =
ExposedConstructors name


isExposed : String -> Exposed -> Bool
isExposed name exposed =
case exposed of
All ->
Expand Down Expand Up @@ -146,6 +148,7 @@ toDocs file =
, aliases = imports.aliases
}

gathered : { values : List Elm.Docs.Value, aliases : List Elm.Docs.Alias, unions : List Elm.Docs.Union }
gathered =
List.foldl (gather context exposingSet)
{ values = []
Expand Down Expand Up @@ -255,8 +258,8 @@ gather :
, aliases : List Elm.Docs.Alias
, unions : List Elm.Docs.Union
}
gather context exposed node found =
case Node.value node of
gather context exposed (Node _ node) found =
case node of
Elm.Syntax.Declaration.FunctionDeclaration fn ->
let
(Node _ fnName) =
Expand All @@ -278,6 +281,7 @@ gather context exposed node found =

Elm.Syntax.Declaration.AliasDeclaration alias ->
let
aliasName : String
aliasName =
Node.value alias.name
in
Expand All @@ -291,6 +295,7 @@ gather context exposed node found =

Elm.Syntax.Declaration.CustomTypeDeclaration type_ ->
let
typeName : String
typeName =
Node.value type_.name
in
Expand All @@ -309,6 +314,7 @@ gather context exposed node found =

Elm.Syntax.Declaration.PortDeclaration portSignature ->
let
portName : String
portName =
Node.value portSignature.name
in
Expand Down Expand Up @@ -341,21 +347,23 @@ portToValue context signature =
toDocValue : Context -> Elm.Syntax.Expression.Function -> Maybe Elm.Docs.Value
toDocValue context fn =
Maybe.map
(\signature ->
(\(Node _ signature) ->
{ name =
case Node.value fn.declaration of
implementation ->
Node.value implementation.name
let
implementation : Elm.Syntax.Expression.FunctionImplementation
implementation =
Node.value fn.declaration
in
Node.value implementation.name
, comment =
case fn.documentation of
Nothing ->
""

Just doc ->
Node.value doc
Just (Node _ doc) ->
doc
, tipe =
Node.value signature
|> .typeAnnotation
signature.typeAnnotation
|> toDocType context
}
)
Expand All @@ -370,17 +378,15 @@ toDocUnion context type_ =
Nothing ->
""

Just doc ->
Node.value doc
Just (Node _ doc) ->
doc
, args = List.map Node.value type_.generics
, tags =
List.map
(\const ->
case Node.value const of
node ->
( Node.value node.name
, List.map (toDocType context) node.arguments
)
(\(Node _ const) ->
( Node.value const.name
, List.map (toDocType context) const.arguments
)
)
type_.constructors
}
Expand All @@ -394,8 +400,8 @@ toDocUnionOpaque type_ =
Nothing ->
""

Just doc ->
Node.value doc
Just (Node _ doc) ->
doc
, args = List.map Node.value type_.generics
, tags =
[]
Expand All @@ -410,8 +416,8 @@ toDocAlias context typeAlias =
Nothing ->
""

Just str ->
Node.value str
Just (Node _ doc) ->
doc
, args = List.map Node.value typeAlias.generics
, tipe =
typeAlias.typeAnnotation
Expand All @@ -425,11 +431,11 @@ toDocType context (Node _ annotation) =
Elm.Syntax.TypeAnnotation.GenericType var ->
Elm.Type.Var var

Elm.Syntax.TypeAnnotation.Typed modName inner ->
Elm.Syntax.TypeAnnotation.Typed (Node _ modName) inner ->
let
typeName : String
typeName =
case Node.value modName of
case modName of
-- This is the list found at https://package.elm-lang.org/packages/elm/core/latest/
( [], "List" ) ->
"List.List"
Expand Down Expand Up @@ -490,30 +496,26 @@ toDocType context (Node _ annotation) =
Elm.Syntax.TypeAnnotation.Record fields ->
Elm.Type.Record
(List.map
(\f ->
case Node.value f of
( name, fieldAnnotation ) ->
( Node.value name
, toDocType context fieldAnnotation
)
(\(Node _ ( Node _ name, fieldAnnotation )) ->
( name
, toDocType context fieldAnnotation
)
)
fields
)
Nothing

Elm.Syntax.TypeAnnotation.GenericRecord recordName fields ->
Elm.Syntax.TypeAnnotation.GenericRecord (Node _ recordName) (Node _ fields) ->
Elm.Type.Record
(List.map
(\f ->
case Node.value f of
( name, fieldAnnotation ) ->
( Node.value name
, toDocType context fieldAnnotation
)
(\(Node _ ( Node _ name, fieldAnnotation )) ->
( name
, toDocType context fieldAnnotation
)
)
(Node.value fields)
fields
)
(Just (Node.value recordName))
(Just recordName)

Elm.Syntax.TypeAnnotation.FunctionTypeAnnotation one two ->
Elm.Type.Lambda
Expand Down
Loading
Loading