Dfmt is a formatter for D source code
Go to file
Leandro Lucarella c66fea0fe5 v0.7.1
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCAAGBQJbGrPQAAoJEOPQILQNRairRBoP+wQp3KG8pBYRjYWCUYBCcNrO
 5YgjtI7aEZfjo7mp56a7aYlXHmJpd8zPwR7xC9dwkA7/WzH6Pd6Lz5rz1cZq0KS7
 b+xwv834FRcGP17t7wKh1YqC8cvaL5UxgIIWvsk8L8W8wvt5ZwWXWkWGvUHfCgsp
 yZAjODJHBqUpkVSyCoOPgK8H02iY2wLAhQz1wZDRVyst9oFmNw0bgKprzyYaJrSd
 TkZL+1NZB9emCXBhW54Rh31hBnil5X7BJYvm9gNoEy9NO30uO+M1Z+HtRqY2z/kY
 VeCbk6oIvqQbqX/gbaNDWXhnnYcNJS6T7f6kob0Iu6m0FiCeW7e0PoYit4XmlLvQ
 XuXHx3BMLDYBamMbthEBLZ7iE37df31j+wo26dEj69Ax9lye4xzKEdu7Ke7uPL1C
 DaxInqxdp5DSdzu1CJcKPKpSJbJNslKP3nDPGOEGG119ujBQihV7CfmEbzgi/Py4
 BmK2sBKheRAiPrtbvjDq/HxTMbcjDvZMhqlYur4qNOQsWdei2UfWiRgOY8CFGKdt
 qVDkl/klYAihdYLy9Kh3I3TtbDN/VyRTE+I7O80RgxKB/UYzkTZABuIycsxLhaCp
 45FtPaetBuUUNYl26TTX/tIeEov7MQnvoPidzfg2ldTcswmZV4uz1RGZ7/odxVuV
 VN3VD8zCd6he0EYxdSqH
 =p5+M
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABCAAGBQJbGrPRAAoJEOPQILQNRairLs8P/37fPm1PQIatry/RovNGzu9Q
 CwZEJJDocVz6wc5d9XJoFr5pXnkj0jHzbMd7Bw1JI3/nAnY6H79gKJnK/KJluKkx
 vI79iKmTQyjb4r2mJt9k9XPevDkQlAxFTEpkvP/uAGhqkArQlUbLV1Hp9wPf6oH3
 Qn9mrGi68/h/ENiYpcIAJAbnJj+QUDcHqZeb7c7omX5VKWK3gdl+chBqEqnOCoAm
 1cfKpKDNp3jQHr4dY72MAjYbGBwQRRqRfmwadwjydwKVd22lY4Tc2EnEKRjurlyY
 y/QczFS/0XzPG+Y4Ft11fCkiVJMi/8GJkJZFmCOHi8R49U78Pb5bNpeEbLLRBMCO
 ECMXw/G7YjmlJ1A97AobBAlmGtISNcTT/ia0cgZGEKgZhPmMxNgIIK6ooNYsuOly
 s7M9CYqZ/erH4C94XnJbvWimWbmYai0PwqVb00wOvW4d5vN0YE1Rhq/s4k0UOtnz
 wXpb0acRDVS0sL4m5dyljOBlQ8ChPeJo7+B10yjXj7SBFZ/8XgNtLF+rqQW7Fsyf
 JBgHmj/6nDij4OWa8C8pfv57oXWkMVokopvoChXOWQdiElMF7IyV2wrgAtIsQIKf
 9Sk3pX/E7a2J6cVwrNm/WwlLVWdXNX4PxcK77B7FAXFDxCKBc+fUq3L0jzrKFHAW
 rUWBbzWvK4RHkJO83l67
 =wbJ6
 -----END PGP SIGNATURE-----

Merge tag v0.7.1 into v0.8.x
v0.7.1

# gpg: Signature made Fri 08 Jun 2018 18:50:24 CEST
# gpg:                using RSA key E3D020B40D45A8AB
# gpg: Good signature from "Leandro Lucarella <leandro.lucarella@sociomantic.com>"

