Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
cf453170
Commit
cf453170
authored
Sep 25, 2019
by
Vaibhav Sagar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use CPP to stay compatible with old HLint
parent
ac0882dc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
24 deletions
+69
-24
ihaskell.cabal
ihaskell.cabal
+1
-1
Evaluate.hs
src/IHaskell/Eval/Evaluate.hs
+1
-1
Lint.hs
src/IHaskell/Eval/Lint.hs
+67
-22
No files found.
ihaskell.cabal
View file @
cf453170
...
@@ -68,7 +68,7 @@ library
...
@@ -68,7 +68,7 @@ library
ghc-parser >=0.1.7,
ghc-parser >=0.1.7,
ghc-paths >=0.1,
ghc-paths >=0.1,
haskeline -any,
haskeline -any,
hlint >=1.9
&& <=2.1.17
,
hlint >=1.9,
haskell-src-exts >=1.18,
haskell-src-exts >=1.18,
http-client >= 0.4,
http-client >= 0.4,
http-client-tls >= 0.2,
http-client-tls >= 0.2,
...
...
src/IHaskell/Eval/Evaluate.hs
View file @
cf453170
...
@@ -294,7 +294,7 @@ evaluate kernelState code output widgetHandler = do
...
@@ -294,7 +294,7 @@ evaluate kernelState code output widgetHandler = do
-- Only run things if there are no parse errors.
-- Only run things if there are no parse errors.
[]
->
do
[]
->
do
when
(
getLintStatus
kernelState
/=
LintOff
)
$
liftIO
$
do
when
(
getLintStatus
kernelState
/=
LintOff
)
$
liftIO
$
do
lintSuggestions
<-
lint
cmds
lintSuggestions
<-
lint
c
ode
c
mds
unless
(
noResults
lintSuggestions
)
$
unless
(
noResults
lintSuggestions
)
$
output
(
FinalResult
lintSuggestions
[]
[]
)
Success
output
(
FinalResult
lintSuggestions
[]
[]
)
Success
...
...
src/IHaskell/Eval/Lint.hs
View file @
cf453170
{-# LANGUAGE NoImplicitPrelude, FlexibleContexts, ViewPatterns #-}
{-# LANGUAGE NoImplicitPrelude, FlexibleContexts, ViewPatterns
, CPP
#-}
module
IHaskell.Eval.Lint
(
lint
)
where
module
IHaskell.Eval.Lint
(
lint
)
where
import
IHaskellPrelude
import
IHaskellPrelude
import
Prelude
(
last
)
import
Data.Maybe
(
mapMaybe
)
import
Data.Maybe
(
mapMaybe
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
Language.Haskell.Exts.Syntax
hiding
(
Module
)
import
qualified
Language.Haskell.Exts.Syntax
as
SrcExts
import
Language.Haskell.Exts
(
parseFileContentsWithMode
)
import
Language.Haskell.Exts
hiding
(
Module
)
import
Language.Haskell.Exts
hiding
(
Module
)
import
Language.Haskell.HLint
as
HLint
import
Language.Haskell.HLint
as
HLint
...
@@ -21,7 +18,15 @@ import IHaskell.Display
...
@@ -21,7 +18,15 @@ import IHaskell.Display
import
IHaskell.Eval.Parser
hiding
(
line
)
import
IHaskell.Eval.Parser
hiding
(
line
)
import
StringUtils
(
replace
)
import
StringUtils
(
replace
)
type
ExtsModule
=
SrcExts
.
Module
SrcSpanInfo
#
if
MIN_VERSION_hlint
(
2
,
1
,
18
)
#
else
import
Prelude
(
last
)
import
qualified
Language.Haskell.Exts.Syntax
as
SrcExts
import
Language.Haskell.Exts
(
parseFileContentsWithMode
)
#
endif
data
LintSuggestion
=
data
LintSuggestion
=
Suggest
Suggest
...
@@ -42,10 +47,47 @@ hlintSettings = unsafePerformIO newEmptyMVar
...
@@ -42,10 +47,47 @@ hlintSettings = unsafePerformIO newEmptyMVar
lintIdent
::
String
lintIdent
::
String
lintIdent
=
"lintIdentAEjlkQeh"
lintIdent
=
"lintIdentAEjlkQeh"
#
if
MIN_VERSION_hlint
(
2
,
1
,
18
)
-- | Given code chunks, perform linting and output a displayable report on linting warnings
-- and errors.
lint
::
String
->
[
Located
CodeBlock
]
->
IO
Display
lint
code
_blocks
=
do
-- Initialize hlint settings
initialized
<-
not
<$>
isEmptyMVar
hlintSettings
unless
initialized
$
autoSettings'
>>=
putMVar
hlintSettings
-- Get hlint settings
(
flags
,
classify
,
hint
)
<-
readMVar
hlintSettings
parsed
<-
parseModuleEx
flags
"-"
(
Just
code
)
-- create 'suggestions'
let
ideas
=
case
parsed
of
Left
_
->
[]
Right
mods
->
applyHints
classify
hint
[
mods
]
suggestions
=
mapMaybe
showIdea
$
filter
(
not
.
ignoredIdea
)
ideas
return
$
Display
$
if
null
suggestions
then
[]
else
[
plain
$
concatMap
plainSuggestion
suggestions
,
html
$
htmlSuggestions
suggestions
]
where
autoSettings'
=
do
(
fixts
,
classify
,
hints
)
<-
autoSettings
let
hidingIgnore
=
Classify
Ignore
"Unnecessary hiding"
""
""
return
(
fixts
,
hidingIgnore
:
classify
,
hints
)
ignoredIdea
idea
=
ideaSeverity
idea
==
Ignore
#
else
type
ExtsModule
=
SrcExts
.
Module
SrcSpanInfo
-- | Given parsed code chunks, perform linting and output a displayable report on linting warnings
-- | Given parsed code chunks, perform linting and output a displayable report on linting warnings
-- and errors.
-- and errors.
lint
::
[
Located
CodeBlock
]
->
IO
Display
lint
::
String
->
[
Located
CodeBlock
]
->
IO
Display
lint
blocks
=
do
lint
_code
blocks
=
do
-- Initialize hlint settings
-- Initialize hlint settings
initialized
<-
not
<$>
isEmptyMVar
hlintSettings
initialized
<-
not
<$>
isEmptyMVar
hlintSettings
unless
initialized
$
unless
initialized
$
...
@@ -70,20 +112,6 @@ lint blocks = do
...
@@ -70,20 +112,6 @@ lint blocks = do
return
(
fixts
,
hidingIgnore
:
classify
,
hints
)
return
(
fixts
,
hidingIgnore
:
classify
,
hints
)
ignoredIdea
idea
=
ideaSeverity
idea
==
Ignore
ignoredIdea
idea
=
ideaSeverity
idea
==
Ignore
showIdea
::
Idea
->
Maybe
LintSuggestion
showIdea
idea
=
case
ideaTo
idea
of
Nothing
->
Nothing
Just
wn
->
Just
Suggest
{
line
=
srcSpanStartLine
$
ideaSpan
idea
,
found
=
showSuggestion
$
ideaFrom
idea
,
whyNot
=
showSuggestion
wn
,
severity
=
ideaSeverity
idea
,
suggestion
=
ideaHint
idea
}
createModule
::
ParseMode
->
Located
CodeBlock
->
Maybe
ExtsModule
createModule
::
ParseMode
->
Located
CodeBlock
->
Maybe
ExtsModule
createModule
md
(
Located
ln
block
)
=
createModule
md
(
Located
ln
block
)
=
case
block
of
case
block
of
...
@@ -154,6 +182,23 @@ createModule md (Located ln block) =
...
@@ -154,6 +182,23 @@ createModule md (Located ln block) =
imptToModule
::
String
->
ParseResult
ExtsModule
imptToModule
::
String
->
ParseResult
ExtsModule
imptToModule
=
parseFileContentsWithMode
md
imptToModule
=
parseFileContentsWithMode
md
#
endif
showIdea
::
Idea
->
Maybe
LintSuggestion
showIdea
idea
=
case
ideaTo
idea
of
Nothing
->
Nothing
Just
wn
->
Just
Suggest
{
line
=
srcSpanStartLine
$
ideaSpan
idea
,
found
=
showSuggestion
$
ideaFrom
idea
,
whyNot
=
showSuggestion
wn
,
severity
=
ideaSeverity
idea
,
suggestion
=
ideaHint
idea
}
plainSuggestion
::
LintSuggestion
->
String
plainSuggestion
::
LintSuggestion
->
String
plainSuggestion
suggest
=
plainSuggestion
suggest
=
printf
"Line %d: %s
\n
Found:
\n
%s
\n
Why not:
\n
%s"
(
line
suggest
)
(
suggestion
suggest
)
(
found
suggest
)
printf
"Line %d: %s
\n
Found:
\n
%s
\n
Why not:
\n
%s"
(
line
suggest
)
(
suggestion
suggest
)
(
found
suggest
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment