LinuxCommandLibrary

hlint

Suggest improvements for Haskell code

TLDR

Display suggestions for a given file

$ hlint [path/to/file] options
copy

Check all Haskell files and generate a report
$ hlint [path/to/directory] [[-r|--report]]
copy

Automatically apply most suggestions
$ hlint [path/to/file] --refactor
copy

Display additional options
$ hlint [path/to/file] --refactor-options
copy

Generate a settings file ignoring all outstanding hints
$ hlint [path/to/file] --default > [.hlint.yaml]
copy

SYNOPSIS

hlint [OPTION...] [FILE|DIR]...

PARAMETERS

-h, --help
    Display help message and exit

-i, --ignore=NOTE
    Ignore suggestions matching the given note(s)

--hint=FILE
    Load hints from the given file(s), can be repeated

-j, --threads=N
    Set the number of threads to use (default: auto-detect)

--json
    Output results in JSON format for tooling integration

-r, --refactor
    Enable refactoring mode, printing replacement hints

-x, --refactor-hint=NOTE
    Refactor only hints matching NOTE

--test
    Run in test mode, checking if hints apply correctly

-c, --color=YES|NO|AUTO
    Control colored output (default: AUTO)

--cpp-include=FILE
    Include FILE before parsing for CPP preprocessing

-p, --parallel
    Deprecated alias for --threads (use auto)

--report
    Generate HTML report file

-q, --quiet
    Suppress non-error output

--find=QUERY
    Suggest hints matching the query

--no-exit-code
    Always exit with code 0, even if suggestions found

DESCRIPTION

HLint is a powerful command-line tool designed specifically for Haskell programmers. It analyzes Haskell source code files or entire directories, identifying opportunities for improvement such as simplifying expressions, replacing verbose code with more idiomatic alternatives, fixing style issues, and suggesting performance enhancements.

Unlike rigid linters, HLint provides suggestions rather than errors, allowing developers to focus on code quality without disrupting workflow. It uses a flexible hint system where rules are defined in external files, enabling customization for project-specific needs or team conventions. Hints cover common patterns like using map instead of explicit list comprehensions, avoiding unnecessary seq, or preferring foldl' over foldl.

HLint supports parallel processing for large codebases, JSON output for integration with editors like Vim or VS Code via plugins, and refactoring modes to automatically apply changes. It's an essential tool in the Haskell ecosystem, often run in CI pipelines or pre-commit hooks to maintain high code standards. Written in Haskell itself, it's efficient and extensible.

CAVEATS

Requires a Haskell environment (GHC); install via cabal install hlint or stack install hlint. Only works on Haskell source code (.hs, .lhs files). May produce false positives on highly custom code.

EDITOR INTEGRATION

Plugins available for Vim (vim-hlint), Emacs (flycheck-hlint), VS Code (haskell extension). Run hlint --json for piping into tools.

CUSTOM HINTS

Create .hlint.yaml in project root for local rules. Example: ignore: {name: "Use foo"} to suppress specific hints.

HISTORY

Developed by Neil Mitchell starting in 2006. Actively maintained as part of the Haskell toolchain, with regular releases via Hackage. Evolved from simple style checker to full-featured suggester with JSON/parallel support in recent versions.

SEE ALSO

ghc(1), cabal(1), stack(8), ghcid(1)

Copied to clipboard