Create temp project binary that lints

This commit is contained in:
Jeroen Engels 2017-06-15 16:17:32 +02:00
parent 35d5cdadfd
commit 992bdb88ea
5 changed files with 137 additions and 32 deletions

View File

@ -1,4 +1,4 @@
port module LintConfig exposing (..)
module LintConfig exposing (config)
import Lint.Types exposing (LintRule)
import Lint.Rules.DefaultPatternPosition
@ -17,37 +17,8 @@ import Lint.Rules.SimplifyPiping
import Lint.Rules.SimplifyPropertyAccess
-- import Lint.Runner.Node exposing (runLint)
import Test exposing (describe, Test)
import Test.Runner.Node exposing (run)
import Json.Encode exposing (Value)
-- Needs to be put into main somehow
files : List String
files =
[ "src"
]
main : Test.Runner.Node.TestProgram
main =
run emit all
all : Test
all =
describe "Visitors" []
port emit : ( String, Value ) -> Cmd msg
rules : List (String -> List LintRule)
rules =
config : List LintRule
config =
[ Lint.Rules.DefaultPatternPosition.rule { position = Lint.Rules.DefaultPatternPosition.Last }
, Lint.Rules.NoConstantCondition.rule
, Lint.Rules.NoDebug.rule

View File

@ -0,0 +1,19 @@
{
"dependencies": {
"Bogdanp/elm-ast": "8.0.3 <= v < 9.0.0",
"elm-community/list-extra": "5.0.1 <= v < 6.0.0",
"elm-community/parser-combinators": "1.1.0 <= v < 2.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"version": "1.0.0",
"summary": "Linting binary",
"repository": "https://github.com/jfmengels/elm-lint.git",
"license": "BSD3",
"source-directories": [
"src",
"../src"
],
"exposed-modules": [],
"elm-version": "0.18.0 <= v < 0.19.0"
}

13
lintingDir/runner.js Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env node
const Elm = require('./ok');
const app = Elm.LintApp.worker();
app.ports.linting.send({
filename: 'SomeFile.elm',
source: "add a b = a + b"
});
app.ports.resultPort.subscribe(function(result) {
console.log('result', result)
// app.ports.suggestions.send(suggestions);
});

View File

@ -0,0 +1,66 @@
port module LintApp exposing (..)
import Json.Decode
import Dict exposing (Dict)
import Lint exposing (lintSource)
import Lint.Types exposing (LintError)
import LintConfig exposing (config)
type alias File =
{ filename : String
, source : String
}
port linting : (File -> msg) -> Sub msg
port resultPort : ( File, List String ) -> Cmd msg
type alias Model =
Dict String (List LintError)
type Msg
= Lint File
lint : String -> List String
lint source =
case lintSource config source of
Err errors ->
errors
Ok errors ->
errors
init : ( Model, Cmd Msg )
init =
( Dict.empty, Cmd.none )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Lint file ->
( model
, resultPort
( file, lint file.source )
)
subscriptions : Model -> Sub Msg
subscriptions model =
linting Lint
main : Program Never Model Msg
main =
Platform.program
{ init = init
, update = update
, subscriptions = subscriptions
}

View File

@ -0,0 +1,36 @@
module LintConfig exposing (config)
import Lint.Types exposing (LintRule)
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
config : List LintRule
config =
[ Lint.Rules.DefaultPatternPosition.rule { position = Lint.Rules.DefaultPatternPosition.Last }
, Lint.Rules.NoConstantCondition.rule
, Lint.Rules.NoDebug.rule
, Lint.Rules.NoDuplicateImports.rule
, Lint.Rules.NoExposingEverything.rule
, Lint.Rules.NoImportingEverything.rule
, Lint.Rules.NoNestedLet.rule
, Lint.Rules.NoUnannotatedFunction.rule
, Lint.Rules.NoUnusedVariables.rule
, Lint.Rules.NoUselessIf.rule
, Lint.Rules.NoUselessPatternMatching.rule
, Lint.Rules.NoWarningComments.rule
, Lint.Rules.SimplifyPiping.rule
, Lint.Rules.SimplifyPropertyAccess.rule
]