brittany
Format Haskell source code
TLDR
Format a Haskell source file and print the result to stdout
Format all Haskell source files in the current directory in-place
Check whether a Haskell source file needs changes and indicate the result through the programme's exit code
Format a Haskell source file using the specified amount of spaces per indentation level and line length
Format a Haskell source file according to the style defined in the specified configuration file
SYNOPSIS
brittany [OPTIONS] [FILE...]
brittany --stdin
PARAMETERS
--write-mode
Formats files in-place. This is the default behavior.
--check-mode
Checks if files are formatted correctly without modifying them. Exits with a non-zero status if formatting issues are found.
--diff-mode
Shows a diff of changes that would be applied without actually modifying the files.
--stdin
Reads input from standard input and writes formatted output to standard output.
--config
Specifies a custom configuration file to use instead of the default .brittany.yaml.
--language-extensions
Enables specific GHC language extensions for parsing Haskell code.
--version
Displays the Brittany version information.
--help
Shows the command's help message and available options.
DESCRIPTION
Brittany is an opinionated, yet highly configurable, source code formatter for Haskell. Its primary goal is to ensure consistent code style across projects and teams, significantly improving code readability and reducing debates over formatting choices.
It supports various modes of operation: formatting files in-place (the default), checking for formatting compliance without modifications (--check-mode), and showing a diff of potential changes (--diff-mode). Configuration is handled via .brittany.yaml files, allowing users to customize rules like column limits, indentation, and specific syntax preferences. Brittany is a valuable tool for maintaining code quality and consistency in Haskell development workflows, often integrated into CI/CD pipelines or Git hooks.
CAVEATS
Brittany is inherently opinionated; while configurable, it might not align perfectly with every coding style.
It requires a working Haskell environment (e.g., GHC, Stack, or Cabal) to be installed on the system.
Performance can sometimes be a concern on extremely large or complex Haskell codebases.
CONFIGURATION FILES
Brittany leverages YAML-based configuration files, typically named .brittany.yaml, to control its formatting behavior. These files allow users to define detailed rules, such as maximum line length, indentation levels, and specific formatting preferences for various Haskell constructs. They can be placed in the project root or user's home directory for global settings.
INTEGRATION IN WORKFLOWS
A common use case for Brittany is its integration into development workflows. It's frequently used in Git hooks (e.g., pre-commit hooks) to automatically format code before commits, or incorporated into CI/CD pipelines to enforce code style compliance across pull requests. This ensures that all code contributed to a project adheres to a consistent formatting standard.
HISTORY
Brittany originated as a community-driven project within the Haskell ecosystem to address the need for an opinionated yet flexible code formatter. It was developed to provide an alternative to existing formatters, balancing strictness with user configurability. Its development is ongoing, focusing on robustness and broader language feature support.