Fix type problems

This commit is contained in:
Jeroen Engels 2023-02-01 23:01:21 +01:00
parent f4ef7c2a3a
commit e9628b2cdb
5 changed files with 27 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -93,7 +93,7 @@ new =
{-| Represents a parsed file. {-| Represents a parsed file.
-} -}
type alias ProjectModule = type alias ProjectModule =
ProjectModule.ProjectModule ProjectModule.ProjectModuleRecord
{-| Add an Elm file to the project. If a file with the same path already exists, {-| Add an Elm file to the project. If a file with the same path already exists,
@ -158,7 +158,7 @@ addParsedModule { path, source, ast } project =
|> forceModuleGraphRecomputation |> forceModuleGraphRecomputation
addModuleToProject : ProjectModule -> Project -> Project addModuleToProject : ProjectModule.ProjectModule -> Project -> Project
addModuleToProject module_ (Internal.Project project) = addModuleToProject module_ (Internal.Project project) =
Internal.Project { project | modules = Dict.insert (ProjectModule.path module_) module_ project.modules } Internal.Project { project | modules = Dict.insert (ProjectModule.path module_) module_ project.modules }
@ -199,6 +199,7 @@ removeFileFromFilesThatFailedToParse path (Internal.Project project) =
modules : Project -> List ProjectModule modules : Project -> List ProjectModule
modules (Internal.Project project) = modules (Internal.Project project) =
Dict.values project.modules Dict.values project.modules
|> List.map ProjectModule.toRecord
{-| Get the list of file paths that failed to parse, because they were syntactically invalid Elm code. {-| Get the list of file paths that failed to parse, because they were syntactically invalid Elm code.

View File

@ -2,6 +2,7 @@ module Review.Project.ProjectModule exposing
( ProjectModule, create ( ProjectModule, create
, path, source, ast, contentHash, isInSourceDirectories , path, source, ast, contentHash, isInSourceDirectories
, setIsInSourceDirectories , setIsInSourceDirectories
, ProjectModuleRecord, toRecord
) )
{-| Represents a parsed file. {-| Represents a parsed file.
@ -11,6 +12,8 @@ module Review.Project.ProjectModule exposing
@docs path, source, ast, contentHash, isInSourceDirectories @docs path, source, ast, contentHash, isInSourceDirectories
@docs setIsInSourceDirectories @docs setIsInSourceDirectories
@docs ProjectModuleRecord, toRecord
-} -}
import Elm.Syntax.File import Elm.Syntax.File
@ -86,3 +89,17 @@ isInSourceDirectories (ProjectModule module_) =
setIsInSourceDirectories : Bool -> ProjectModule -> ProjectModule setIsInSourceDirectories : Bool -> ProjectModule -> ProjectModule
setIsInSourceDirectories isInSourceDirectories_ (ProjectModule module_) = setIsInSourceDirectories isInSourceDirectories_ (ProjectModule module_) =
ProjectModule { module_ | isInSourceDirectories = isInSourceDirectories_ } ProjectModule { module_ | isInSourceDirectories = isInSourceDirectories_ }
type alias ProjectModuleRecord =
{ path : String
, source : String
, ast : Elm.Syntax.File.File
, contentHash : ContentHash
, isInSourceDirectories : Bool
}
toRecord : ProjectModule -> ProjectModuleRecord
toRecord (ProjectModule module_) =
module_

View File

@ -323,11 +323,10 @@ import Review.ModuleNameLookupTable.Compute
import Review.ModuleNameLookupTable.Internal as ModuleNameLookupTableInternal import Review.ModuleNameLookupTable.Internal as ModuleNameLookupTableInternal
import Review.Options as ReviewOptions exposing (ReviewOptions) import Review.Options as ReviewOptions exposing (ReviewOptions)
import Review.Options.Internal as InternalOptions exposing (ReviewOptionsData, ReviewOptionsInternal(..)) import Review.Options.Internal as InternalOptions exposing (ReviewOptionsData, ReviewOptionsInternal(..))
import Review.Project exposing (ProjectModule)
import Review.Project.Dependency import Review.Project.Dependency
import Review.Project.Internal exposing (Project) import Review.Project.Internal exposing (Project)
import Review.Project.InvalidProjectError as InvalidProjectError import Review.Project.InvalidProjectError as InvalidProjectError
import Review.Project.ProjectModule as ProjectModule import Review.Project.ProjectModule as ProjectModule exposing (ProjectModule)
import Review.Project.Valid as ValidProject exposing (ValidProject) import Review.Project.Valid as ValidProject exposing (ValidProject)
import Review.RequestedData as RequestedData exposing (RequestedData(..)) import Review.RequestedData as RequestedData exposing (RequestedData(..))
import Vendor.Graph as Graph exposing (Graph) import Vendor.Graph as Graph exposing (Graph)

View File

@ -137,7 +137,6 @@ import Review.FileParser as FileParser
import Review.Fix as Fix import Review.Fix as Fix
import Review.Options as ReviewOptions import Review.Options as ReviewOptions
import Review.Project as Project exposing (Project, ProjectModule) import Review.Project as Project exposing (Project, ProjectModule)
import Review.Project.ProjectModule as ProjectModule
import Review.Rule as Rule exposing (ReviewError, Rule) import Review.Rule as Rule exposing (ReviewError, Rule)
import Review.Test.Dependencies exposing (projectWithElmCore) import Review.Test.Dependencies exposing (projectWithElmCore)
import Review.Test.FailureMessage as FailureMessage import Review.Test.FailureMessage as FailureMessage
@ -495,14 +494,14 @@ hasOneElement list =
moduleToRunResult : List ReviewError -> ProjectModule -> SuccessfulRunResult moduleToRunResult : List ReviewError -> ProjectModule -> SuccessfulRunResult
moduleToRunResult errors projectModule = moduleToRunResult errors projectModule =
{ moduleName = { moduleName =
(ProjectModule.ast projectModule).moduleDefinition projectModule.ast.moduleDefinition
|> Node.value |> Node.value
|> Module.moduleName |> Module.moduleName
|> String.join "." |> String.join "."
, inspector = codeInspectorForSource True (ProjectModule.source projectModule) , inspector = codeInspectorForSource True projectModule.source
, errors = , errors =
errors errors
|> List.filter (\error_ -> Rule.errorFilePath error_ == ProjectModule.path projectModule) |> List.filter (\error_ -> Rule.errorFilePath error_ == projectModule.path)
|> List.sortWith compareErrorPositions |> List.sortWith compareErrorPositions
} }
@ -583,7 +582,7 @@ findDuplicateModuleNames previousModuleNames modules =
let let
moduleName : List String moduleName : List String
moduleName = moduleName =
(ProjectModule.ast module_).moduleDefinition module_.ast.moduleDefinition
|> Node.value |> Node.value
|> Module.moduleName |> Module.moduleName
in in
@ -888,7 +887,7 @@ doCheckResultsAreTheSameWhenIgnoringFiles allErrors rule project =
filePaths : List String filePaths : List String
filePaths = filePaths =
Project.modules project Project.modules project
|> List.map ProjectModule.path |> List.map .path
|> maybeCons .path (Project.elmJson project) |> maybeCons .path (Project.elmJson project)
|> maybeCons .path (Project.readme project) |> maybeCons .path (Project.readme project)