2017-01-07 20:29:26 +03:00
|
|
|
module Main exposing (main)
|
|
|
|
|
2018-11-05 20:59:42 +03:00
|
|
|
-- Rules
|
|
|
|
|
2018-11-05 21:06:03 +03:00
|
|
|
import Browser
|
2017-06-12 21:04:02 +03:00
|
|
|
import Html exposing (..)
|
2018-11-06 15:08:20 +03:00
|
|
|
import Html.Attributes exposing (class, id, style)
|
2018-11-05 21:30:47 +03:00
|
|
|
import Html.Events exposing (onInput)
|
2018-11-11 01:37:18 +03:00
|
|
|
import Lint exposing (Rule, Severity(..), lintSource)
|
|
|
|
import Lint.Error exposing (Error)
|
2017-01-29 23:35:00 +03:00
|
|
|
import Lint.Rules.NoDebug
|
2018-11-05 21:30:47 +03:00
|
|
|
import Result exposing (Result)
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= Replace String
|
|
|
|
|
|
|
|
|
2018-11-11 01:37:18 +03:00
|
|
|
config : List ( Severity, Rule )
|
2017-06-17 12:56:34 +03:00
|
|
|
config =
|
2018-11-05 21:30:47 +03:00
|
|
|
[ ( Critical, Lint.Rules.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 )
|
2017-01-20 01:31:55 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-01-07 20:29:26 +03:00
|
|
|
init : String
|
|
|
|
init =
|
2017-01-19 23:02:21 +03:00
|
|
|
"""module Main exposing (f)
|
|
|
|
|
|
|
|
import Html
|
2017-01-20 00:27:11 +03:00
|
|
|
import Html exposing (..)
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
f : Int -> Int
|
2017-01-07 23:17:01 +03:00
|
|
|
f x = x Debug.log 1
|
2017-01-07 20:29:26 +03:00
|
|
|
|
2017-01-19 23:02:21 +03:00
|
|
|
g n = n + 1
|
2017-01-07 20:29:26 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> String -> String
|
|
|
|
update action model =
|
|
|
|
case action of
|
|
|
|
Replace m ->
|
|
|
|
m
|
|
|
|
|
|
|
|
|
2018-11-11 01:37:18 +03:00
|
|
|
errorToString : Error -> String
|
2018-11-06 15:15:23 +03:00
|
|
|
errorToString { message, range } =
|
|
|
|
message ++ " (line " ++ String.fromInt range.start.row ++ ", column " ++ String.fromInt range.start.column ++ ")"
|
|
|
|
|
|
|
|
|
2017-01-10 00:12:37 +03:00
|
|
|
lint : String -> Html Msg
|
|
|
|
lint source =
|
2017-01-07 22:58:41 +03:00
|
|
|
let
|
2018-11-11 01:37:18 +03:00
|
|
|
lintResult : Result (List String) (List ( Severity, Error ))
|
2017-06-12 21:04:02 +03:00
|
|
|
lintResult =
|
2017-06-17 12:56:34 +03:00
|
|
|
lintSource config source
|
2017-01-17 01:38:05 +03:00
|
|
|
|
2018-11-05 21:30:47 +03:00
|
|
|
messages : List String
|
2017-01-17 01:38:05 +03:00
|
|
|
messages =
|
2017-06-12 21:04:02 +03:00
|
|
|
case lintResult of
|
|
|
|
Err errors ->
|
|
|
|
errors
|
|
|
|
|
|
|
|
Ok errors ->
|
|
|
|
if List.isEmpty errors then
|
|
|
|
[ "No errors." ]
|
2018-11-05 20:59:42 +03:00
|
|
|
|
2017-06-12 21:04:02 +03:00
|
|
|
else
|
2018-11-06 15:15:23 +03:00
|
|
|
List.map (Tuple.second >> errorToString) errors
|
2017-01-07 22:58:41 +03:00
|
|
|
in
|
2018-11-05 20:59:42 +03:00
|
|
|
div []
|
|
|
|
(List.map
|
|
|
|
(\message -> p [] [ text message ])
|
|
|
|
messages
|
|
|
|
)
|
2017-01-07 22:58:41 +03:00
|
|
|
|
|
|
|
|
2017-01-07 20:29:26 +03:00
|
|
|
view : String -> Html Msg
|
|
|
|
view model =
|
2017-01-10 00:12:37 +03:00
|
|
|
div [ id "wrapper" ]
|
2017-01-16 00:57:03 +03:00
|
|
|
[ div [ id "left" ]
|
|
|
|
[ p [ class "title" ] [ text "Source code" ]
|
|
|
|
, textarea
|
|
|
|
[ id "input"
|
2018-11-05 21:30:47 +03:00
|
|
|
, onInput Replace
|
2018-11-06 15:08:20 +03:00
|
|
|
, style "height" "500px"
|
|
|
|
, style "width" "500px"
|
2017-01-16 00:57:03 +03:00
|
|
|
]
|
|
|
|
[ text model ]
|
|
|
|
, div []
|
|
|
|
[ p [ class "title" ] [ text "Linting errors" ]
|
2018-11-05 21:30:47 +03:00
|
|
|
, ul [ id "lint" ]
|
|
|
|
[ li [] [ lint model ]
|
2017-01-16 00:57:03 +03:00
|
|
|
]
|
|
|
|
]
|
2017-01-10 00:12:37 +03:00
|
|
|
]
|
|
|
|
]
|
2017-01-07 20:29:26 +03:00
|
|
|
|
|
|
|
|
2018-11-05 21:30:47 +03:00
|
|
|
main : Program () String Msg
|
2017-01-07 20:29:26 +03:00
|
|
|
main =
|
2018-11-05 21:06:03 +03:00
|
|
|
Browser.sandbox
|
2018-11-05 21:30:47 +03:00
|
|
|
{ init = init
|
2017-01-07 20:29:26 +03:00
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
}
|