Represents the contents of the project to be analyzed. This information will then be fed to the review rules.
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 project information (like the elm.json
, dependencies, ...).
Internal.Project
Holds all the information related to the project such as the contents of
the elm.json
file, the project modules and the project dependencies.
new : Project
Create a new empty Project.
For tests, you can also start of with a project that contains the elm/core
dependency using
Review.Test.Dependencies.projectWithElmCore
. Some more prepared
dependencies can be found in that same module.
ProjectModule
Represents a parsed file.
addModule : { path : String, source : String } -> Project -> Project
Add an Elm file to the project. If a file with the same path already exists, then it will replace it.
If the file is syntactically valid Elm code, it will then be analyzed by the
review rules. Otherwise, the file will be added to the list of files that failed
to parse, which you can get using modulesThatFailedToParse
,
and for which a parsing error will be reported when running the review function
.
addParsedModule : { path : String, source : String, ast : Elm.Syntax.File.File } -> Project -> Project
Add an already parsed module to the project. This module will then be analyzed by the rules.
removeModule : String -> Project -> Project
Remove a module from the project by its path.
modules : Project -> List ProjectModule
Get the list of modules in the project.
modulesThatFailedToParse : Project -> List { path : String, source : String }
Get the list of file paths that failed to parse, because they were syntactically invalid Elm code.
precomputeModuleGraph : Project -> Project
Precomputes the module graph.
@deprecated This is not useful anymore.
elm.json
addElmJson : { path : String, raw : String, project : Elm.Project.Project } -> Project -> Project
Add the content of the elm.json
file to the project, making it
available for rules to access using
Review.Rule.withElmJsonModuleVisitor
and
Review.Rule.withElmJsonProjectVisitor
.
The raw
value should be the raw JSON as a string, and project
corresponds to
elm/project-metadata-utils
's Elm.Project.Project
type.
elmJson : Project -> Maybe { path : String, raw : String, project : Elm.Project.Project }
Get the contents of the elm.json
file, if available.
This will give you a Elm.Project.Project
type from the
elm/project-metadata-utils
package, so you will need to install and use it to gain access to the
information from the elm.json
file.
README.md
addReadme : { path : String, content : String } -> Project -> Project
Add the content of the README.md
file to the project, making it
available for rules to access using
Review.Rule.withReadmeModuleVisitor
and
Review.Rule.withReadmeProjectVisitor
.
readme : Project -> Maybe { path : String, content : String }
Get the contents of the README.md
file, if available.
addDependency : Dependency -> Project -> Project
Add a dependency to the project. These will be available for rules to make better assumptions on what is happening in the code.
Knowing the dependencies of the project will also help better parse the source files, since the dependencies will allow us to know the precedence and associativity of operators, which has an impact on the resulting AST when parsing a file.
For tests, elm-review
comes with a few dependencies that you can find in
Review.Test.Dependencies
.
removeDependency : String -> Project -> Project
Remove a dependency from a project by name.
removeDependencies : Project -> Project
Remove all dependencies of a project. Use this to flush the dependencies of a project when they are changed, before re-adding them.
directDependencies : Project -> Dict String Dependency
Get the direct dependencies of the project.
dependencies : Project -> Dict String Dependency
Get the dependencies of the project.