mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-24 15:54:02 +03:00
Rename the file's name field to path
This is a more accurate name for a field that is like "src/Folder/File.elm"
This commit is contained in:
parent
24f52dd660
commit
4b9e2ae8d9
@ -61,9 +61,7 @@ f x = x Debug.log 1
|
||||
|
||||
g n = n + 1
|
||||
"""
|
||||
|
||||
tmpModel : Model
|
||||
tmpModel =
|
||||
in
|
||||
{ sourceCode = sourceCode
|
||||
, lintErrors = []
|
||||
, noDebugEnabled = True
|
||||
@ -74,8 +72,7 @@ g n = n + 1
|
||||
, noUnusedTypeConstructorsEnabled = True
|
||||
, showConfigurationAsText = False
|
||||
}
|
||||
in
|
||||
{ tmpModel | lintErrors = lintSource (config tmpModel) { fileName = "", source = sourceCode } }
|
||||
|> runLinting
|
||||
|
||||
|
||||
|
||||
@ -124,42 +121,36 @@ update : Msg -> Model -> Model
|
||||
update action model =
|
||||
case action of
|
||||
UserEditedSourceCode sourceCode ->
|
||||
{ model
|
||||
| sourceCode = sourceCode
|
||||
, lintErrors = lintSource (config model) { fileName = "Source code", source = sourceCode }
|
||||
}
|
||||
{ model | sourceCode = sourceCode }
|
||||
|> runLinting
|
||||
|
||||
UserToggledNoDebugRule ->
|
||||
{ model | noDebugEnabled = not model.noDebugEnabled }
|
||||
|> rerunLinting
|
||||
|> runLinting
|
||||
|
||||
UserToggledNoUnusedVariablesRule ->
|
||||
{ model | noUnusedVariablesEnabled = not model.noUnusedVariablesEnabled }
|
||||
|> rerunLinting
|
||||
|> runLinting
|
||||
|
||||
UserToggledNoImportingEverythingRule ->
|
||||
{ model | noImportingEverythingEnabled = not model.noImportingEverythingEnabled }
|
||||
|> rerunLinting
|
||||
|> runLinting
|
||||
|
||||
UserToggledNoExtraBooleanComparisonRule ->
|
||||
{ model | noExtraBooleanComparisonEnabled = not model.noExtraBooleanComparisonEnabled }
|
||||
|> rerunLinting
|
||||
|> runLinting
|
||||
|
||||
UserToggledNoUnusedTypeConstructorsRule ->
|
||||
{ model | noUnusedTypeConstructorsEnabled = not model.noUnusedTypeConstructorsEnabled }
|
||||
|> rerunLinting
|
||||
|> runLinting
|
||||
|
||||
UserToggledConfigurationAsText ->
|
||||
{ model | showConfigurationAsText = not model.showConfigurationAsText }
|
||||
|
||||
|
||||
rerunLinting : Model -> Model
|
||||
rerunLinting model =
|
||||
{ model
|
||||
| lintErrors =
|
||||
lintSource (config model)
|
||||
{ fileName = "Source code", source = model.sourceCode }
|
||||
}
|
||||
runLinting : Model -> Model
|
||||
runLinting model =
|
||||
{ model | lintErrors = lintSource (config model) (file model.sourceCode) }
|
||||
|
||||
|
||||
|
||||
@ -365,9 +356,7 @@ lintErrors model =
|
||||
]
|
||||
|
||||
else
|
||||
[ ( { name = "Source code"
|
||||
, source = model.sourceCode
|
||||
}
|
||||
[ ( file model.sourceCode
|
||||
, model.lintErrors
|
||||
|> List.map fromLintError
|
||||
)
|
||||
@ -382,3 +371,8 @@ fromLintError error =
|
||||
, details = Lint.errorDetails error
|
||||
, range = Lint.errorRange error
|
||||
}
|
||||
|
||||
|
||||
file : String -> { path : String, source : String }
|
||||
file source =
|
||||
{ path = "SOURCE CODE", source = source }
|
||||
|
14
src/Lint.elm
14
src/Lint.elm
@ -58,19 +58,19 @@ type LintError
|
||||
lintSource config sourceCode
|
||||
|
||||
-}
|
||||
lintSource : List Rule -> { fileName : String, source : String } -> List LintError
|
||||
lintSource config { fileName, source } =
|
||||
lintSource : List Rule -> { path : String, source : String } -> List LintError
|
||||
lintSource config { path, source } =
|
||||
case parseSource source of
|
||||
Ok file ->
|
||||
config
|
||||
|> List.concatMap (lintSourceWithRule fileName file)
|
||||
|> List.concatMap (lintSourceWithRule path file)
|
||||
|> List.sortWith compareErrorPositions
|
||||
|
||||
Err _ ->
|
||||
[ LintError
|
||||
{ file = fileName
|
||||
{ file = path
|
||||
, ruleName = "ParsingError"
|
||||
, message = fileName ++ " is not a correct Elm file"
|
||||
, message = path ++ " is not a correct Elm file"
|
||||
, details =
|
||||
[ "I could not understand the contents of this file, and this prevents me from analyzing it. It's highly likely that the contents of the file is not correct Elm code."
|
||||
, "Hint: Try running `elm make`. The compiler should give you better hints on how to resolve the problem."
|
||||
@ -81,9 +81,9 @@ lintSource config { fileName, source } =
|
||||
|
||||
|
||||
lintSourceWithRule : String -> File -> Rule -> List LintError
|
||||
lintSourceWithRule fileName file rule =
|
||||
lintSourceWithRule path file rule =
|
||||
Rule.analyzer rule file
|
||||
|> List.map (ruleErrorToLintError fileName rule)
|
||||
|> List.map (ruleErrorToLintError path rule)
|
||||
|
||||
|
||||
compareErrorPositions : LintError -> LintError -> Order
|
||||
|
Loading…
Reference in New Issue
Block a user