dfmt 0.3.0

Dfmt is a formatter for D source code


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

dfmt Build Status

dfmt is a formatter for D source code

Status

dfmt is beta quality. Make backups of your files or use source control when using the --inplace option.

Building

Using Make

  • Clone the repository
  • Run `git submodule update --init` in the dfmt directory
  • To compile with DMD, run `make in the dfmt directory. To compile with LDC, run make ldc instead. The generated binary will be placed in dfmt/bin/`.

Using

By default, dfmt reads its input from stdin and writes to stdout. If a file name is specified on the command line, input will be read from the file instead, and output will be written to stdout.

dfmt uses EditorConfig files for configuration. If you run dfmt on a source file it will look for .editorconfig files that apply to that source file. If no file is specified on the command line, dfmt will look for .editorconfig files that would apply to a D file in the current working directory. Command line options can be used instead of .editorconfig files, or to override options found in .editorconfig files.

Options

  • --help: Display command line options
  • --inplace: A file name is required and the file will be edited in-place.
  • --align_switch_statements: See dfmt_align_switch_statements below
  • --brace_style: See brace_style below
  • --end_of_line: See end_of_line below
  • --indent_size: See indent_size below
  • --indent_style: See indent_style below
  • --max_line_length: See max_line_length below
  • --soft_max_line_length: See dfmt_soft_max_line_length below
  • --outdent_attributes: See dfmt_outdent_attributes below
  • --outdent_labels: See dfmt_outdent_labels below
  • --space_after_cast: See dfmt_space_after_cast below
  • --split_operator_at_line_end: See dfmt_split_operator_at_line_end below
  • --tab_width: See tab_width below

Example

dfmt --inplace --space_after_cast=false --max_line_length=80 \
    --soft_max_line_length=70 --brace_style=otbs file.d

Configuration

dfmt uses EditorConfig configuration files. dfmt-specific properties are prefixed with dfmt_.

Standard EditorConfig properties

Property NameAllowed ValuesDefault ValueDescription
endoflinecr, crlf and lflfSee EditorConfig documentation.
insertfinalnewlinetrueNot supported. dfmt always inserts a final newline.
charsetUTf-8Not supported. dfmt only works correctly on UTF-8.
indent_styletab, spacespaceSee EditorConfig documentation.
indent_sizepositive integers4See EditorConfig documentation.
tab_widthpositive integers8See EditorConfig documentation.
trimtrailingwhitespacetrueNot supported. dfmt does not emit trailing whitespace.
maxlinelengthpositive integers120See EditorConfig documentation.

dfmt-specific properties

Property NameAllowed ValuesDefault ValueDescription
dfmtbracestyleallman, otbs, or stroustrupallmanSee Wikipedia
dfmtsoftmaxlinelengthpositive integers80The formatting process will usually keep lines below this length, but they may be up to maxlinelength columns long.
dfmtoutdentlabels (Not yet implemented)true, falsetrueDecrease the indentation of labels
dfmtalignswitch_statements (Not yet implemented)true, falsetrueAlign labels, cases, and defaults with their enclosing switch
dfmtoutdentattributes (Not yet implemented)true, falsetrueDecrease the indentation level of attributes
dfmtsplitoperatoratline_endtrue, falsefalsePlace operators on the end of the previous line when splitting lines
dfmtspaceafter_casttrue, falsefalseInsert space after the closing paren of a cast expression
dfmtspaceafter_keywords (Not yet implemented)true, falsetrueInsert space after if, while, foreach, etc, and before the (

Terminology

  • Braces - { and }
  • Brackets - [ and ]
  • Parenthesis / Parens - ( and )
Dependencies:
libdparse
Versions:
0.15.2 2024-Aug-21
0.15.1 2023-Jul-19
0.15.0 2023-Apr-07
0.15.0-beta.2 2023-Feb-06
0.15.0-beta.1 2022-Oct-15
Show all 61 versions
Download Stats:
  • 20 downloads today

  • 111 downloads this week

  • 645 downloads this month

  • 109822 downloads total

Score:
4.7
Short URL:
dfmt.dub.pm