* tag 'v0.7.1':
  Update Windows Travis Deploy Regex (#354)
  Deploy binaries to GitHub releases (Linux/MacOS) (#348)
2018-06-08 18:50:25 +02:00
bash-completion/completions Fix pkg file to put bash-completion into the right place 2018-02-20 10:18:47 +01:00
beaver@82f8c8f6bb Add Beaver as submodule 2018-01-25 18:47:17 +01:00
libdparse@4f3c9ed645 Better formatting for UFCS chains 2018-05-09 16:06:12 +02:00
makd@d735c1df67 Build debain package using makd 2017-11-06 11:37:29 +01:00
pkg Fix pkg file to put bash-completion into the right place 2018-02-20 10:18:47 +01:00
relnotes Add ufcs formatting relnotes 2018-05-29 16:05:25 +02:00
src/dfmt Better formatting for UFCS chains 2018-05-09 16:06:12 +02:00
stdx-allocator@b7778fd6bf Update stdx alloc for future removal of std.c (#357) 2018-05-26 20:04:38 +02:00
tests Better formatting for UFCS chains 2018-05-09 16:06:12 +02:00
.editorconfig Use tabs for makefiles 2015-04-23 16:47:03 -07:00
.gitignore Add bash completion support. Fix #218 2016-01-19 20:10:15 -08:00
.gitmodules Switch to use the frozen stdx-allocator 2018-02-11 15:20:26 +01:00
.travis.sh fix #236 - Allow constraints to be indented by a single tab (#337) 2018-03-02 16:26:54 +01:00
.travis.yml Update Windows Travis Deploy Regex (#354) 2018-05-08 23:43:41 +02:00
LICENSE.txt Add license file 2015-03-20 00:50:23 -07:00
README.md fix #236 - Allow constraints to be indented by a single tab (#337) 2018-03-02 16:26:54 +01:00
appveyor.yml Remove dmd-nightly + dmd-beta from AppVeyor 2018-02-02 11:34:20 +01:00
beaver.Dockerfile Use beaver to deploy the xenial-package 2018-01-25 18:47:32 +01:00
build.bat update bat file for stdx module names 2018-02-11 20:56:46 +01:00
dub.json Update stdx alloc for future removal of std.c (#357) 2018-05-26 20:04:38 +02:00
makefile Deploy binaries to GitHub releases (Linux/MacOS) (#348) 2018-04-23 23:17:01 +02:00
release-windows.sh Deploy binaries to GitHub releases (Linux/MacOS) (#348) 2018-04-23 23:17:01 +02:00
release.sh Deploy binaries to GitHub releases (Linux/MacOS) (#348) 2018-04-23 23:17:01 +02:00

README.md

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 --recursive 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/.

Installing with DUB

> dub fetch --version='~master' dfmt && dub run dfmt -- -h

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 | -h: Display command line options
  • --inplace | -i: 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 | -t: 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
  • --single_template_constraint_indent: See dfmt_template_constraint_style below
  • --space_after_cast: See dfmt_space_after_cast below
  • --space_before_function_parameters: See dfmt_space_before_function_parameters below
  • --split_operator_at_line_end: See dfmt_split_operator_at_line_end below
  • --tab_width: See tab_width below
  • --selective_import_space: See dfmt_selective_import_space below
  • --compact_labeled_statements: See dfmt_compact_labeled_statements below
  • --template_constraint_style: See dfmt_template_constraint_style below

Example

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

Disabling formatting

Formatting can be temporarily disabled by placing the comments // dfmt off and // dfmt on around code that you do not want formatted.

void main(string[] args)
{
    bool optionOne, optionTwo, optionThree;

    // dfmt has no way of knowing that "getopt" is special, so it wraps the
    // argument list normally
	getopt(args, "optionOne", &optionOne, "optionTwo", &optionTwo, "optionThree", &optionThree);

    // dfmt off
    getopt(args,
        "optionOne", &optionOne,
        "optionTwo", &optionTwo,
        "optionThree", &optionThree);
    // dfmt on
}

Configuration

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

Standard EditorConfig properties

Property Name Allowed Values Default Value Description
end_of_line cr, crlf and lf lf See EditorConfig documentation.
insert_final_newline true Not supported. dfmt always inserts a final newline.
charset UTF-8 Not supported. dfmt only works correctly on UTF-8.
indent_style tab, space space See EditorConfig documentation.
indent_size positive integers 4 See EditorConfig documentation.
tab_width positive integers 4 See EditorConfig documentation.
trim_trailing_whitespace true Not supported. dfmt does not emit trailing whitespace.
max_line_length positive integers 120 See EditorConfig documentation.

dfmt-specific properties

Property Name Allowed Values Default Value Description
dfmt_brace_style allman, otbs, or stroustrup allman See Wikipedia
dfmt_soft_max_line_length positive integers 80 The formatting process will usually keep lines below this length, but they may be up to max_line_length columns long.
dfmt_align_switch_statements (Not yet implemented) true, false true Align labels, cases, and defaults with their enclosing switch.
dfmt_outdent_attributes (Not yet implemented) true, false true Decrease the indentation level of attributes.
dfmt_split_operator_at_line_end true, false false Place operators on the end of the previous line when splitting lines.
dfmt_space_after_cast true, false true Insert space after the closing paren of a cast expression.
dfmt_space_after_keywords (Not yet implemented) true, false true Insert space after if, while, foreach, etc, and before the (.
dfmt_space_before_function_parameters true, false false Insert space before the opening paren of a function parameter list.
dfmt_selective_import_space true, false true Insert space after the module name and before the : for selective imports.
dfmt_compact_labeled_statements true, false true Place labels on the same line as the labeled switch, for, foreach, or while statement.
dfmt_template_constraint_style conditional_newline_indent conditional_newline always_newline always_newline_indent conditional_newline_indent Control the formatting of template constraints.
dfmt_single_template_constraint_indent true, false false Set if the constraints are indented by a single tab instead of two. Has only an effect for if indentation style if set to always_newline_indent or conditional_newline_indent.

Terminology

  • Braces - { and }
  • Brackets - [ and ]
  • Parenthesis / Parens - ( and )