diff --git a/LintConfig.elm b/LintConfig.elm index eb9c0097..8b3aaf79 100644 --- a/LintConfig.elm +++ b/LintConfig.elm @@ -1,38 +1,38 @@ module LintConfig exposing (config) -import Lint.Types exposing (Rule, Severity(..)) -import Lint.Rules.DefaultPatternPosition -import Lint.Rules.NoConstantCondition -import Lint.Rules.NoDebug -import Lint.Rules.NoDuplicateImports -import Lint.Rules.NoExposingEverything -import Lint.Rules.NoImportingEverything -import Lint.Rules.NoNestedLet -import Lint.Rules.NoUnannotatedFunction -import Lint.Rules.NoUnusedVariables -import Lint.Rules.NoUselessIf -import Lint.Rules.NoUselessPatternMatching -import Lint.Rules.NoWarningComments -import Lint.Rules.SimplifyPiping -import Lint.Rules.SimplifyPropertyAccess -import Lint.Rules.ElmTest.NoDuplicateTestBodies +import Lint.Rule exposing (Rule, Severity(..)) +import Lint.Rule.DefaultPatternPosition +import Lint.Rule.NoConstantCondition +import Lint.Rule.NoDebug +import Lint.Rule.NoDuplicateImports +import Lint.Rule.NoExposingEverything +import Lint.Rule.NoImportingEverything +import Lint.Rule.NoNestedLet +import Lint.Rule.NoUnannotatedFunction +import Lint.Rule.NoUnusedVariables +import Lint.Rule.NoUselessIf +import Lint.Rule.NoUselessPatternMatching +import Lint.Rule.NoWarningComments +import Lint.Rule.SimplifyPiping +import Lint.Rule.SimplifyPropertyAccess +import Lint.Rule.ElmTest.NoDuplicateTestBodies config : List ( Severity, Rule ) config = - [ ( Critical, Lint.Rules.DefaultPatternPosition.rule { position = Lint.Rules.DefaultPatternPosition.Last } ) - , ( Critical, Lint.Rules.NoConstantCondition.rule ) - , ( Critical, Lint.Rules.NoDebug.rule ) - , ( Critical, Lint.Rules.NoDuplicateImports.rule ) - , ( Critical, Lint.Rules.NoExposingEverything.rule ) - , ( Critical, Lint.Rules.NoImportingEverything.rule { exceptions = [ "Html", "Ast.Expression", "Ast.Statement" ] } ) - , ( Critical, Lint.Rules.NoNestedLet.rule ) - , ( Critical, Lint.Rules.NoUnannotatedFunction.rule ) - , ( Critical, Lint.Rules.NoUnusedVariables.rule ) - , ( Critical, Lint.Rules.NoUselessIf.rule ) - , ( Critical, Lint.Rules.NoUselessPatternMatching.rule ) - , ( Warning, Lint.Rules.NoWarningComments.rule ) - , ( Critical, Lint.Rules.SimplifyPiping.rule ) - , ( Critical, Lint.Rules.SimplifyPropertyAccess.rule ) - , ( Critical, Lint.Rules.ElmTest.NoDuplicateTestBodies.rule ) + [ ( Critical, Lint.Rule.DefaultPatternPosition.rule { position = Lint.Rule.DefaultPatternPosition.Last } ) + , ( Critical, Lint.Rule.NoConstantCondition.rule ) + , ( Critical, Lint.Rule.NoDebug.rule ) + , ( Critical, Lint.Rule.NoDuplicateImports.rule ) + , ( Critical, Lint.Rule.NoExposingEverything.rule ) + , ( Critical, Lint.Rule.NoImportingEverything.rule { exceptions = [ "Html", "Ast.Expression", "Ast.Statement" ] } ) + , ( Critical, Lint.Rule.NoNestedLet.rule ) + , ( Critical, Lint.Rule.NoUnannotatedFunction.rule ) + , ( Critical, Lint.Rule.NoUnusedVariables.rule ) + , ( Critical, Lint.Rule.NoUselessIf.rule ) + , ( Critical, Lint.Rule.NoUselessPatternMatching.rule ) + , ( Warning, Lint.Rule.NoWarningComments.rule ) + , ( Critical, Lint.Rule.SimplifyPiping.rule ) + , ( Critical, Lint.Rule.SimplifyPropertyAccess.rule ) + , ( Critical, Lint.Rule.ElmTest.NoDuplicateTestBodies.rule ) ] diff --git a/elm.json b/elm.json index 67e1b243..34017b8d 100644 --- a/elm.json +++ b/elm.json @@ -6,8 +6,8 @@ "version": "3.0.0", "exposed-modules": [ "Lint", - "Lint.Types", - "Lint.Rules.NoDebug" + "Lint.Rule", + "Lint.Rule.NoDebug" ], "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { diff --git a/example/Main.elm b/example/Main.elm index 6bd7122e..addcd975 100644 --- a/example/Main.elm +++ b/example/Main.elm @@ -8,7 +8,7 @@ import Html.Attributes exposing (class, id, style) import Html.Events exposing (onInput) import Lint exposing (Rule, Severity(..), lintSource) import Lint.Error exposing (Error) -import Lint.Rules.NoDebug +import Lint.Rule.NoDebug import Result exposing (Result) @@ -18,22 +18,22 @@ type Msg config : List ( Severity, Rule ) config = - [ ( Critical, Lint.Rules.NoDebug.rule ) + [ ( Critical, Lint.Rule.NoDebug.rule ) - -- , ( Critical, Lint.Rules.DefaultPatternPosition.rule { position = Lint.Rules.DefaultPatternPosition.Last } ) - -- , ( Critical, Lint.Rules.NoConstantCondition.rule ) - -- , ( Critical, Lint.Rules.NoDuplicateImports.rule ) - -- , ( Critical, Lint.Rules.NoExposingEverything.rule ) - -- , ( Critical, Lint.Rules.NoImportingEverything.rule { exceptions = [ "Html" ] } ) - -- , ( Critical, Lint.Rules.NoNestedLet.rule ) - -- , ( Critical, Lint.Rules.NoUnannotatedFunction.rule ) - -- , ( Critical, Lint.Rules.NoUnusedVariables.rule ) - -- , ( Critical, Lint.Rules.NoUselessIf.rule ) - -- , ( Critical, Lint.Rules.NoUselessPatternMatching.rule ) - -- , ( Warning, Lint.Rules.NoWarningComments.rule ) - -- , ( Critical, Lint.Rules.SimplifyPiping.rule ) - -- , ( Critical, Lint.Rules.SimplifyPropertyAccess.rule ) - -- , ( Critical, Lint.Rules.ElmTest.NoDuplicateTestBodies.rule ) + -- , ( Critical, Lint.Rule.DefaultPatternPosition.rule { position = Lint.Rule.DefaultPatternPosition.Last } ) + -- , ( Critical, Lint.Rule.NoConstantCondition.rule ) + -- , ( Critical, Lint.Rule.NoDuplicateImports.rule ) + -- , ( Critical, Lint.Rule.NoExposingEverything.rule ) + -- , ( Critical, Lint.Rule.NoImportingEverything.rule { exceptions = [ "Html" ] } ) + -- , ( Critical, Lint.Rule.NoNestedLet.rule ) + -- , ( Critical, Lint.Rule.NoUnannotatedFunction.rule ) + -- , ( Critical, Lint.Rule.NoUnusedVariables.rule ) + -- , ( Critical, Lint.Rule.NoUselessIf.rule ) + -- , ( Critical, Lint.Rule.NoUselessPatternMatching.rule ) + -- , ( Warning, Lint.Rule.NoWarningComments.rule ) + -- , ( Critical, Lint.Rule.SimplifyPiping.rule ) + -- , ( Critical, Lint.Rule.SimplifyPropertyAccess.rule ) + -- , ( Critical, Lint.Rule.ElmTest.NoDuplicateTestBodies.rule ) ] diff --git a/src/Lint.elm b/src/Lint.elm index 9d4d83e9..e9c90e24 100644 --- a/src/Lint.elm +++ b/src/Lint.elm @@ -57,8 +57,8 @@ import Elm.Syntax.Expression exposing (Expression) import Elm.Syntax.File exposing (File) import Elm.Syntax.Node exposing (Node) import Lint.Error exposing (Error) -import Lint.Types exposing (Direction, LintRuleImplementation, Visitor, initialContext) -import Lint.Visitor exposing (expressionToVisitors, transformDeclarationsIntoVisitors) +import Lint.NodeToVisitor exposing (declarationsIntoVisitors, expressionToVisitors) +import Lint.Rule exposing (Direction, Implementation, Visitor, initialContext) {-| Shortcut to a lint rule @@ -122,7 +122,7 @@ parseSource source = rule input = lint input implementation - implementation : LintRuleImplementation Context + implementation : Implementation Context implementation = { typeFn = doNothing , visitExpression = visitExpression @@ -131,10 +131,10 @@ parseSource source = } -} -lint : File -> LintRuleImplementation context -> List Error +lint : File -> Implementation context -> List Error lint file rule = file.declarations - |> transformDeclarationsIntoVisitors + |> declarationsIntoVisitors |> lintWithVisitors rule @@ -150,7 +150,7 @@ part of the implementation of complex rules much easier. It gives back a list of _ -> ( [], ctx ) - subimplementation : LintRuleImplementation Subcontext + subimplementation : Implementation Subcontext subimplementation = { statementFn = doNothing , typeFn = doNothing @@ -160,19 +160,19 @@ part of the implementation of complex rules much easier. It gives back a list of } -} -visitExpression : LintRuleImplementation context -> Node Expression -> ( List Error, context ) +visitExpression : Implementation context -> Node Expression -> ( List Error, context ) visitExpression rule expression = expressionToVisitors expression |> List.foldl (visitAndAccumulate rule) ( [], initialContext rule ) -visitAndAccumulate : LintRuleImplementation context -> Visitor context -> ( List Error, context ) -> ( List Error, context ) +visitAndAccumulate : Implementation context -> Visitor context -> ( List Error, context ) -> ( List Error, context ) visitAndAccumulate rule visitor ( errors, ctx ) = visitor rule ctx |> Tuple.mapFirst (\errors_ -> errors ++ errors_) -lintWithVisitors : LintRuleImplementation context -> List (Visitor context) -> List Error +lintWithVisitors : Implementation context -> List (Visitor context) -> List Error lintWithVisitors rule visitors = visitors |> List.foldl (visitAndAccumulate rule) ( [], initialContext rule ) diff --git a/src/Lint/Visitor.elm b/src/Lint/NodeToVisitor.elm similarity index 93% rename from src/Lint/Visitor.elm rename to src/Lint/NodeToVisitor.elm index b9a26638..5efd5f48 100644 --- a/src/Lint/Visitor.elm +++ b/src/Lint/NodeToVisitor.elm @@ -1,10 +1,10 @@ -module Lint.Visitor exposing (expressionToVisitors, transformDeclarationsIntoVisitors) +module Lint.NodeToVisitor exposing (declarationsIntoVisitors, expressionToVisitors) import Elm.Syntax.Declaration exposing (Declaration(..)) import Elm.Syntax.Expression exposing (Expression(..), Function, FunctionImplementation, LetDeclaration(..)) import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node, value) -import Lint.Types exposing (Direction(..), Visitor, evaluateExpression, finalEvaluation) +import Lint.Rule exposing (Direction(..), Visitor, evaluateExpression, finalEvaluation) createExitAndEnterWithChildren : (Direction -> nodeType -> Visitor context) -> nodeType -> List (Visitor context) -> List (Visitor context) @@ -134,8 +134,8 @@ declarationToVisitors declaration = childrenVisitors -transformDeclarationsIntoVisitors : List (Node Declaration) -> List (Visitor context) -transformDeclarationsIntoVisitors declarations = +declarationsIntoVisitors : List (Node Declaration) -> List (Visitor context) +declarationsIntoVisitors declarations = declarations |> List.concatMap (value >> declarationToVisitors) |> (\allVisitors -> List.append allVisitors [ moduleVisitor ]) diff --git a/src/Lint/Types.elm b/src/Lint/Rule.elm similarity index 75% rename from src/Lint/Types.elm rename to src/Lint/Rule.elm index 75c1a44a..984f00f2 100644 --- a/src/Lint/Types.elm +++ b/src/Lint/Rule.elm @@ -1,6 +1,6 @@ -module Lint.Types exposing +module Lint.Rule exposing ( Direction(..) - , LintRuleImplementation, createRule + , Implementation, createRule , Visitor, LintResult , evaluateExpression, finalEvaluation, initialContext ) @@ -15,7 +15,7 @@ module Lint.Types exposing # Writing rules -@docs LintRuleImplementation, createRule +@docs Implementation, createRule # Internal types @@ -56,7 +56,7 @@ type Direction | Exit -{-| A LintRuleImplementation is the implementation of a rule. It is a record that contains: +{-| A Implementation is the implementation of a rule. It is a record that contains: - initialContext: An initial context @@ -69,7 +69,7 @@ type Direction rule input = lint input implementation - implementation : LintRuleImplementation Context + implementation : Implementation Context implementation = { expression = expression , visitEnd = (\\ctx -> ( [], ctx )) @@ -77,8 +77,8 @@ type Direction } -} -type LintRuleImplementation context - = LintRuleImplementation +type Implementation context + = Implementation { initContext : context , visitors : Visitors context } @@ -90,9 +90,9 @@ type alias Visitors context = } -createRule : context -> (Visitors context -> Visitors context) -> LintRuleImplementation context +createRule : context -> (Visitors context -> Visitors context) -> Implementation context createRule initContext createVisitors = - LintRuleImplementation + Implementation { initContext = initContext , visitors = createVisitors @@ -102,18 +102,18 @@ createRule initContext createVisitors = } -initialContext : LintRuleImplementation context -> context -initialContext (LintRuleImplementation { initContext }) = +initialContext : Implementation context -> context +initialContext (Implementation { initContext }) = initContext -evaluateExpression : LintRuleImplementation context -> context -> Direction -> Node Expression -> ( List Error, context ) -evaluateExpression (LintRuleImplementation { visitors }) = +evaluateExpression : Implementation context -> context -> Direction -> Node Expression -> ( List Error, context ) +evaluateExpression (Implementation { visitors }) = visitors.visitExpression -finalEvaluation : LintRuleImplementation context -> context -> ( List Error, context ) -finalEvaluation (LintRuleImplementation { visitors }) = +finalEvaluation : Implementation context -> context -> ( List Error, context ) +finalEvaluation (Implementation { visitors }) = visitors.visitEnd @@ -130,4 +130,4 @@ Note: this is internal API, and will be removed in a future version. -} type alias Visitor context = - LintRuleImplementation context -> context -> ( List Error, context ) + Implementation context -> context -> ( List Error, context ) diff --git a/src/Lint/Rules/NoDebug.elm b/src/Lint/Rule/NoDebug.elm similarity index 87% rename from src/Lint/Rules/NoDebug.elm rename to src/Lint/Rule/NoDebug.elm index 53ab8579..5bbdb6f7 100644 --- a/src/Lint/Rules/NoDebug.elm +++ b/src/Lint/Rule/NoDebug.elm @@ -1,4 +1,4 @@ -module Lint.Rules.NoDebug exposing (rule) +module Lint.Rule.NoDebug exposing (rule) {-| @@ -34,7 +34,7 @@ import Elm.Syntax.Expression exposing (Expression(..)) import Elm.Syntax.Node exposing (Node, range, value) import Lint exposing (Rule, lint) import Lint.Error exposing (Error) -import Lint.Types exposing (Direction(..), LintRuleImplementation, createRule) +import Lint.Rule exposing (Direction(..), Implementation, createRule) type alias Context = @@ -53,7 +53,7 @@ rule input = lint input implementation -implementation : LintRuleImplementation Context +implementation : Implementation Context implementation = createRule Context diff --git a/tests/NoDebugTest.elm b/tests/NoDebugTest.elm index bca9f570..f06f3c6b 100644 --- a/tests/NoDebugTest.elm +++ b/tests/NoDebugTest.elm @@ -3,8 +3,8 @@ module NoDebugTest exposing (all) import Elm.Syntax.Range exposing (Location, Range) import Lint exposing (Rule) import Lint.Error exposing (Error) -import Lint.Rules.NoDebug exposing (rule) -import Lint.Types exposing (LintResult) +import Lint.Rule exposing (LintResult) +import Lint.Rule.NoDebug exposing (rule) import Test exposing (Test, describe, only, test) import TestUtil exposing (expectErrors, ruleTester) diff --git a/tests/TestUtil.elm b/tests/TestUtil.elm index 80498fd7..a4c4e917 100644 --- a/tests/TestUtil.elm +++ b/tests/TestUtil.elm @@ -3,7 +3,7 @@ module TestUtil exposing (expectErrors, ruleTester) import Expect import Lint exposing (Rule, parseSource) import Lint.Error exposing (Error) -import Lint.Types exposing (LintResult) +import Lint.Rule exposing (LintResult) ruleTester : Rule -> String -> LintResult