brittany: Pretty-print Haskell source files

“brittany” is a tool used for formatting Haskell source code in a visually appealing and consistent manner. It is specifically designed to improve the readability and maintainability of Haskell code by automatically applying a set of formatting rules.

Here are some key points about “brittany” and its features:

  • Formatting Haskell Code: “brittany” takes Haskell source code as input and transforms it according to a predefined set of formatting rules. It analyzes the code’s structure, including indentation, line breaks, spacing, and alignment, and applies consistent formatting throughout the file.
  • Code Style Consistency: One of the primary goals of “brittany” is to enforce a consistent code style across projects and developers. By automatically formatting the code, it ensures that the same formatting conventions are applied consistently, improving code readability and making it easier for developers to collaborate.
  • Configurable Formatting Rules: “brittany” allows you to configure various formatting options according to your preferences and project guidelines. You can customize aspects such as indentation width, line length, spacing, and wrapping behavior to align with your desired code style.
  • Integration with Development Workflow: “brittany” is designed to seamlessly integrate with popular Haskell development tools and workflows. It can be used as a standalone command-line tool, integrated into text editors, or incorporated into build systems to automatically format code during development.
  • Respect for Existing Code Style: While “brittany” applies its formatting rules to the code, it also respects existing code style choices. It avoids making unnecessary changes to the code and focuses on improving the formatting without altering the code’s functionality or logic.
  • Editor Integration: “brittany” provides plugins or extensions for various text editors and integrated development environments (IDEs). These plugins enable on-the-fly code formatting, making it easier to maintain a consistent code style while writing code.

Using “brittany” can greatly enhance the readability and maintainability of Haskell code. By automatically applying consistent formatting rules, it reduces the time and effort spent on manual formatting and allows developers to focus more on writing clean and efficient code.

brittany Command Examples

1. Format a Haskell source file and print the result to stdout:

# brittany /path/to/file.hs

2. Format all Haskell source files in the current directory in-place:

# brittany --write-mode=inplace *.hs

3. Check whether a Haskell source file needs changes and indicate the result through the programme’s exit code:

# brittany --check-mode /path/to/file.hs

4. Format a Haskell source file using the specified amount of spaces per indentation level and line length:

# brittany --indent 4 --columns 100 path/to/file.hs

5. Format a Haskell source file according to the style defined in the specified config file:

# brittany --config-file /path/to/config.yaml path/to/file.hs
Related Post