diff --git a/src/Analyser/Checks/CoreArrayUsage.elm b/src/Analyser/Checks/CoreArrayUsage.elm new file mode 100644 index 00000000..83d25750 --- /dev/null +++ b/src/Analyser/Checks/CoreArrayUsage.elm @@ -0,0 +1,28 @@ +module Analyser.Checks.CoreArrayUsage exposing (checker) + +import Analyser.Messages.Types exposing (Message, MessageData(CoreArrayUsage), newMessage) +import AST.Types exposing (InnerExpression, ModuleName, Import) +import Analyser.FileContext exposing (FileContext) +import Analyser.Configuration exposing (Configuration) +import Analyser.Checks.Base exposing (Checker, keyBasedChecker) + + +checker : Checker +checker = + { check = scan + , shouldCheck = keyBasedChecker [ "CoreArrayUsage" ] + } + + +scan : FileContext -> Configuration -> List Message +scan fileContext _ = + fileContext.ast.imports + |> List.filter isArrayImport + |> List.map (.range >> CoreArrayUsage fileContext.path) + |> List.map (newMessage [ ( fileContext.sha1, fileContext.path ) ]) + |> List.take 1 + + +isArrayImport : Import -> Bool +isArrayImport { moduleName } = + moduleName == [ "Array" ] diff --git a/src/Analyser/Messages/Json.elm b/src/Analyser/Messages/Json.elm index bcc86880..2b3f3c86 100644 --- a/src/Analyser/Messages/Json.elm +++ b/src/Analyser/Messages/Json.elm @@ -131,6 +131,7 @@ decodeMessageData = , ( "DropConsOfItemAndList", decodeFileAndRange DropConsOfItemAndList ) , ( "UnnecessaryListConcat", decodeFileAndRange UnnecessaryListConcat ) , ( "NonStaticRegex", decodeFileAndRange NonStaticRegex ) + , ( "CoreArrayUsage", decodeFileAndRange CoreArrayUsage ) ] @@ -374,3 +375,10 @@ encodeMessageData m = [ ( "file", JE.string file ) , ( "range", Ranges.encode range ) ] + + CoreArrayUsage file range -> + encodeTyped "CoreArrayUsage" <| + JE.object + [ ( "file", JE.string file ) + , ( "range", Ranges.encode range ) + ] diff --git a/src/Analyser/Messages/Types.elm b/src/Analyser/Messages/Types.elm index 76df5e53..ebb0e8df 100644 --- a/src/Analyser/Messages/Types.elm +++ b/src/Analyser/Messages/Types.elm @@ -64,6 +64,7 @@ type MessageData | MultiLineRecordFormatting FileName Range | UnnecessaryPortModule FileName | NonStaticRegex FileName Range + | CoreArrayUsage FileName Range type alias GetFiles = diff --git a/src/Analyser/Messages/Util.elm b/src/Analyser/Messages/Util.elm index dbd15785..008d1f70 100644 --- a/src/Analyser/Messages/Util.elm +++ b/src/Analyser/Messages/Util.elm @@ -221,6 +221,18 @@ getMessageInfo m = , False ) + CoreArrayUsage fileName range -> + ( String.concat + [ "Use of `Array` is disadviced. In \"" + , fileName + , "\" at " + , rangeToString range + ] + , always [ fileName ] + , [ range ] + , False + ) + DebugLog fileName range -> ( String.concat [ "Use of debug log in file \"" diff --git a/src/Inspection.elm b/src/Inspection.elm index 3a5bad5b..f7338bde 100644 --- a/src/Inspection.elm +++ b/src/Inspection.elm @@ -21,6 +21,7 @@ import Analyser.Checks.UnnecessaryListConcat as UnnecessaryListConcat import Analyser.Checks.MultiLineRecordFormatting as MultiLineRecordFormatting import Analyser.Checks.UnnecessaryPortModule as UnnecessaryPortModule import Analyser.Checks.NonStaticRegex as NonStaticRegex +import Analyser.Checks.CoreArrayUsage as CoreArrayUsage import Analyser.Checks.Base exposing (Checker) import Analyser.Util import Analyser.Configuration as Configuration exposing (Configuration) @@ -46,6 +47,7 @@ checkers = , MultiLineRecordFormatting.checker , UnnecessaryPortModule.checker , NonStaticRegex.checker + , CoreArrayUsage.checker ]