Skip to content

Commit

Permalink
Merge pull request #53 from stil4m/issue-51
Browse files Browse the repository at this point in the history
Issue #51: Implemented check
  • Loading branch information
stil4m authored Mar 15, 2017
2 parents 591bd5f + ef26667 commit 327533c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Analyser/Checks/CoreArrayUsage.elm
Original file line number Diff line number Diff line change
@@ -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" ]
8 changes: 8 additions & 0 deletions src/Analyser/Messages/Json.elm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ decodeMessageData =
, ( "DropConsOfItemAndList", decodeFileAndRange DropConsOfItemAndList )
, ( "UnnecessaryListConcat", decodeFileAndRange UnnecessaryListConcat )
, ( "NonStaticRegex", decodeFileAndRange NonStaticRegex )
, ( "CoreArrayUsage", decodeFileAndRange CoreArrayUsage )
]


Expand Down Expand Up @@ -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 )
]
1 change: 1 addition & 0 deletions src/Analyser/Messages/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type MessageData
| MultiLineRecordFormatting FileName Range
| UnnecessaryPortModule FileName
| NonStaticRegex FileName Range
| CoreArrayUsage FileName Range


type alias GetFiles =
Expand Down
12 changes: 12 additions & 0 deletions src/Analyser/Messages/Util.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 \""
Expand Down
2 changes: 2 additions & 0 deletions src/Inspection.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -46,6 +47,7 @@ checkers =
, MultiLineRecordFormatting.checker
, UnnecessaryPortModule.checker
, NonStaticRegex.checker
, CoreArrayUsage.checker
]


Expand Down

0 comments on commit 327533c

Please sign in to comment.