How to turn all pedantic mode for hie in haskell?

Viewed 141

Is it possible to somehow pass --pedantic (as in stack build --pedantic) switch to Haskell-ide-engine? I'd like to see more errors in IDE during compile time as I'm very new to the language, for example for non-exhaustive case patterns.

I cannot find any infos on project page apart from this bug https://github.com/haskell/haskell-ide-engine/issues/449 but this does not seem to adress this issue.

1 Answers

So far as I can tell it is not possible to pass compiler or build tool switches in to HIE. HIE automatically determines your compiler flags based on your build tool and does not have an override mechanism.

Instead you should add the appropriate compiler flags to your build file. stack build --pedantic passes the -Wall and -Werror flags, so those are the flags you want to add to your build file. That way the flags will always be used by both stack build and HIE.

package.yaml

If you have a package.yaml file (the default for most Stack projects) then you should add the following lines to the ghc-options section of that file:

      - -Wall
      - -Werror

Example:

name:                project-name
version:             0.1.0.0
github:              "githubuser/project-name"
license:             BSD3
author:              "Author name here"
maintainer:          "example@example.com"
copyright:           "2020 Author name here"

description:         Example

dependencies:
- base >= 4.7 && < 5

ghc-options:
- -Wall
- -Werror

executables:
  project-name-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N

package-name.cabal

If you do not have a package.yaml file, then add the following lines to all of the executable and library sections your cabal file:

  ghc-options:
    -Wall
    -Werror

Example:

name:                project-name
version:             0.1.0.0
-- synopsis:
-- description:
homepage:            https://github.com/githubuser/project-name#readme
license:             BSD3
license-file:        LICENSE
author:              Author name here
maintainer:          example@example.com
copyright:           2020 Author name here
category:            Web
build-type:          Simple
cabal-version:       >=1.10
extra-source-files:  README.md

executable project-name
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5
  ghc-options:
    -Wall
    -Werror

More flags

As a side note, GHC's -Wall does not enable all of the warnings, only most of them. You might want to add these extra warnings:

-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wpartial-fields

See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html for more details.

During development you might want to remove -Werror from your package.yaml or cabal file.

Related