Forrest logo
tool overview
On this page you find all important commands for the CLI tool black. If the command you are looking for is missing please ask our AI.

black

Black is a popular command line tool used for code formatting in various programming languages, particularly Python. It aims to enforce a consistent and readable code style by automatically reformatting the code according to its predefined rules.

Some key features of Black are:

  1. Opinionated Formatting: Black follows a set of strict formatting rules known as the PEP 8 style guide. It doesn't allow any configuration or customization to its formatting rules, ensuring consistent code style across different projects.

  2. Idempotent Formatting: Black is designed to be idempotent, meaning that running it on already formatted code will not introduce any changes. This makes it safe to use as part of your codebase's automated formatting process.

  3. Intelligent Line Length Handling: Black automatically wraps code to a maximum line length of 88 characters, following PEP 8's recommendation. It uses an intelligent algorithm to determine where line breaks should occur in complex expression statements.

  4. Command Line Interface (CLI): Black provides a command line interface that allows you to format code files or entire projects with a single command. It supports various options like specifying which files or directories to format, excluding specific files, and even applying the changes directly to the source files.

  5. Editor Integrations: Black integrates well with popular code editors and IDEs, such as Visual Studio Code, PyCharm, and Sublime Text. It can be set up to automatically format code on save or execute formatting commands directly from the editor's interface.

Overall, Black simplifies the process of maintaining consistent code style across Python projects, improves code readability, and reduces the time and effort spent on manual formatting decisions.

List of commands for black:

  • black:tldr:297f7 black: Auto-format a file or entire directory.
    $ black ${filename_or_directory}
    try on your machine
    explain this command
  • black:tldr:496f2 black: Auto-format a file or directory, emitting exclusively error messages to `stderr`.
    $ black --quiet ${filename_or_directory}
    try on your machine
    explain this command
  • black:tldr:6eef6 black: Auto-format a file or directory without replacing single quotes with double quotes (adoption helper, avoid using this for new projects).
    $ black --skip-string-normalization ${filename_or_directory}
    try on your machine
    explain this command
  • black:tldr:721bf black: Output changes that would be made to a file or a directory without performing them (dry-run).
    $ black --diff ${filename_or_directory}
    try on your machine
    explain this command
  • black:tldr:80afa black: Format the code passed in as a string.
    $ black -c "${code}"
    try on your machine
    explain this command
  • black:tldr:8208e black: Output whether a file or a directory would have changes made to them if they were to be formatted.
    $ black --check ${filename_or_directory}
    try on your machine
    explain this command
tool overview