diff --git a/src/NoInvalidLicense.elm b/src/NoInvalidLicense.elm index 6e187a60..fb51bd5c 100644 --- a/src/NoInvalidLicense.elm +++ b/src/NoInvalidLicense.elm @@ -133,12 +133,12 @@ initProjectContext = } -fromProjectToModule : Rule.FileKey -> Node ModuleName -> ProjectContext -> ModuleContext +fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> ProjectContext -> ModuleContext fromProjectToModule _ _ projectContext = projectContext -fromModuleToProject : Rule.FileKey -> Node ModuleName -> ModuleContext -> ProjectContext +fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> ModuleContext -> ProjectContext fromModuleToProject _ _ moduleContext = moduleContext diff --git a/src/NoUnusedDependencies.elm b/src/NoUnusedDependencies.elm index 7eb99545..86cfc5cb 100644 --- a/src/NoUnusedDependencies.elm +++ b/src/NoUnusedDependencies.elm @@ -106,13 +106,13 @@ initProjectContext = } -fromProjectToModule : Rule.FileKey -> Node ModuleName -> ProjectContext -> ModuleContext +fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> ProjectContext -> ModuleContext fromProjectToModule _ _ projectContext = projectContext.importedModuleNames -fromModuleToProject : Rule.FileKey -> Node ModuleName -> ModuleContext -> ProjectContext -fromModuleToProject fileKey moduleName importedModuleNames = +fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> ModuleContext -> ProjectContext +fromModuleToProject moduleKey moduleName importedModuleNames = { moduleNameToDependency = Dict.empty , directProjectDependencies = Set.empty , importedModuleNames = importedModuleNames diff --git a/src/NoUnusedExports.elm b/src/NoUnusedExports.elm index 16a7a0e6..70ed4ab3 100644 --- a/src/NoUnusedExports.elm +++ b/src/NoUnusedExports.elm @@ -91,7 +91,7 @@ type alias ProjectContext = , projectType : ProjectType , modules : Dict ModuleName - { fileKey : Rule.FileKey + { moduleKey : Rule.ModuleKey , exposed : Dict String { range : Range, exposedElement : ExposedElement } } , used : Set ( ModuleName, String ) @@ -127,8 +127,8 @@ initProjectContext = } -fromProjectToModule : Rule.FileKey -> Node ModuleName -> ProjectContext -> ModuleContext -fromProjectToModule fileKey moduleName projectContext = +fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> ProjectContext -> ModuleContext +fromProjectToModule moduleKey moduleName projectContext = { scope = Scope.fromProjectToModule projectContext.scope , exposesEverything = False , exposed = Dict.empty @@ -137,14 +137,14 @@ fromProjectToModule fileKey moduleName projectContext = } -fromModuleToProject : Rule.FileKey -> Node ModuleName -> ModuleContext -> ProjectContext -fromModuleToProject fileKey moduleName moduleContext = +fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> ModuleContext -> ProjectContext +fromModuleToProject moduleKey moduleName moduleContext = { scope = Scope.fromModuleToProject moduleName moduleContext.scope , projectType = IsApplication , modules = Dict.singleton (Node.value moduleName) - { fileKey = fileKey + { moduleKey = moduleKey , exposed = moduleContext.exposed } , used = @@ -213,7 +213,7 @@ finalEvaluationForProject projectContext = |> removeExposedPackages projectContext |> Dict.toList |> List.concatMap - (\( moduleName, { fileKey, exposed } ) -> + (\( moduleName, { moduleKey, exposed } ) -> exposed |> removeApplicationExceptions projectContext moduleName |> removeReviewConfig moduleName @@ -234,7 +234,7 @@ finalEvaluationForProject projectContext = ExposedType -> "Exposed type" in - Rule.errorForFile fileKey + Rule.errorForFile moduleKey { message = what ++ " `" ++ name ++ "` is never used outside this module." , details = [ "This exposed element is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project." ] } diff --git a/src/NoUnusedModules.elm b/src/NoUnusedModules.elm index 7f39c8e1..07e73c07 100644 --- a/src/NoUnusedModules.elm +++ b/src/NoUnusedModules.elm @@ -72,7 +72,7 @@ moduleVisitorSchema schema = type alias ProjectContext = { modules : Dict ModuleName - { fileKey : Rule.FileKey + { moduleKey : Rule.ModuleKey , moduleNameLocation : Range } , usedModules : Set ModuleName @@ -95,7 +95,7 @@ initProjectContext = } -fromProjectToModule : Rule.FileKey -> Node ModuleName -> ProjectContext -> ModuleContext +fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> ProjectContext -> ModuleContext fromProjectToModule _ _ projectContext = { importedModules = Set.empty , containsMainFunction = False @@ -103,12 +103,12 @@ fromProjectToModule _ _ projectContext = } -fromModuleToProject : Rule.FileKey -> Node ModuleName -> ModuleContext -> ProjectContext -fromModuleToProject fileKey moduleName moduleContext = +fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> ModuleContext -> ProjectContext +fromModuleToProject moduleKey moduleName moduleContext = { modules = Dict.singleton (Node.value moduleName) - { fileKey = fileKey, moduleNameLocation = Node.range moduleName } + { moduleKey = moduleKey, moduleNameLocation = Node.range moduleName } , usedModules = if Set.member [ "Test" ] moduleContext.importedModules || moduleContext.containsMainFunction then Set.insert (Node.value moduleName) moduleContext.importedModules @@ -165,9 +165,9 @@ finalEvaluationForProject { modules, usedModules } = |> List.map error -error : ( ModuleName, { fileKey : Rule.FileKey, moduleNameLocation : Range } ) -> Error -error ( moduleName, { fileKey, moduleNameLocation } ) = - Rule.errorForFile fileKey +error : ( ModuleName, { moduleKey : Rule.ModuleKey, moduleNameLocation : Range } ) -> Error +error ( moduleName, { moduleKey, moduleNameLocation } ) = + Rule.errorForFile moduleKey { message = "Module `" ++ String.join "." moduleName ++ "` is never used." , details = [ "This module is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project." ] } diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index 7fe67f90..1f8d92a9 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -6,7 +6,7 @@ module Review.Rule exposing , withModuleDefinitionVisitor, withCommentsVisitor, withImportVisitor, Direction(..), withDeclarationVisitor, withDeclarationListVisitor, withExpressionVisitor, withFinalModuleEvaluation , withModuleElmJsonVisitor, withModuleDependenciesVisitor , ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withProjectElmJsonVisitor, withProjectDependenciesVisitor, withFinalProjectEvaluation, withContextFromImportedModules - , Error, error, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath, FileKey, errorForFile, ElmJsonKey, errorForElmJson + , Error, error, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath, ModuleKey, errorForFile, ElmJsonKey, errorForElmJson , withFixes ) @@ -199,7 +199,7 @@ simpler version of project rules. ## Errors -@docs Error, error, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath, FileKey, errorForFile, ElmJsonKey, errorForElmJson +@docs Error, error, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath, ModuleKey, errorForFile, ElmJsonKey, errorForElmJson ## Automatic fixing @@ -671,8 +671,8 @@ type ProjectRuleSchema projectContext moduleContext { name : String , context : { initProjectContext : projectContext - , fromProjectToModule : FileKey -> Node ModuleName -> projectContext -> moduleContext - , fromModuleToProject : FileKey -> Node ModuleName -> moduleContext -> projectContext + , fromProjectToModule : ModuleKey -> Node ModuleName -> projectContext -> moduleContext + , fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext , foldProjectContexts : projectContext -> projectContext -> projectContext } , moduleVisitorSchema : ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext @@ -695,8 +695,8 @@ newProjectRuleSchema : -> { moduleVisitorSchema : ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext , initProjectContext : projectContext - , fromProjectToModule : FileKey -> Node ModuleName -> projectContext -> moduleContext - , fromModuleToProject : FileKey -> Node ModuleName -> moduleContext -> projectContext + , fromProjectToModule : ModuleKey -> Node ModuleName -> projectContext -> moduleContext + , fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext , foldProjectContexts : projectContext -> projectContext -> projectContext } -> ProjectRuleSchema projectContext moduleContext @@ -851,9 +851,9 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache project computeModule : ProjectRuleCache projectContext -> List ProjectModule -> ProjectModule -> { source : String, errors : List Error, context : projectContext } computeModule cache importedModules module_ = let - fileKey : FileKey - fileKey = - FileKey module_.path + moduleKey : ModuleKey + moduleKey = + ModuleKey module_.path moduleNameNode_ : Node ModuleName moduleNameNode_ = @@ -864,7 +864,7 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache project case schema.traversalType of AllModulesInParallel -> schema.context.fromProjectToModule - fileKey + moduleKey moduleNameNode_ initialContext @@ -876,7 +876,7 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache project |> Maybe.map .context ) |> List.foldl schema.context.foldProjectContexts initialContext - |> schema.context.fromProjectToModule fileKey moduleNameNode_ + |> schema.context.fromProjectToModule moduleKey moduleNameNode_ moduleVisitor : ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext moduleVisitor = @@ -894,7 +894,7 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache project , errors = List.map (setFilePathIfUnset module_) fileErrors , context = schema.context.fromModuleToProject - fileKey + moduleKey moduleNameNode_ context } @@ -1921,12 +1921,12 @@ error { message, details } range = key in order to use the [`errorForFile`](#errorForFile) function. This is to prevent creating errors for modules you have not visited, or files that do not exist. -You can get a `FileKey` from the `fromProjectToModule` and `fromModuleToProject` +You can get a `ModuleKey` from the `fromProjectToModule` and `fromModuleToProject` functions that you define when using [`newProjectRuleSchema`](#newProjectRuleSchema). -} -type FileKey - = FileKey String +type ModuleKey + = ModuleKey String {-| TODO documentation @@ -1949,8 +1949,8 @@ by the tests automatically. (Node.range node) -} -errorForFile : FileKey -> { message : String, details : List String } -> Range -> Error -errorForFile (FileKey path) { message, details } range = +errorForFile : ModuleKey -> { message : String, details : List String } -> Range -> Error +errorForFile (ModuleKey path) { message, details } range = Error { message = message , ruleName = "" @@ -1962,8 +1962,8 @@ errorForFile (FileKey path) { message, details } range = {-| A key to be able to report an error for the `elm.json` file. You need this -key in order to use the [`errorForElmJson`](#errorForElmJson) function. This is to -prevent creating errors for it if you have not visited it. +key in order to use the [`errorForElmJson`](#errorForElmJson) function. This is +to prevent creating errors for it if you have not visited it. You can get a `ElmJsonKey` using the [`withProjectElmJsonVisitor`](#withProjectElmJsonVisitor) function. diff --git a/src/Scope2.elm b/src/Scope2.elm index 51f3e526..9fbf8f15 100644 --- a/src/Scope2.elm +++ b/src/Scope2.elm @@ -241,8 +241,8 @@ addModuleVisitors setterGetter schema = -- -> -- { moduleVisitorSchema : Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasNoVisitor : () } moduleContext -> Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasAtLeastOneVisitor : () } moduleContext -- , initProjectContext : projectContext --- , fromProjectToModule : Rule.FileKey -> Node ModuleName -> projectContext -> moduleContext --- , fromModuleToProject : Rule.FileKey -> Node ModuleName -> moduleContext -> projectContext +-- , fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> projectContext -> moduleContext +-- , fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> moduleContext -> projectContext -- , foldProjectContexts : projectContext -> projectContext -> projectContext -- } -- -> Rule.ProjectRuleSchema projectContext moduleContext diff --git a/tests/Scope2Test.elm b/tests/Scope2Test.elm index 20932b8c..a49d1dcd 100644 --- a/tests/Scope2Test.elm +++ b/tests/Scope2Test.elm @@ -142,12 +142,12 @@ rule = |> Rule.withFinalModuleEvaluation finalEvaluation , initProjectContext = { scope = Scope.initProjectContext } , fromProjectToModule = - \fileKey moduleNameNode projectContext -> + \moduleKey moduleNameNode projectContext -> { scope = Scope.fromProjectToModule projectContext.scope , text = "" } , fromModuleToProject = - \fileKey moduleNameNode moduleContext -> + \moduleKey moduleNameNode moduleContext -> { scope = Scope.fromModuleToProject moduleNameNode moduleContext.scope } , foldProjectContexts = \a b -> { scope = Scope.foldProjectContexts a.scope b.scope }