mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-28 00:56:51 +03:00
Add NoDebug rule
This commit is contained in:
parent
bd1b3dec99
commit
a0e532c07b
7
Lint.elm
7
Lint.elm
@ -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
|
||||
|
@ -4,7 +4,8 @@
|
||||
"repository": "https://github.com/user/project.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"."
|
||||
".",
|
||||
"rules"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
30
rules/NoDebug.elm
Normal 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 )
|
Loading…
Reference in New Issue
Block a user