hlint
Suggest improvements for Haskell code
TLDR
Display suggestions for a given file
Check all Haskell files and generate a report
Automatically apply most suggestions
Display additional options
Generate a settings file ignoring all outstanding hints
SYNOPSIS
hlint [OPTIONS] [FILES_OR_DIRECTORIES...]
PARAMETERS
-h, --help
Show the help message and exit.
-V, --version
Show the version number and exit.
-v, --verbose
Display more detailed information, including ignored hints.
-q, --quiet
Suppress all suggestions, only show errors/warnings.
--hint=FILE
Specify a hint file or module to load custom hints.
--ignore=HINT
Ignore a specific hint by its name, e.g., 'Redundant do'.
--deny=HINT
Treat a specific hint as an error, causing hlint to exit with a non-zero status if found.
--only=HINT
Only apply specific hints and ignore all others.
--suggestions
Display suggestions that can be applied automatically.
--auto
Automatically apply suggestions to the source files. Use with extreme caution and version control!
--json
Output results in JSON format, suitable for machine parsing.
--report=FILE
Generate an HTML report of the linting results to the specified file.
--color, --no-color
Force or disable colored output regardless of terminal capabilities.
--extension=NAME
Enable a specific GHC language extension (e.g., 'OverloadedStrings').
--fail-on=LEVEL
Exit with a non-zero status if messages of the specified level (e.g., 'warning', 'error', 'suggestion') or higher are found.
--git
Analyze only the changes in git-tracked files compared to the last commit.
--dot-hlint=PATH
Specify an alternative path to the .hlint.yaml
configuration file.
--no-dot-hlint
Prevent hlint from reading the default .hlint.yaml
configuration file.
DESCRIPTION
hlint is a static analysis tool for Haskell source code that identifies common errors, suggests improvements, and enforces stylistic guidelines. It reads Haskell modules and provides recommendations to make the code more concise, performant, or idiomatic.
It can detect issues like redundant parentheses, unused imports, inefficient list comprehensions, and opportunities to use more idiomatic Haskell features. hlint leverages GHC's parsing infrastructure to understand the code structure, allowing it to provide sophisticated suggestions beyond simple regex matching. It's an invaluable tool for developers to maintain high code quality, consistency, and learn about better Haskell patterns.
CAVEATS
While hlint is powerful, it can occasionally produce false positives, especially with highly specialized domain-specific code or complex type-level programming. The --auto
option is destructive and should only be used after committing changes to version control, as it directly modifies source files. Performance on very large codebases might be slow without proper configuration or filtering.
CONFIGURATION
hlint can be configured using a .hlint.yaml
file placed in the project root or specified via the --dot-hlint
option. This file allows users to define custom hints, ignore specific hints globally or for certain paths, and set default options.
INTEGRATION
hlint is often integrated into build systems like Cabal and Stack, CI/CD pipelines, and editor plugins (e.g., for VS Code, Emacs, Vim) to provide real-time feedback and enforce coding standards across a team.
HISTORY
hlint was created by Neil Mitchell, with its initial public releases dating back to around 2008-2009. It quickly became a standard tool in the Haskell ecosystem for code quality and consistency. It has been actively developed and maintained since its inception, continually adding new hints, improving performance, and adapting to new GHC versions and language features.