• 作成:

現在StackageのLTS Haskell 14.16で入るhlintのv2.1.26は壊れているので対策しました

hlintがParse Errorを報告する意味が解らなかったのでissueを書いていたのですが, allow: newerを有効にしてnightlyの最新版を入れたら治っていました. 最新版では治っているものにissue建てても流石に無駄だなあと思ったので私個人の記事に書いて供養します.

現在の対処法としては, hlintコマンドを使う時に

hlint --ignore="Parse error" src

などとすることです.

どうせシンタックスエラーはGHCがビルドする時にエラーになるので, hlintでチェックしてもあまり意味がないのでこれで問題ないでしょう.

コメントでパースエラーの制御は出来ませんでした. 方法はあるのかもしれませんけど.

以下はissueに途中まで書いてたものです.


My Env.

2019-12-02T20:18:32 ncaq@strawberry/pts/3(0) ~
% cat /etc/os-release
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo/Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"
2019-12-02T20:18:36 ncaq@strawberry/pts/3(0) ~
% stack --version
Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2
2019-12-02T20:18:39 ncaq@strawberry/pts/3(0) ~
% hlint --version
HLint v2.1.26, (C) Neil Mitchell 2006-2019

I write Yesod Application. I updated LTS 13 -> 14. I see hlint Parse Error.

% stack exec -- hlint src
src/Application.hs:64:77: Error: Parse error
Found:
      -- Some basic initializations: HTTP connection manager, logger, and static
      -- subsite.
  >   appStatic <- (if appMutableStatic appSettings then staticDevel else static) $ appStaticDir appSettings

    -- | 環境を確認する


1 hint

I try write minimal repro code.

% stack new foo yesodweb/sqlite
Downloading template "yesodweb/sqlite" to create project "foo" in foo/ ...
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- foo/

Selecting the best among 16 snapshots...

* Matches lts-14.16

Selected resolver: lts-14.16
Initialising configuration using resolver: lts-14.16
Total number of user packages considered: 1
Writing configuration to file: foo/stack.yaml
All done.
2019-12-02T19:57:15 ncaq@strawberry/pts/4(0) ~/Downloads
% cd foo
app/  config/  src/  static/  templates/  test/  .dir-locals.el  .gitignore  README.md  foo.cabal  package.yaml  stack.yaml
2019-12-02T19:57:19 ncaq@strawberry/pts/4(0) ~/Downloads/foo
% hlint src
src/Application.hs:64:70: Error: Parse error
Found:
        appLogger <- newStdoutLoggerSet defaultBufSize >>= makeYesodLogger
        appStatic <-
  >         (if appMutableStatic appSettings then staticDevel else static)
            (appStaticDir appSettings)


src/Foundation.hs:7:1: Warning: Unused LANGUAGE pragma
Found:
  {-# LANGUAGE ExplicitForAll #-}
Perhaps you should remove it.
Note: Extension ExplicitForAll is implied by RankNTypes

src/Foundation.hs:79:9: Suggestion: Replace case with fromMaybe
Found:
  case appRoot $ appSettings app of
      Nothing -> getApprootText guessApproot app req
      Just root -> root
Perhaps:
  Data.Maybe.fromMaybe (getApprootText guessApproot app req)
    (appRoot $ appSettings app)

src/Foundation.hs:261:23: Suggestion: Use :
Found:
  [authOpenId Claimed []] ++ extraAuthPlugins
Perhaps:
  authOpenId Claimed [] : extraAuthPlugins

src/Handler/Comment.hs:6:16: Suggestion: Redundant bracket
Found:
  do comment <- (requireCheckJsonBody :: Handler Comment)
     maybeCurrentUserId <- maybeAuthId
     let comment' = comment{commentUserId = maybeCurrentUserId}
     insertedComment <- runDB $ insertEntity comment'
     returnJson insertedComment
Perhaps:
  do comment <- requireCheckJsonBody :: Handler Comment
     maybeCurrentUserId <- maybeAuthId
     let comment' = comment{commentUserId = maybeCurrentUserId}
     insertedComment <- runDB $ insertEntity comment'
     returnJson insertedComment

src/Handler/Home.hs:30:20: Suggestion: Redundant $
Found:
  runDB $ getAllComments
Perhaps:
  runDB getAllComments

src/Handler/Home.hs:33:9: Suggestion: Reduce duplication
Found:
  let (commentFormId, commentTextareaId, commentListId) = commentIds
  aDomId <- newIdent
  setTitle "Welcome To Yesod!"
  $( widgetFile "homepage" )

Perhaps:
  Combine with src/Handler/Home.hs:48:9

src/Handler/Home.hs:45:20: Suggestion: Redundant $
Found:
  runDB $ getAllComments
Perhaps:
  runDB getAllComments

8 hints

Parse Error too.

These code syntax is correct. GHC build to success.

I try write more minimal repro code.

data Foo
  = Foo
    { fooMutableStatic :: Bool
    }

foo :: Foo
foo = Foo
      { fooMutableStatic = True
      }

staticDevel :: Int -> Int
staticDevel x = x + 1

static :: Int -> Int
static x = x

main :: IO ()
main = do
  let use = (if fooMutableStatic foo then staticDevel else static) 0
  print use

This code is "Parse Error", however another reason.

% hlint HlintParseErrorIfThenElse.hs
HlintParseErrorIfThenElse.hs:14:8: Error: Parse error
Found:
    staticDevel x = x + 1

  > static :: Int -> Int
    static x = x


1 hint

Is it hlint bug?