Add NoDebug rule

This commit is contained in:
Jeroen Engels 2017-01-07 21:17:01 +01:00
parent bd1b3dec99
commit a0e532c07b
5 changed files with 48 additions and 8 deletions

View File

@ -1,4 +1,4 @@
module Lint exposing (lint, LintRule, Error)
module Lint exposing (lint, LintRule, Error, doNothing)
import Ast.Expression exposing (..)
import Ast.Statement exposing (..)
@ -24,6 +24,11 @@ type alias Visitor context =
LintRule context -> context -> ( List Error, context )
doNothing : LintImplementation a context
doNothing ctx _ =
( [], ctx )
visitExpression : Expression -> Visitor context
visitExpression node rule context =
rule.expressionFn context node

View File

@ -4,7 +4,8 @@
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
".",
"rules"
],
"exposed-modules": [],
"dependencies": {

View File

@ -8,6 +8,8 @@ import Html exposing (Html, p, div, li, ul, pre, textarea, text)
import Html.Attributes exposing (id)
import Html.Events exposing (..)
import Json.Decode as JD
import Lint
import NoDebug
type Msg
@ -19,12 +21,12 @@ init =
"""module Main exposing (..)
f : Int -> Int
f x = x + 1
f x = x Debug.log 1
g : Int -> Int
g x = x * 2
a : a -> a
a = Debug.log "foo" x
h = f << g
h = f << Debug.log
"""
@ -98,7 +100,7 @@ lint ast =
|> Result.withDefault []
errors =
[]
Lint.lint statements NoDebug.rule
in
div [] (List.map (\x -> p [] [ text x ]) errors)

View File

@ -4,7 +4,9 @@
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
".",
"..",
"../rules"
],
"exposed-modules": [],
"dependencies": {

30
rules/NoDebug.elm Normal file
View File

@ -0,0 +1,30 @@
module NoDebug exposing (rule)
import Lint exposing (LintRule, Error, doNothing)
import Ast.Expression exposing (..)
type alias Context =
{}
rule : LintRule Context
rule =
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = expressionFn
, context = Context
}
expressionFn : Context -> Expression -> ( List Error, Context )
expressionFn ctx node =
case node of
Variable vars ->
if List.member "Debug" vars then
( [ "Forbidden use of Debug" ], ctx )
else
( [], ctx )
_ ->
( [], ctx )