From 9ebb4ac7d412294dfc77d38b9a0211a01ea56488 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 8 Jan 2017 11:44:31 +0100 Subject: [PATCH] Add NoExposingEverything rule --- Lint.elm | 7 +++++-- example/Main.elm | 8 +++++++- rules/NoExposingEverything.elm | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 rules/NoExposingEverything.elm diff --git a/Lint.elm b/Lint.elm index 4d35c44b..98c09550 100644 --- a/Lint.elm +++ b/Lint.elm @@ -75,10 +75,10 @@ typeToVisitors node = statementToVisitors : Statement -> List (Visitor context) statementToVisitors node = let - visitAndTransformChildren expresssions types = + visitAndTransformChildren expressions types = List.concat [ [ statementVisitor node ] - , List.concatMap expressionToVisitors expresssions + , List.concatMap expressionToVisitors expressions , List.concatMap typeToVisitors types ] in @@ -89,6 +89,9 @@ statementToVisitors node = FunctionDeclaration name params body -> visitAndTransformChildren [ body ] [] + ModuleDeclaration name exportSet -> + visitAndTransformChildren [] [] + _ -> [] diff --git a/example/Main.elm b/example/Main.elm index 574c8c2b..98e4aa5a 100644 --- a/example/Main.elm +++ b/example/Main.elm @@ -9,8 +9,13 @@ import Html.Attributes exposing (id) import Html.Events exposing (..) import Json.Decode as JD import Lint -import NoDebug + + +-- Rules + import FindNoAnnotatedFunction +import NoDebug +import NoExposingEverything type Msg @@ -107,6 +112,7 @@ lint ast = List.concat [ lint FindNoAnnotatedFunction.rule , lint NoDebug.rule + , lint NoExposingEverything.rule ] in div [] (List.map (\x -> p [] [ text x ]) errors) diff --git a/rules/NoExposingEverything.elm b/rules/NoExposingEverything.elm new file mode 100644 index 00000000..e2e858bf --- /dev/null +++ b/rules/NoExposingEverything.elm @@ -0,0 +1,32 @@ +module NoExposingEverything exposing (rule) + +import Lint exposing (LintRule, Error, doNothing) +import Ast.Statement exposing (..) + + +type alias Context = + {} + + +rule : LintRule Context +rule = + { statementFn = statementFn + , typeFn = doNothing + , expressionFn = doNothing + , context = Context + } + + +statementFn : Context -> Statement -> ( List Error, Context ) +statementFn ctx node = + case node of + ModuleDeclaration names AllExport -> + case names of + [ name ] -> + ( [ "Do not expose everything from module " ++ name ++ " using (..)" ], ctx ) + + _ -> + ( [], ctx ) + + _ -> + ( [], ctx )