如何在 haskell 中为他开启所有迂腐模式?
How to turn all pedantic mode for hie in haskell?
是否有可能以某种方式将 --pedantic(如在 stack build --pedantic 中)切换到 Haskell-ide-engine?我希望在编译期间在 IDE 中看到更多错误,因为我对这门语言还很陌生,例如对于非详尽的案例模式。
除了这个错误 https://github.com/haskell/haskell-ide-engine/issues/449,我在项目页面上找不到任何信息,但这似乎没有解决这个问题。
据我所知,不可能将编译器或构建工具开关传递给 HIE。 HIE 会根据您的构建工具自动确定您的编译器标志,并且没有覆盖机制。
相反,您应该将适当的编译器标志添加到您的构建文件中。 stack build --pedantic
传递 -Wall
和 -Werror
标志,因此这些是您要添加到构建文件中的标志。这样,标志将始终被 stack build
和 HIE 使用。
package.yaml
如果您有一个 package.yaml
文件(大多数 Stack 项目的默认文件),那么您应该将以下行添加到该文件的 ghc-options
部分:
- -Wall
- -Werror
示例:
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
包名.cabal
如果您 没有 有一个 package.yaml
文件,则将以下行添加到您的所有 executable
和 library
部分阴谋集团文件:
ghc-options:
-Wall
-Werror
示例:
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
更多旗帜
附带说明一下,GHC 的 -Wall
不会启用 所有 警告,只有大部分警告。您可能想要添加这些额外的警告:
-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wpartial-fields
有关详细信息,请参阅 https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html。
在开发过程中,您可能希望从 package.yaml
或 cabal 文件中删除 -Werror
。
是否有可能以某种方式将 --pedantic(如在 stack build --pedantic 中)切换到 Haskell-ide-engine?我希望在编译期间在 IDE 中看到更多错误,因为我对这门语言还很陌生,例如对于非详尽的案例模式。
除了这个错误 https://github.com/haskell/haskell-ide-engine/issues/449,我在项目页面上找不到任何信息,但这似乎没有解决这个问题。
据我所知,不可能将编译器或构建工具开关传递给 HIE。 HIE 会根据您的构建工具自动确定您的编译器标志,并且没有覆盖机制。
相反,您应该将适当的编译器标志添加到您的构建文件中。 stack build --pedantic
传递 -Wall
和 -Werror
标志,因此这些是您要添加到构建文件中的标志。这样,标志将始终被 stack build
和 HIE 使用。
package.yaml
如果您有一个 package.yaml
文件(大多数 Stack 项目的默认文件),那么您应该将以下行添加到该文件的 ghc-options
部分:
- -Wall
- -Werror
示例:
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
包名.cabal
如果您 没有 有一个 package.yaml
文件,则将以下行添加到您的所有 executable
和 library
部分阴谋集团文件:
ghc-options:
-Wall
-Werror
示例:
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
更多旗帜
附带说明一下,GHC 的 -Wall
不会启用 所有 警告,只有大部分警告。您可能想要添加这些额外的警告:
-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wpartial-fields
有关详细信息,请参阅 https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html。
在开发过程中,您可能希望从 package.yaml
或 cabal 文件中删除 -Werror
。