Compare commits

...

122 Commits

Author SHA1 Message Date
Mathis Beer aa49b9035c Tag the constructor arguments in new-anonymous-class calls as named arguments. 2025-10-09 08:25:39 +02:00
Mathis Beer 49612a48a6 Track 'new' expressions in the named argument offset list as well. 2025-09-25 23:29:13 +02:00
Mathis Beer a12e83e8a4 Avoid interpreting named args as labels when indenting newline in keep_line_breaks mode. 2025-09-25 23:29:13 +02:00
Nicholas Wilson d8e43e23ec remove explicit `nothrow` from `globMatchEditorConfig`
The in contract may throw.
2024-08-21 09:58:22 +02:00
Andrei Horodniceanu 0ea0572e86 makefile: Remove stdx-allocator from imports and sources
Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2024-05-11 20:07:03 +02:00
Andrei Horodniceanu 5ea76cd293 makefile: fix bin/dfmt-test target
Don't call the D compiler with bin/githash.txt as a source file.

Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2024-05-11 20:07:03 +02:00
Jeremy Baxter fa463b472c improve makefile
o  add 'install' target
 o  shorten the name of INCLUDE_PATHS to IMPORTS
 o  use filename prerequisities and targets rather than phony keywords
 o  add a dependency on .git/refs/tags for the githash target
 o  add githash.txt and dfmt-test to the clean target
 o  add more targets to .PHONY
2024-02-15 10:41:02 +01:00
Daniel Zuncke 2ea6c43a66 Use libdparse to check for named arg
Remove custom named arg parser
2023-10-26 20:10:50 +00:00
Daniel Zuncke 9f377100f0 Remove unnecessary tok!"comment" filter 2023-10-26 20:10:50 +00:00
Daniel Zuncke 20b8badf8c Fix issue #586 2023-10-26 20:10:50 +00:00
Daniel Zuncke 35e55bc9b2
Fix #578 ternary expressions in AA literals not properly formatted (#591) 2023-10-22 17:52:14 +09:00
Daniel Zuncke 08fe5d6855 Confirm token equality, safer loop
Using different variable to iterate to guarantee unchanged behaviour
if anything doesn't work as intended.
2023-10-18 10:22:48 +02:00
Daniel Zuncke c0452dbd11 Update test to include both known cases
I have formatted them both to look like the the individual bad output
and not like the actual output from formatting the issue0432.d file with
the current implementation. The current implementation makes it look
like a new / different problem.
2023-10-18 10:22:48 +02:00
Daniel Zuncke 876bbe33c1 Fix issue #432
Overview:
Array astInformation.structInitEndLocations is used to find index to use
in astInformation.indentInfoSortedByEndLocation.
Both are sorted, first is used to find the array index, second is
accessed at that index to get brace indentation information.

Problem:
structInitEndLocations is generated from struct initializers
exclusively while the brace information array also contains entries
for function literal initializers. Thus when function literal init(s)
are used, we get accumulating off by one errors in the second array:

match value in structInitEndLocations and take that index:
[3, 50]
    ^--> index 1

take brace indent information from that index:
[3, 15, 50]
    |   ^--> the one we want
    ^------> the one we get (function literal init)

Solution:
This guarantees that searching forward works.
While better search strategies than linear are possible, this should be
enough for any sane and most of the insane code files.
2023-10-18 10:22:48 +02:00
WebFreak001 1e765fb781 add knr test variant for no_space_after_keyword
The generator is so outdated and basic that it didn't generate this.
2023-07-26 16:13:48 +02:00
Robert Schadek c43803575d No space after keywords
Readme update

test files
2023-07-26 16:13:48 +02:00
WebFreak001 470e65f7cc bump minimum libdparse version, fix #583 2023-07-19 14:43:24 +02:00
Eugen Wissner 6f41b20d5b Remove travis 2023-05-01 23:01:54 +02:00
Razvan Nitu 49b9fe4051
Merge pull request #579 from belka-ew/bug/revert-array-indent-on-line
Keep "(" indentation with a "]" in the same line
2023-04-07 23:19:48 +08:00
Eugen Wissner fec7394175 Add reflow_property_chains option
Recalculate the splitting of property chains into multiple lines.
2023-03-29 11:29:59 +02:00
Eugen Wissner 727472c365
Keep "(" indentation with a "]" in the same line 2023-03-20 18:23:33 +01:00
WebFreak001 840aeee45e add missing test 2023-03-01 22:07:37 +01:00
WebFreak001 a91f044958 add some missing hasCurrent checks 2023-03-01 22:07:37 +01:00
Eugen Wissner dba8c87ebc Revert operator indentation in an argument list 2023-02-06 10:17:09 +01:00
Eugen Wissner a4fbc6f881 Revert chain indentation in an argument list 2023-01-15 20:51:03 +01:00
Eugen Wissner 57f57d95de Fix else indentation after array literal 2023-01-14 02:18:28 +01:00
WebFreak001 4a6078779a Fix #568, don't output empty files without error
Now when an error in formatting happens, it never outputs anything and
doesn't override the file when working inplace.

Additionally dfmt is no longer able to fail in the middle of a file, as
now we first write everything to a buffer and only if everything was
successful, that buffer is printed to stdout or written to the inplace
file.

This should also guard against segfaults with inplace file formatting
erasing parts of the file, as well as the user thinking it was
successful, even though dfmt didn't finish properly.
2022-10-15 02:33:04 +02:00
Iain Buclaw e251e4343a Remove appveyor.yml
This pipeline isn't in use anymore.
2022-10-06 21:10:01 +02:00
Iain Buclaw 02070df593 Update downloads.dlang.org links to use https 2022-10-06 21:10:01 +02:00
Andrey Proskurin 6744df20f3 Add knr brace style to README 2022-09-14 13:25:04 +02:00
Eugen Wissner 8d42254d47 Fix indentation of callchains with comments
Weird formatting and indentation of multiline callchains with comments
in the middle.
2022-08-06 08:55:43 +02:00
Bastiaan Veelo 2a4af7a2b2
Retain line ending by default. (#553) 2022-07-28 17:21:10 +02:00
Eugen Wissner 026a58e273 Very long chained calls in array literals are indented weirdly 2022-07-28 17:14:01 +02:00
Bastiaan Veelo 4947beec6b CI
Add GitHub action.
2022-07-14 23:19:37 +02:00
belka-ew d862d8aef1
Fix array literal indentation in foreach (#554) 2022-06-14 12:35:54 +00:00
skyline131313 036da91542
Update dub.json to remove dependency on `rdmd` (#547) 2022-06-13 16:23:56 +02:00
Max Haughton ed5fc2ffd2
Merge pull request #551 from veelo/d_test_script
Port `test.sh` to platform independent D.
2022-05-30 00:15:49 +01:00
Bastiaan Veelo b8da7c5cd4 Refactor courtesy WebFreak001.
Co-authored-by: Jan Jurzitza <gh@webfreak.org>
2022-05-27 19:47:47 +02:00
Bastiaan Veelo f6d9d04e43 Port `test.sh` to platform independent D.
This executes also way faster by not spawning GNU diff.
2022-05-26 16:10:07 +02:00
Bastiaan Veelo f81ddeadbd
obey `end_of_line` setting in all tokens (#550)
Multi-line tokens would be written with `LF`, regardless the `end_of_line` setting.

Fixes #228 and also produces end_of_line specified line-endings in strings.
2022-05-25 13:21:07 +02:00
Bastiaan Veelo 3e1e643972
Merge branch 'dlang-community:master' into master 2022-05-23 16:23:20 +02:00
Eugen Wissner 77e2ba4e3d Fix array indentation as argument 2022-05-23 14:09:26 +02:00
RazvanN7 6a24f0dc7c Upgrade libdparse to latest version 2022-01-26 14:05:44 +01:00
Martin Kinkelin b776d5a9b9 Fix tests 2021-10-31 20:37:32 +09:00
Razvan Nitu 2beb819851
Merge pull request #535 from dlang-community/single-indent
Add single_indent option
2021-10-22 16:22:40 +03:00
Jan Jurzitza f1e57135bb
Merge pull request #534 from dlang-community/knr_brace_style 2021-10-09 09:09:50 +02:00
Max Haughton e5e11604f0
Merge pull request #542 from belka-ew/comment-before-contract
Fix comment before contract
2021-09-07 16:46:42 +01:00
Eugen Wissner e8bd41c70d
Fix comment before contract
Fixes #451.
2021-09-07 14:29:45 +02:00
Sönke Ludwig b3b8ff1a43 Avoid possible null pointer access. 2021-08-16 18:09:57 +02:00
Amin Yahyaabadi 0e5615e13e
Fix the CLI help output about the `--config` option (#541) 2021-08-04 00:40:22 +03:00
belka-ew f6490b31c9
Format multiline arrays first (#538) 2021-06-16 17:23:27 +03:00
Eugen Wissner 995c21ab87 Format do like body after function attributes 2021-06-14 21:06:32 +00:00
Eugen Wissner 821b9be9e9 Fix double array indentation inside parens 2021-06-12 05:39:30 +00:00
Eugen Wissner ea36fbf58b
Add single_indent option 2021-05-18 06:36:57 +02:00
Sönke Ludwig 0f61586438 Add tests for "knr" brace style. 2021-04-16 13:57:59 +02:00
Sönke Ludwig e35bde0815 Add Kernighan & Ritchie style brace formatting.
The original K&R style behaves like BraceStyle.otbs, except for function definitions that use Allman style.
2021-04-16 13:57:21 +02:00
WebFreak001 e79ba9f0c8 upgrade libdparse to <0.18.0 2021-04-06 20:14:47 +02:00
Preetpal Sohal 3479e73707
Fix installation instructions on README.md (#531)
* Fix installation instructions on README.md

Fixes Issue #530.
2021-03-11 16:40:44 +02:00
Eugen Wissner 1f21a97713 Don't indent associative array keys as labels 2021-03-09 11:38:33 +01:00
Eugen Wissner c4b6a7e7e3 Don't write a space after the return attribute
Fixes #521.
2021-02-27 16:06:06 +01:00
Eugen Wissner e6199aaa9b Don't output an extra newline after a comment
with keep_line_breaks=true.

Fixes #509 and #490.
2020-10-10 07:25:27 +02:00
Brian Schott e880e00e73
Merge pull request #516 from dlang-community/issue-515
Fix #515
2020-10-07 14:14:03 -07:00
Hackerpilot 41e8c05558 Fix #515 2020-10-07 02:19:55 -07:00
Brian Schott 7659b1ae1a
Fix Issue 508 (#511)
Fix Issue 508
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-10-01 08:35:20 +02:00
Eugen Wissner eab4cac12f Regenerate line break hints after newline
Fixes #486.
2020-09-04 00:14:25 +02:00
Eugen Wissner 94351246f6 Keep line break after function attributes
Fixes #504.
2020-09-02 09:09:19 +02:00
Eugen Wissner d100c40dab Print colon in AA before identifiers 2020-08-27 09:43:25 +02:00
Eugen Wissner 58b2c6ebc6 Break line on multiline strings
Fixes #476.
2020-08-10 15:25:59 +02:00
Mathis Beer b5dbb0e031 Fix issue 483: indent continuing case statements on the same level 2020-07-22 10:27:52 +02:00
Mathis Beer e4f2f20720 Fix issue 497: insert space before function/delegate in function type that returns template instantiated with parenless value argument 2020-07-20 08:04:51 +02:00
The Dlang Bot d92a6799ac
Merge pull request #493 from WebFreak001/upgrade-libdparse
Upgrade libdparse to <0.16.0
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-06-28 08:33:28 +02:00
WebFreak001 e5eda5c14a Upgrade libdparse to <0.16.0 2020-06-24 22:26:03 +02:00
The Dlang Bot f80bffcf84
Merge pull request #491 from WebFreak001/add-minmax-libdparse
use test_with_package.d for libdparse for tests
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-06-09 23:18:25 +02:00
Jan Jurzitza ad00b113a9 use test_with_package for libdparse test
test both minimum and maximum allowed libdparse versions with dub
2020-06-08 14:21:33 +02:00
The Dlang Bot 83f8a4c65d
Merge pull request #488 from WebFreak001/fix-482
switch statement alignment is implemented fix #482
merged-on-behalf-of: Petar Kirov <PetarKirov@users.noreply.github.com>
2020-05-06 06:42:34 +02:00
Jan Jurzitza f59f25bb09 switch statement alignment is implemented fix #482 2020-05-05 14:06:55 +02:00
The Dlang Bot 09caf255e5
Merge pull request #475 from WebFreak001/fix-474
Fix #474
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-04-03 09:51:49 +02:00
Jan Jurzitza 34810aa928 Fix stuck-while TODO (this is a do-while loop) 2020-04-03 09:19:24 +02:00
Jan Jurzitza cb1dfe091f Check for token before access, fix #474 2020-04-02 13:39:29 +02:00
Jan Jurzitza 7b955c18d1 Add hasCurrent to check if a token is available 2020-04-02 13:38:02 +02:00
Jan Jurzitza 1964f807cf
Merge pull request #473 from belka-ew/break-on-this
keep_line_breaks: multi-line tokens and argument list break
2020-03-24 14:42:25 +01:00
Eugen Wissner ef83514541 keep_line_breaks: Compare with the token end line 2020-03-24 14:39:31 +01:00
Eugen Wissner 394da5d02a Fix break after comma, before this 2020-03-22 17:54:59 +01:00
The Dlang Bot 66faac49f1
Merge pull request #470 from dlang-community/issue-469
Fix Issue #469
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-03-09 10:03:20 +01:00
Hackerpilot e9034f4fec Fix return value when reading from stdin 2020-03-08 13:23:42 -07:00
Brian Schott b17304accd
Update tests/test.sh
Co-Authored-By: Jan Jurzitza <gh@webfreak.org>
2020-03-08 13:17:48 -07:00
The Dlang Bot c41c0349a2
Merge pull request #471 from belka-ew/feature/keep-line-breaks
Support disabling automatic line breaks
merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
2020-03-07 21:47:03 +01:00
Eugen Wissner 5f0d2843e6 Support disabling automatic line breaks
Support disabling automatic line breaks With --keep_line_breaks.
2020-03-07 21:14:10 +01:00
Hackerpilot 63a29ab757 Update dependency 2020-03-06 13:28:45 -08:00
Hackerpilot 2dc19b6577 Update submodule 2020-03-06 13:11:20 -08:00
Hackerpilot fbd8559ceb Test case for issue 469 2020-03-06 13:10:21 -08:00
Hackerpilot 977318214d Add check for tests that are supposed to error out, and clean up code based on shellcheck suggestions 2020-03-06 13:10:04 -08:00
Hackerpilot 4db5ba44b2 Error out on lexer failure 2020-03-06 13:09:14 -08:00
The Dlang Bot 399041c84f
Merge pull request #467 from Geod24/fix-deps
Replace 'body' with 'do'
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
2020-02-04 03:36:42 +01:00
Geod24 d38c3d96bf Replace 'body' with 'do'
The former is set to be deprecated in the next (2.091.0) DMD release.
2020-02-04 11:28:21 +09:00
Geod24 da51958770 Remove trailing whitespace 2020-02-04 11:27:58 +09:00
Eugen Wissner 27929e4cc5 Wrap the argument list of a template function
Fixes #454.
2020-01-12 22:49:16 +01:00
Eugen Wissner 0795a477f1 Put space between a comment and an identifier
Fixes #452.
2020-01-05 23:11:18 +01:00
Eugen Wissner 8f779b33bf Put a space in contract expressions
Fixes #448.
2020-01-05 20:28:56 +01:00
Sebastian Wilzbach 024c6e6a63
Merge pull request #460 from WebFreak001/fix-trivials
Fix trivial issues
2019-12-03 02:13:34 +01:00
WebFreak001 8c2076d4f2 better gen_expected script 2019-11-25 17:10:20 +01:00
WebFreak001 70bae7487e add dub build to readme fix #234 2019-11-25 17:09:51 +01:00
WebFreak001 79ae2c09d0 trivially fix #195
probably fixed in previous libdparse
2019-11-25 17:09:51 +01:00
WebFreak001 28b32d9d77 trivially fix #134
was fixed in the past
2019-11-25 17:09:51 +01:00
WebFreak001 d33b878965 fix #430 already working
resolved with previous libdparse update
2019-11-25 17:09:51 +01:00
The Dlang Bot a4d4d94a50
Merge pull request #459 from WebFreak001/libdparse-0-13-z
upgrade libdparse to 0.13.z
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
2019-11-25 16:41:20 +01:00
WebFreak001 30ab6e103d upgrade libdparse to 0.13.z 2019-11-25 16:22:13 +01:00
The Dlang Bot 3f141b272d
Merge pull request #446 from Sobaya007/fix-issue256
Fix: Issue 256 "named member struct initialisers"
merged-on-behalf-of: Jan Jurzitza <gh@webfreak.org>
2019-08-06 23:22:24 +02:00
sobaya 06881d8654 Fix: assertion message in indent manipulation of struct initializer 2019-08-04 13:05:39 +09:00
sobaya ac8e34815f Fix: Use more readable expression 2019-08-04 13:04:39 +09:00
sobaya b3946b7525 Add: Test for nested struct formatting 2019-08-03 08:55:32 +09:00
sobaya 05db8ae8fa Fix: indentation for wrapping in struct initializer 2019-08-01 17:43:45 +09:00
sobaya 81c607a115 Fix: extrace space after first field 2019-08-01 16:58:41 +09:00
sobaya 1024f16715 Add: struct fields to the test of issue 256 2019-07-30 23:04:02 +09:00
sobaya ac61efe767 Fix: Issue 256 "named member struct initialisers" 2019-07-30 13:02:48 +09:00
The Dlang Bot 4fea171d2f
Merge pull request #442 from kotet/issue-361
Fix #361
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
2019-05-14 10:41:32 +02:00
Kotet 3af8edc57f Fix #361 - Unexpected empty new line if function header ends with a comment 2019-05-14 09:00:56 +09:00
The Dlang Bot 6d2a56e15e
Merge pull request #441 from kotet/issue-426
Fix #426
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
2019-05-13 11:06:56 +02:00
Kotet f8f34ff097 Fix #426 2019-05-13 17:49:12 +09:00
The Dlang Bot 999c044020
Merge pull request #440 from kotet/issue-0433
Fix #433
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
2019-05-13 08:57:58 +02:00
Kotet 2cc1f59235 Fix #433 2019-05-13 12:13:32 +09:00
Bastiaan Veelo 5274e5531e
Merge pull request #1 from dlang-community/master
Allow comments in selective imports. (#403)
2018-10-29 12:04:52 +01:00
437 changed files with 6200 additions and 542 deletions

16
.gitattributes vendored Normal file
View File

@ -0,0 +1,16 @@
tests/issue0228.d text eol=lf
tests/allman/issue0228.d.ref text eol=crlf
tests/knr/issue0228.d.ref text eol=crlf
tests/otbs/issue0228.d.ref text eol=crlf
tests/issue0552_lf.d text eol=lf
tests/allman/issue0552_lf.d.ref text eol=lf
tests/knr/issue0552_lf.d.ref text eol=lf
tests/otbs/issue0552_lf.d.ref text eol=lf
tests/issue0552_cr.d text eol=cr
tests/allman/issue0552_cr.d.ref text eol=cr
tests/knr/issue0552_cr.d.ref text eol=cr
tests/otbs/issue0552_cr.d.ref text eol=cr
tests/issue0552_crlf.d text eol=crlf
tests/allman/issue0552_crlf.d.ref text eol=crlf
tests/knr/issue0552_crlf.d.ref text eol=crlf
tests/otbs/issue0552_crlf.d.ref text eol=crlf

34
.github/workflows/d.yml vendored Normal file
View File

@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: D
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dlang-community/setup-dlang@4c99aa991ce7d19dd3064de0a4f2f6b2f152e2d7
- name: 'Build & Test'
run: |
# Build the project, with its main file included, without unittests
dub build --compiler=$DC
# Build and run tests, as defined by `unittest` configuration
# In this mode, `mainSourceFile` is excluded and `version (unittest)` are included
# See https://dub.pm/package-format-json.html#configurations
dub test --compiler=$DC
# Run tests
cd tests && rdmd test

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "stdx-allocator"]
path = stdx-allocator
url = https://github.com/dlang-community/stdx-allocator
[submodule "d-test-utils"]
path = d-test-utils
url = https://github.com/dlang-community/d-test-utils.git

View File

@ -1,15 +0,0 @@
#!/bin/bash
set -e
if [[ $BUILD == dub ]]; then
dub build --build=release
elif [[ $DC == ldc2 ]]; then
git submodule update --init --recursive
make ldc -j2
else
git submodule update --init --recursive
make debug -j2
fi
cd tests && ./test.sh

View File

@ -1,94 +0,0 @@
sudo: false
language: d
d:
- dmd
- ldc
os:
- linux
- osx
branches:
only:
- master
- /^v\d+\.\d+\.\d+([+-]\S*)*$/
env:
- BUILD=
- BUILD=dub
script: ./.travis.sh
jobs:
include:
- stage: GitHub Release
#if: tag IS present
d: ldc-1.13.0
os: linux
script: echo "Deploying to GitHub releases ..." && ./release.sh
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.tar.gz
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
- stage: GitHub Release
#if: tag IS present
d: ldc-1.13.0
os: osx
script: echo "Deploying to GitHub releases ..." && ./release.sh
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.tar.gz
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
- stage: GitHub Release
#if: tag IS present
d: dmd
os: linux
language: generic
sudo: yes
script: echo "Deploying to GitHub releases ..." && ./release-windows.sh
addons:
apt:
packages:
- p7zip-full
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.zip
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
- stage: GitHub Release
#if: tag IS present
d: dmd
os: linux
language: generic
sudo: yes
script: echo "Deploying to GitHub releases ..." && ARCH=64 ./release-windows.sh
addons:
apt:
packages:
- p7zip-full
deploy:
provider: releases
api_key: $GH_REPO_TOKEN
file_glob: true
file: bin/dfmt-*.zip
skip_cleanup: true
on:
repo: dlang-community/dfmt
tags: true
stages:
- name: test
if: type = pull_request or (type = push and branch = master)

View File

@ -1,22 +1,28 @@
# dfmt [![Build Status](https://travis-ci.org/dlang-community/dfmt.svg?branch=master)](https://travis-ci.org/dlang-community/dfmt)
# dfmt [![Build Status](https://github.com/dlang-community/dfmt/actions/workflows/d.yml/badge.svg)](https://github.com/dlang-community/dfmt/actions?query=workflow%3A%22D%22)
**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
## Installation
### Installing with DUB
```sh
> dub run dfmt -- -h
```
### Building from source 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
```sh
> dub fetch --version='~master' dfmt && dub run dfmt -- -h
```
### Building from source using dub
* Clone the repository
* run `dub build --build=release`, optionally with `--compiler=ldc2`
## Using
By default, dfmt reads its input from **stdin** and writes to **stdout**.
@ -46,10 +52,15 @@ found there.
* `--soft_max_line_length`: *see dfmt_soft_max_line_length [below](#dfmt-specific-properties)*
* `--space_after_cast`: *see dfmt_space_after_cast [below](#dfmt-specific-properties)*
* `--space_before_aa_colon`: *see dfmt_space_before_aa_colon [below](#dfmt-specific-properties)*
* `--space_before_named_arg_colon`: *see dfmt_space_before_named_arg_colon [below](#dfmt-specific-properties)*
* `--space_before_function_parameters`: *see dfmt_space_before_function_parameters [below](#dfmt-specific-properties)*
* `--split_operator_at_line_end`: *see dfmt_split_operator_at_line_end [below](#dfmt-specific-properties)*
* `--tab_width`: *see tab_width [below](#standard-editorconfig-properties)*
* `--template_constraint_style`: *see dfmt_template_constraint_style [below](#dfmt-specific-properties)*
* `--keep_line_breaks`: *see dfmt_keep_line_breaks [below](#dfmt-specific-properties)*
* `--single_indent`: *see dfmt_single_indent [below](#dfmt-specific-properties)*
* `--reflow_property_chains`: *see dfmt_property_chains [below](#dfmt-specific-properties)*
* `--space_after_keywords`: *see dfmt_space_after_keywords [below](#dfmt-specific-properties)*
### Example
```
@ -85,7 +96,7 @@ void main(string[] args)
### Standard EditorConfig properties
Property Name | Allowed Values | Description
--------------|----------------|------------
end_of_line | `cr`, `crlf` and **`lf`** | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line)
end_of_line | `cr`, `crlf` and `lf` | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line) When not set, `dfmt` adopts the first line ending in the input.
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`** | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_style)
@ -96,9 +107,9 @@ max_line_length | positive integers (**`120`**) | [See EditorConfig documentatio
### dfmt-specific properties
Property Name | Allowed Values | Description
--------------|----------------|------------
dfmt_brace_style | **`allman`**, `otbs`, or `stroustrup` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style)
dfmt_brace_style | **`allman`**, `otbs`, `stroustrup` or `knr` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style)
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` | Align labels, cases, and defaults with their enclosing switch.
dfmt_align_switch_statements | **`true`**, `false` | Align labels, cases, and defaults with their enclosing switch.
dfmt_outdent_attributes (Not yet implemented) | **`true`**, `false`| Decrease the indentation level of attributes.
dfmt_split_operator_at_line_end | `true`, **`false`** | Place operators on the end of the previous line when splitting lines.
dfmt_space_after_cast | **`true`**, `false` | Insert space after the closing paren of a `cast` expression.
@ -109,6 +120,11 @@ dfmt_compact_labeled_statements | **`true`**, `false` | Place labels on the same
dfmt_template_constraint_style | **`conditional_newline_indent`** `conditional_newline` `always_newline` `always_newline_indent` | Control the formatting of template constraints.
dfmt_single_template_constraint_indent | `true`, **`false`** | Set if the constraints are indented by a single tab instead of two. Has only an effect if the style set to `always_newline_indent` or `conditional_newline_indent`.
dfmt_space_before_aa_colon | `true`, **`false`** | Adds a space after an associative array key before the `:` like in older dfmt versions.
dfmt_space_before_named_arg_colon | `true`, **`false`** | Adds a space after a named function argument or named struct constructor argument before the `:`.
dfmt_keep_line_breaks | `true`, **`false`** | Keep existing line breaks if these don't violate other formatting rules.
dfmt_single_indent | `true`, **`false`** | Set if the code in parens is indented by a single tab instead of two.
dfmt_reflow_property_chains | **`true`**, `false` | Recalculate the splitting of property chains into multiple lines.
dfmt_space_after_keywords | **`true`**, `false` | Insert space after keywords (if,while,foreach,for, etc.).
## Terminology
* Braces - `{` and `}`

View File

@ -1,112 +0,0 @@
platform: x64
environment:
matrix:
- DC: dmd
DVersion: stable
arch: x64
- DC: dmd
DVersion: stable
arch: x86
# - DC: ldc
# DVersion: beta
# arch: x86
# - DC: ldc
# DVersion: beta
# arch: x64
# - DC: ldc
# DVersion: stable
# arch: x86
# - DC: ldc
# DVersion: stable
# arch: x64
skip_tags: false
branches:
only:
- master
- /^v\d+\.\d+\.\d+([+-]\S*)*$/
install:
- ps: function ResolveLatestDMD
{
$version = $env:DVersion;
if($version -eq "stable") {
$latest = (Invoke-WebRequest "http://downloads.dlang.org/releases/LATEST").toString();
$url = "http://downloads.dlang.org/releases/2.x/$($latest)/dmd.$($latest).windows.7z";
}elseif($version -eq "beta") {
$latest = (Invoke-WebRequest "http://downloads.dlang.org/pre-releases/LATEST").toString();
$latestVersion = $latest.split("-")[0].split("~")[0];
$url = "http://downloads.dlang.org/pre-releases/2.x/$($latestVersion)/dmd.$($latest).windows.7z";
}elseif($version -eq "nightly") {
$url = "http://nightlies.dlang.org/dmd-master-2017-05-20/dmd.master.windows.7z"
}else {
$url = "http://downloads.dlang.org/releases/2.x/$($version)/dmd.$($version).windows.7z";
}
$env:PATH += ";C:\dmd2\windows\bin;";
return $url;
}
- ps: function ResolveLatestLDC
{
$version = $env:DVersion;
if($version -eq "stable") {
$latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST").toString().replace("`n","").replace("`r","");
$url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-win64-msvc.zip";
}elseif($version -eq "beta") {
$latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST_BETA").toString().replace("`n","").replace("`r","");
$url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-win64-msvc.zip";
} else {
$latest = $version;
$url = "https://github.com/ldc-developers/ldc/releases/download/v$($version)/ldc2-$($version)-win64-msvc.zip";
}
$env:PATH += ";C:\ldc2-$($latest)-win64-msvc\bin";
$env:DC = "ldc2";
return $url;
}
- ps: function SetUpDCompiler
{
$env:toolchain = "msvc";
if($env:DC -eq "dmd"){
echo "downloading ...";
$url = ResolveLatestDMD;
echo $url;
Invoke-WebRequest $url -OutFile "c:\dmd.7z";
echo "finished.";
pushd c:\\;
7z x dmd.7z > $null;
popd;
}
elseif($env:DC -eq "ldc"){
echo "downloading ...";
$url = ResolveLatestLDC;
echo $url;
Invoke-WebRequest $url -OutFile "c:\ldc.zip";
echo "finished.";
pushd c:\\;
7z x ldc.zip > $null;
popd;
}
}
- ps: SetUpDCompiler
build_script:
- ps: if($env:arch -eq "x86"){
$env:compilersetupargs = "x86";
$env:Darch = "x86";
$env:DConf = "m32";
}elseif($env:arch -eq "x64"){
$env:compilersetupargs = "amd64";
$env:Darch = "x86_64";
$env:DConf = "m64";
}
- ps: $env:compilersetup = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall";
- '"%compilersetup%" %compilersetupargs%'
test_script:
- echo %PLATFORM%
- echo %Darch%
- echo %DC%
- echo %PATH%
- '%DC% --version'
- dub test --arch=%Darch% --compiler=%DC%
- git submodule update --init --recursive
- build.bat

View File

@ -24,7 +24,7 @@ _dfmt()
eolOpts="lf cr crlf"
boolOpts="true false"
braceOpts="allman otbs stroustrup"
braceOpts="allman otbs stroustrup knr"
indentOpts="tab space"
constraintOpts="conditional_newline_indent conditional_newline always_newline always_newline_indent"

1
d-test-utils Submodule

@ -0,0 +1 @@
Subproject commit 206a2e6abd97b4462f3a320e4f2d23986fad3cff

View File

@ -4,7 +4,7 @@
"targetType": "autodetect",
"license": "BSL-1.0",
"dependencies": {
"libdparse": "~>0.11.4"
"libdparse": ">=0.19.2 <1.0.0"
},
"targetPath" : "bin/",
"targetName" : "dfmt",
@ -14,7 +14,7 @@
"versions" : [
"built_with_dub"
],
"preGenerateCommands" : [
"rdmd \"$PACKAGE_DIR/dubhash.d\""
"preBuildCommands" : [
"$DC -run \"$PACKAGE_DIR/dubhash.d\""
]
}

@ -1 +1 @@
Subproject commit aae371931a99027465952cd6fdaede4eb4743e76
Subproject commit fe6d1e38fb4fc04323170389cfec67ed7fd4e24a

View File

@ -1,53 +1,63 @@
PREFIX = /usr/local
SRC := $(shell find src -name "*.d") \
$(shell find libdparse/src -name "*.d") \
$(shell find stdx-allocator/source -name "*.d")
INCLUDE_PATHS := -Ilibdparse/src -Istdx-allocator/source -Isrc -Jbin
DMD_COMMON_FLAGS := -dip25 -w $(INCLUDE_PATHS)
DMD_DEBUG_FLAGS := -debug -g $(DMD_COMMON_FLAGS)
DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS)
DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS)
LDC_FLAGS := -g -w -oq $(INCLUDE_PATHS)
GDC_FLAGS := -g -w -oq $(INCLUDE_PATHS)
override DMD_FLAGS += $(DFLAGS)
override LDC_FLAGS += $(DFLAGS)
override GDC_FLAGS += $(DFLAGS)
$(shell find libdparse/src -name "*.d")
IMPORTS := -Ilibdparse/src -Isrc -Jbin
DC ?= dmd
LDC ?= ldc2
GDC ?= gdc
.PHONY: dmd ldc gdc test
DMD_COMMON_FLAGS := -w $(IMPORTS)
DMD_DEBUG_FLAGS := -debug -g $(DMD_COMMON_FLAGS)
DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS)
DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS)
LDC_FLAGS := -g -w -oq $(IMPORTS)
GDC_FLAGS := -g -w -oq $(IMPORTS)
override DMD_FLAGS += $(DFLAGS)
override LDC_FLAGS += $(DFLAGS)
override GDC_FLAGS += $(DFLAGS)
dmd: bin/dfmt
.PHONY: all clean install debug dmd ldc gdc pkg release test
githash:
all: bin/dfmt
bin/githash.txt:
mkdir -p bin
git describe --tags > bin/githash.txt
ldc: githash
dmd: bin/dfmt
ldc: bin/githash.txt
$(LDC) $(SRC) $(LDC_FLAGS) -ofbin/dfmt
-rm -f *.o
gdc:githash
gdc: bin/githash.txt
$(GDC) $(SRC) $(GDC_FLAGS) -obin/dfmt
test: debug
cd tests && ./test.sh
cd tests && ./test.d
bin/dfmt-test: githash $(SRC)
$(DC) $(DMD_TEST_FLAGS) $^ -of$@
bin/dfmt-test: bin/githash.txt $(SRC)
$(DC) $(DMD_TEST_FLAGS) $(filter %.d,$^) -of$@
bin/dfmt: githash $(SRC)
bin/dfmt: bin/githash.txt $(SRC)
$(DC) $(DMD_FLAGS) $(filter %.d,$^) -of$@
debug: githash $(SRC)
debug: bin/githash.txt $(SRC)
$(DC) $(DMD_DEBUG_FLAGS) $(filter %.d,$^) -ofbin/dfmt
pkg: dmd
$(MAKE) -f makd/Makd.mak pkg
clean:
$(RM) bin/dfmt
$(RM) bin/dfmt bin/dfmt-test bin/githash.txt
install:
chmod +x bin/dfmt
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f bin/dfmt $(DESTDIR)$(PREFIX)/bin/dfmt
release:
./release.sh
githash
$(MAKE) bin/githash.txt

View File

@ -23,6 +23,12 @@ struct BraceIndentInfo
uint beginIndentLevel;
}
struct StructInitializerInfo
{
size_t startLocation;
size_t endLocation;
}
/// AST information that is needed by the formatter.
struct ASTInformation
{
@ -53,8 +59,12 @@ struct ASTInformation
sort(sharedStaticConstructorDestructorLocations);
sort!((a,b) => a.endLocation < b.endLocation)
(indentInfoSortedByEndLocation);
sort!((a,b) => a.endLocation < b.endLocation)
(structInfoSortedByEndLocation);
sort(ufcsHintLocations);
ufcsHintLocations = ufcsHintLocations.uniq().array();
sort(ternaryColonLocations);
sort(namedArgumentColonLocations);
}
/// Locations of end braces for struct bodies
@ -87,6 +97,12 @@ struct ASTInformation
/// Closing braces of function literals
size_t[] funLitEndLocations;
/// Locations of aggregate bodies (struct, class, union)
size_t[] aggregateBodyLocations;
/// Locations of function bodies
size_t[] funBodyLocations;
/// Conditional statements that have matching "else" statements
size_t[] conditionalWithElseLocations;
@ -118,6 +134,15 @@ struct ASTInformation
size_t[] ufcsHintLocations;
BraceIndentInfo[] indentInfoSortedByEndLocation;
/// Opening & closing braces of struct initializers
StructInitializerInfo[] structInfoSortedByEndLocation;
/// Locations ternary expression colons.
size_t[] ternaryColonLocations;
/// Locations of named arguments of function call or struct constructor.
size_t[] namedArgumentColonLocations;
}
/// Collects information from the AST that is useful for the formatter
@ -189,6 +214,18 @@ final class FormatVisitor : ASTVisitor
destructor.accept(this);
}
override void visit (const FunctionBody functionBody)
{
if (auto bd = functionBody.specifiedFunctionBody)
{
if (bd.blockStatement)
{
astInformation.funBodyLocations ~= bd.blockStatement.startLocation;
}
}
functionBody.accept(this);
}
override void visit(const ConditionalDeclaration dec)
{
if (dec.hasElse)
@ -272,6 +309,8 @@ final class FormatVisitor : ASTVisitor
{
astInformation.structInitStartLocations ~= structInitializer.startLocation;
astInformation.structInitEndLocations ~= structInitializer.endLocation;
astInformation.structInfoSortedByEndLocation ~=
StructInitializerInfo(structInitializer.startLocation, structInitializer.endLocation);
astInformation.indentInfoSortedByEndLocation ~=
BraceIndentInfo(structInitializer.startLocation, structInitializer.endLocation);
@ -300,6 +339,7 @@ final class FormatVisitor : ASTVisitor
override void visit(const StructBody structBody)
{
astInformation.aggregateBodyLocations ~= structBody.startLocation;
astInformation.doubleNewlineLocations ~= structBody.endLocation;
structBody.accept(this);
}
@ -406,6 +446,58 @@ final class FormatVisitor : ASTVisitor
outStatement.accept(this);
}
override void visit(const TernaryExpression ternaryExpression)
{
astInformation.ternaryColonLocations ~= ternaryExpression.colon.index;
ternaryExpression.accept(this);
}
override void visit(const FunctionCallExpression functionCall)
{
visit(functionCall.arguments);
functionCall.accept(this);
}
override void visit(const NewExpression newCall)
{
visit(newCall.arguments);
newCall.accept(this);
}
override void visit(const NewAnonClassExpression newAnonClassCall)
{
visit(newAnonClassCall.constructorArguments);
newAnonClassCall.accept(this);
}
private void visit(const Arguments arguments)
{
// Check if call has any arguments.
if (!arguments || arguments.namedArgumentList is null)
{
return;
}
foreach (item; arguments.namedArgumentList.items)
{
// Do nothing if not a named argument.
if (item.name == tok!"")
{
continue;
}
// Find first colon if named argument.
foreach (t; item.tokens)
{
if (t.type == tok!":")
{
astInformation.namedArgumentColonLocations ~= t.index;
break;
}
}
}
}
private:
ASTInformation* astInformation;
}

View File

@ -10,18 +10,20 @@ import dfmt.editorconfig;
/// Brace styles
enum BraceStyle
{
unspecified,
_unspecified,
/// $(LINK https://en.wikipedia.org/wiki/Indent_style#Allman_style)
allman,
/// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)
otbs,
/// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_Stroustrup)
stroustrup
stroustrup,
/// $(LINK https://en.wikipedia.org/wiki/Indentation_style#K&R_style)
knr,
}
enum TemplateConstraintStyle
{
unspecified,
_unspecified,
conditional_newline_indent,
conditional_newline,
always_newline,
@ -57,6 +59,16 @@ struct Config
OptionalBoolean dfmt_single_template_constraint_indent;
///
OptionalBoolean dfmt_space_before_aa_colon;
///
OptionalBoolean dfmt_keep_line_breaks;
///
OptionalBoolean dfmt_single_indent;
///
OptionalBoolean dfmt_reflow_property_chains;
///
OptionalBoolean dfmt_space_after_statement_keyword;
///
OptionalBoolean dfmt_space_before_named_arg_colon;
mixin StandardEditorConfigFields;
@ -67,7 +79,7 @@ struct Config
void initializeWithDefaults()
{
pattern = "*.d";
end_of_line = EOL.lf;
end_of_line = EOL._default;
indent_style = IndentStyle.space;
indent_size = 4;
tab_width = 4;
@ -85,6 +97,10 @@ struct Config
dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent;
dfmt_single_template_constraint_indent = OptionalBoolean.f;
dfmt_space_before_aa_colon = OptionalBoolean.f;
dfmt_keep_line_breaks = OptionalBoolean.f;
dfmt_single_indent = OptionalBoolean.f;
dfmt_reflow_property_chains = OptionalBoolean.t;
dfmt_space_before_named_arg_colon = OptionalBoolean.f;
}
/**

View File

@ -26,21 +26,22 @@ private auto commentRe = ctRegex!(`^\s*[#;].*$`);
enum OptionalBoolean : ubyte
{
unspecified = 3,
_unspecified = 3,
t = 1,
f = 0
}
enum IndentStyle : ubyte
{
unspecified,
_unspecified,
tab,
space
}
enum EOL : ubyte
{
unspecified,
_unspecified,
_default,
lf,
cr,
crlf
@ -74,7 +75,7 @@ mixin template StandardEditorConfigFields()
static if (N == "pattern")
continue;
else static if (is(T == enum))
*thisN = otherN != T.unspecified ? otherN : *thisN;
*thisN = otherN != T._unspecified ? otherN : *thisN;
else static if (is(T == int))
*thisN = otherN != -1 ? otherN : *thisN;
else static if (is(T == string))

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ import std.path : filenameCharCmp, isDirSeparator;
// * changes meaning to match all characters except '/'
// ** added to take over the old meaning of *
bool globMatchEditorConfig(CaseSensitive cs = CaseSensitive.osDefault, C, Range)(
Range path, const(C)[] pattern) @safe pure nothrow
Range path, const(C)[] pattern) @safe pure
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range)
&& isSomeChar!C && is(Unqual!C == Unqual!(ElementEncodingType!Range)))
in
@ -23,7 +23,7 @@ in
assert(balancedParens(pattern, '[', ']', 0));
assert(balancedParens(pattern, '{', '}', 0));
}
body
do
{
alias RC = Unqual!(ElementEncodingType!Range);

View File

@ -5,6 +5,8 @@
module dfmt.indentation;
import dfmt.config;
import dfmt.editorconfig;
import dparse.lexer;
import std.bitmanip : bitfields;
@ -31,6 +33,14 @@ bool isTempIndent(IdType type) pure nothrow @nogc @safe
*/
struct IndentStack
{
/// Configuration
private const Config* config;
this(const Config* config)
{
this.config = config;
}
static struct Details
{
mixin(bitfields!(
@ -221,7 +231,7 @@ struct IndentStack
/**
* Dumps the current state of the indentation stack to `stderr`. Used for debugging.
*/
void dump(size_t pos = size_t.max, string file = __FILE__, uint line = __LINE__)
void dump(size_t pos = size_t.max, string file = __FILE__, uint line = __LINE__) const
{
import dparse.lexer : str;
import std.algorithm.iteration : map;
@ -260,8 +270,20 @@ private:
if (i + 1 < index)
{
if (config.dfmt_single_indent == OptionalBoolean.t && skipDoubleIndent(i, parenCount))
{
parenCount = pc;
continue;
}
immutable currentIsNonWrapTemp = !details[i].wrap
&& details[i].temp && arr[i] != tok!")" && arr[i] != tok!"!";
if (currentIsNonWrapTemp && arr[i + 1] == tok!"]")
{
parenCount = pc;
continue;
}
if (arr[i] == tok!"static"
&& arr[i + 1].among!(tok!"if", tok!"else", tok!"foreach", tok!"foreach_reverse")
&& (i + 2 >= index || arr[i + 2] != tok!"{"))
@ -276,7 +298,7 @@ private:
continue;
}
}
else if (parenCount == 0 && arr[i] == tok!"(")
else if (parenCount == 0 && arr[i] == tok!"(" && config.dfmt_single_indent == OptionalBoolean.f)
size++;
if (arr[i] == tok!"!")
@ -287,6 +309,12 @@ private:
}
return size;
}
bool skipDoubleIndent(size_t i, int parenCount) const pure nothrow @safe @nogc
{
return (details[i + 1].wrap && arr[i] == tok!")")
|| (parenCount == 0 && arr[i + 1] == tok!"," && arr[i] == tok!"(");
}
}
unittest

View File

@ -38,13 +38,13 @@ version (NoMain)
}
else
{
import std.array : front, popFront;
import std.stdio : stdout, stdin, stderr, writeln, File;
import dfmt.config : Config;
import dfmt.formatter : format;
import std.path : buildPath, dirName, expandTilde;
import dfmt.editorconfig : getConfigFor;
import dfmt.formatter : format;
import std.array : appender, front, popFront;
import std.getopt : getopt, GetOptException;
import std.path : buildPath, dirName, expandTilde;
import std.stdio : File, stderr, stdin, stdout, writeln;
int main(string[] args)
{
@ -92,6 +92,21 @@ else
case "space_before_aa_colon":
optConfig.dfmt_space_before_aa_colon = optVal;
break;
case "space_before_named_arg_colon":
optConfig.dfmt_space_before_named_arg_colon = optVal;
break;
case "keep_line_breaks":
optConfig.dfmt_keep_line_breaks = optVal;
break;
case "single_indent":
optConfig.dfmt_single_indent = optVal;
break;
case "reflow_property_chains":
optConfig.dfmt_reflow_property_chains = optVal;
break;
case "space_after_keywords":
optConfig.dfmt_space_after_keywords = optVal;
break;
default:
assert(false, "Invalid command-line switch");
}
@ -114,14 +129,19 @@ else
"soft_max_line_length", &optConfig.dfmt_soft_max_line_length,
"outdent_attributes", &handleBooleans,
"space_after_cast", &handleBooleans,
"space_after_keywords", &handleBooleans,
"selective_import_space", &handleBooleans,
"space_before_function_parameters", &handleBooleans,
"split_operator_at_line_end", &handleBooleans,
"compact_labeled_statements", &handleBooleans,
"single_template_constraint_indent", &handleBooleans,
"space_before_aa_colon", &handleBooleans,
"space_before_named_arg_colon", &handleBooleans,
"tab_width", &optConfig.tab_width,
"template_constraint_style", &optConfig.dfmt_template_constraint_style);
"template_constraint_style", &optConfig.dfmt_template_constraint_style,
"keep_line_breaks", &handleBooleans,
"single_indent", &handleBooleans,
"reflow_property_chains", &handleBooleans);
// dfmt on
}
catch (GetOptException e)
@ -145,14 +165,13 @@ else
args.popFront();
immutable bool readFromStdin = args.length == 0;
File output = stdout;
version (Windows)
{
// On Windows, set stdout to binary mode (needed for correct EOL writing)
// See Phobos' stdio.File.rawWrite
{
import std.stdio : _O_BINARY;
immutable fd = output.fileno;
immutable fd = stdout.fileno;
_setmode(fd, _O_BINARY);
version (CRuntime_DigitalMars)
{
@ -173,7 +192,7 @@ else
if (!exists(explicitConfigDir) || !isDir(explicitConfigDir))
{
stderr.writeln("--config_dir|c must specify existing directory path");
stderr.writeln("--config|c must specify existing directory path");
return 1;
}
explicitConfig = getConfigFor!Config(explicitConfigDir);
@ -211,7 +230,9 @@ else
else
break;
}
format("stdin", buffer, output.lockingTextWriter(), &config);
immutable bool formatSuccess = format("stdin", buffer,
stdout.lockingTextWriter(), &config);
return formatSuccess ? 0 : 1;
}
else
{
@ -219,6 +240,7 @@ else
if (args.length >= 2)
inplace = true;
int retVal;
while (args.length > 0)
{
const path = args.front;
@ -251,13 +273,21 @@ else
{
buffer = new ubyte[](cast(size_t) f.size);
f.rawRead(buffer);
auto output = appender!string;
immutable bool formatSuccess = format(path, buffer, output, &config);
if (formatSuccess)
{
if (inplace)
output = File(path, "wb");
format(path, buffer, output.lockingTextWriter(), &config);
File(path, "wb").rawWrite(output.data);
else
stdout.rawWrite(output.data);
}
else
retVal = 1;
}
}
return retVal;
}
return 0;
}
}
@ -276,12 +306,14 @@ private version (Windows)
template optionsToString(E) if (is(E == enum))
{
import std.algorithm.searching : startsWith;
enum optionsToString = () {
string result = "(";
foreach (s; [__traits(allMembers, E)])
{
if (s != "unspecified")
if (!s.startsWith("_"))
result ~= s ~ "|";
}
result = result[0 .. $ - 1] ~ ")";
@ -297,7 +329,7 @@ https://github.com/dlang-community/dfmt
Options:
--help, -h Print this help message
--inplace, -i Edit files in place
--config_dir, -c Path to directory to load .editorconfig file from.
--config, -c Path to directory to load .editorconfig file from.
--version Print the version number and then exit
Formatting Options:
@ -308,17 +340,22 @@ Formatting Options:
--indent_size
--indent_style, -t `,
optionsToString!(typeof(Config.indent_style)), `
--keep_line_breaks
--soft_max_line_length
--max_line_length
--outdent_attributes
--space_after_cast
--space_before_function_parameters
--space_after_keywords
--selective_import_space
--single_template_constraint_indent
--split_operator_at_line_end
--compact_labeled_statements
--template_constraint_style
--space_before_aa_colon
--space_before_named_arg_colon
--single_indent
--reflow_property_chains
`,
optionsToString!(typeof(Config.dfmt_template_constraint_style)));
}

View File

@ -15,7 +15,7 @@ in
{
assert(tokens[0].type == tok!"(");
}
body
do
{
uint length = 0;
size_t i = 1;

View File

@ -172,9 +172,6 @@ size_t[] chooseLineBreakTokens(size_t index, const Token[] tokens,
void validMoves(OR)(auto ref OR output, const Token[] tokens, immutable short[] depths,
uint current, const Config* config, int currentLineLength, int indentLevel)
{
import std.algorithm : sort, canFind, min;
import std.array : insertInPlace;
foreach (i, token; tokens)
{
if (!isBreakToken(token.type) || (((1 << i) & current) != 0))

View File

@ -0,0 +1,23 @@
class C
{
void f()
{
if (true)
{
f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map
.map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__);
g(map && map && map && map && map && map && map && map && map && map && map
&& map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __LINE__);
h(map || map || map || map || map || map || map || map || map || map || map
|| map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __LINE__);
i(map + map + map + map + map + map + map + map + map + map + map + map + map
+ map + map + map + map + map, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __FILE__, __FILE__, __LINE__);
}
}
}

View File

@ -0,0 +1,31 @@
class C
{
void f()
{
if (true)
{
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
g(
map &&
map,
__FILE__,
__LINE__);
h(
map ||
map,
__FILE__,
__LINE__);
i(
map
+ map,
__FILE__,
__LINE__);
}
}
}

View File

@ -1,7 +1,7 @@
unittest
{
foo([
target.value.region[1], target.value.region[1],
target.value.region[1], target.value.region[1], target.value.region[1]
target.value.region[1], target.value.region[1], target.value.region[1],
target.value.region[1], target.value.region[1]
]);
}

View File

@ -0,0 +1,8 @@
void main()
{
string key;
int[string] var = [
key: 5
];
}

View File

@ -7,8 +7,8 @@ unittest
]),
"short": Bson(["a": "b", "c": "d"]),
"numbers": Bson([
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
3, 4, 5, 6, 7, 8, 9, 0
]),
"shuffleOnReset": serializeToBson([
"all": false,

View File

@ -13,8 +13,8 @@ do
}
int bar(int arg)
in(arg > 0)
out(; true)
in (arg > 0)
out (; true)
out /*Major*/ ( /*Tom*/ result /*To ground control*/ ; result == 0)
{
return 0;

View File

@ -0,0 +1,54 @@
static foreach (x; [
1,
2,
3,
])
{
}
static foreach_reverse (x; [
1,
2,
3,
])
{
}
void f()
{
foreach (x; [
1,
2,
3,
])
{
}
foreach_reverse (x; [
1,
2,
3,
])
{
}
if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri))
{
send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, [
]));
}
foreach (x; map([
1,
2,
3,
]))
{
}
foreach (x; foo!(map!([
1,
2,
3,
])))
{
}
}

View File

@ -0,0 +1 @@
alias u8 = ubyte

View File

@ -0,0 +1,15 @@
void foo()
{
string command;
version (Posix)
command ~= " 2> /dev/null 1> /dev/null";
version (Posix)
command ~= " 2> /dev/null 1> /dev/null";
unittest
{
version (Posix)
command ~= " 2> /dev/null 1> /dev/null";
}
}

View File

@ -0,0 +1,16 @@
void main()
{
auto myTid = runTask({
auto conn = connectTCP("localhost", 4222);
auto l = Lexer(conn);
foreach (t; l)
{
}
conn.close();
});
// foo
runEventLoop();
}

View File

@ -0,0 +1,8 @@
/* This test relies on ../.gitattributes to contain these lines:
tests/issue0228.d text eol=lf
tests/allman/issue0228.d.ref text eol=crlf
tests/knr/issue0228.d.ref text eol=crlf
tests/otbs/issue0228.d.ref text eol=crlf
*/

View File

@ -0,0 +1,11 @@
void main()
{
S s1 = {a: 3};
S s2 = {a: 3, b: "test string"};
S s3 = {a: 3, b: "test string", c: {x: 3.14, y: 3 + 4}};
T t = {
someStructMember1: 2, someStructMember2: 42, someStructMember3: null, // foobar
someOtherMember1: objA, someOtherMember2: objB, someOtherMember3: 0,
somethingMore: null, someFlagInThisStruct: -1
};
}

View File

@ -0,0 +1,15 @@
void foo() /**/
in
{
}
body
{
}
void bar() /**/
out
{
}
body
{
}

View File

@ -0,0 +1,6 @@
import std.stdio;
@safe extern (C) void main()
{
writeln("Hello World!");
}

View File

@ -0,0 +1,6 @@
void f(bool body)
{
if (body)
{
}
}

View File

@ -0,0 +1,40 @@
struct S1
{
ulong x;
ulong y;
ulong function(ulong) f;
}
struct S2
{
ulong x;
ulong y;
ulong z;
ulong w;
}
// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer
immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },
};
void f1()
{
}
// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer
int function(int) f2 = (x) { return x + 1111; };
immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,
};
void f2()
{
}

View File

@ -0,0 +1,7 @@
int abs(int x)
{
if (x < 0) // x negative, must negate
return -x;
else // x already non-negative, just return it
return x;
}

View File

@ -0,0 +1,4 @@
struct S
{
invariant (true);
}

View File

@ -0,0 +1,40 @@
class C
{
abstract void f1() //
in (true);
abstract void f2() /* */
in (true);
abstract bool f3() //
out (r; r);
abstract bool f4() /* */
out (r; r);
abstract void f5() //
do
{
}
abstract void f6() /* */
do
{
}
abstract bool f7() //
in (true) //
out (r; r) //
do //
{
return true;
}
abstract bool f8() /* */
in (true) /* */
out (r; r) /* */
do /* */
{
return true;
}
}

View File

@ -0,0 +1,2 @@
@nogc //
void foo();

View File

@ -0,0 +1,10 @@
void main()
{
format!"%s" //
("");
format!("%s") //
("");
format!("%s") //
("", argument1, argument2, argument3, argument4, argument5,
argument6, argument7, argument8, argument9, argument10);
}

View File

@ -0,0 +1,8 @@
bool asdf(const string owner, const string mail) @safe
{
requestHTTP(url, (scope HTTPClientRequest request) {
request.writeFormBody([owner: owner, mail: mail]);
}, (scope HTTPClientResponse response) {});
return true;
}

View File

@ -0,0 +1,7 @@
string BuildForwardCall()
{
return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `)))
{
return (mocked___.` ~ methodString ~ argsPassed ~ `);
}`;
}

View File

@ -0,0 +1,15 @@
module tests.issue0483;
void main()
{
switch (0)
{
case 1:
case 2:
label:
case 3:
break;
default:
break;
}
}

View File

@ -0,0 +1,5 @@
void main()
{
int a;
int[int] hashmap = [a : a, a : a, a : a];
}

View File

@ -0,0 +1,5 @@
void main()
{
auto someAutoVariableName = this.firstLink.secondLink
.filter!(shouldBeProbablySomeIdentifierOrNot);
}

View File

@ -0,0 +1,29 @@
void main()
{
const a1 = [
builder.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];
const a2 = [
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];
foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}
void foo()
{
afdsafds.asdf.flub;
}

View File

@ -0,0 +1,74 @@
private void selectMember(Args...)(Args args)
{
static if (true)
{
static if (args[0])
{
}
else
{
}
}
if (true)
{
if (args[0])
{
}
else
{
}
}
}
private void selectMember(Args...)(Args args)
{
static if (true)
{
static if ([
0,
1,
2,
3,
4,
])
{
}
else
{
}
}
if (true)
{
if (args[
0,
1,
2,
3,
4,
])
{
}
else
{
}
}
}
void f()
{
foreach (x; y)
if (foo)
{
}
else
{
}
if (a)
if (b)
{
}
else
{
}
}

View File

@ -0,0 +1,34 @@
void main()
{
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];
const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];
foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}
void foo()
{
afdsafds
.asdf
.flub;
}

View File

@ -0,0 +1,5 @@
alias f1 = S function();
alias f2 = S!"foo" function();
alias f3 = S!5 function();
alias f4 = S!S function();
alias f5 = S!(S) function();

View File

@ -0,0 +1,4 @@
void main()
{
auto aa = ["aaa": 1, "bbb": 2];
}

View File

@ -0,0 +1,15 @@
string f()
{
return duration.total!"seconds".to!string;
}
string g()
{
return duration.total!"seconds"().to!string;
}
string h()
{
return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string
.to!string.to!string.to!string;
}

View File

@ -0,0 +1,40 @@
deprecated("foo")
void test()
{
}
package(foo)
void bar()
{
}
@uda()
void baz()
{
}
deprecated
deprecated_()
{
}
@uda
void uda_()
{
}
@property
void property()
{
}
deprecated("Reason") @uda
void propertyuda()
{
}
deprecated("Reason")
@uda
void udaproperty()
{
}

View File

@ -0,0 +1,7 @@
struct S
{
@safe invariant
{
assert(true);
}
}

View File

@ -0,0 +1,34 @@
void main()
{
string a = "foo"
~ "bar" // bar
~ "baz";
}
void foo()
{
afdsafds
.asdf // blah
.flub;
}
void main()
{
string a = "foo"
~ "bar" /* bar */
~ "baz";
}
void foo()
{
afdsafds
.asdf /* blah */
.flub;
}
void foo() // hello
{ // world
// ok
writeln("hi"); // hi!
} // done
//finish

View File

@ -0,0 +1,7 @@
struct S
{
ref S foo() return
{
return this;
}
}

View File

@ -0,0 +1,17 @@
public int f() return
in (true)
{
return 0;
}
public int g() return
out (; true)
{
return 0;
}
public int h() return
body
{
return 0;
}

View File

@ -0,0 +1,4 @@
void f() return
do
{
}

View File

@ -0,0 +1 @@
/// Testing CR line endings. void main() { }

View File

@ -0,0 +1,4 @@
/// Testing CRLF line endings.
void main()
{
}

View File

@ -0,0 +1,4 @@
/// Testing LF line endings.
void main()
{
}

View File

@ -0,0 +1,8 @@
void f()
{
auto t = true ? 1 : 0;
auto a = [true ? 1 : 0];
auto aa1 = [0: true ? 1 : 0];
auto aa2 = [0: true ? (false ? 1 : 2) : 3];
auto aa3 = [0: true ? false ? 1 : 2 : 3];
}

View File

@ -0,0 +1,38 @@
void temp(int v1, int v2)
{
}
int f(int i)
{
return i;
}
struct S
{
int i;
int j;
}
void main()
{
temp(v1: 1, v2: 2);
temp(v1: 1, v2: 2,);
auto s = S(5, j: 3);
temp(v1: 1, v2: f(i: 2));
temp(v1: true ? i : false ? 2 : f(i: 3), v2: 4);
temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1);
}
void test()
{
return Struct(foo: field.foo, bar: field.bar, baz: field.baz);
return new Class(foo: field.foo, bar: field.bar, baz: field.baz);
// anonymous class
return new class(foo: field.foo, bar: field.bar, baz: field.baz) Class
{
};
}

View File

@ -0,0 +1,11 @@
unittest
{
f([
x
]);
}
void f(T[] x,
const U y)
{
}

View File

@ -0,0 +1,7 @@
unittest
{
functionLengthDoesMatter([
firstFunctionInChain("A").seconFunctionInChain("B").value,
firstFunctionInChain("A").seconFunctionInChain("B").value
]);
}

View File

@ -0,0 +1,38 @@
@safe nothrow
@Read
@NonNull
public
int[] func(int argument_1_1, int argument_1_2,
int argument_2_1, int argument_2_2,
int argument_3_1, int argument_3_2)
{
if (true && true
&& true && true
&& true && true)
{
}
else if (true && true &&
true && true &&
true && true)
{
}
func(argument_1_1).func(argument_1_2)
.func(argument_2_1)
.func(argument_2_2);
auto x = func(argument_1_1, argument_1_2,
this.argument_2_1, this.argument_2_2,
argument_3_1, argument_3_2);
`
<html>
</html>
`.format!"%s";
return [
3, 5,
5, 7,
11, 13,
];
}

View File

@ -0,0 +1,49 @@
unittest
{
{
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
Three charlie, double delta)
{
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
&& foxtrot && golf && hotel && india && juliet)
{
}
}
}
}
void f()
{
string a = "foo"
~ "bar" /* bar */
~ "baz";
}
unittest
{
if (a)
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|| !peekIs(tok!"else")))
a();
}
}
unittest
{
callFunc({ int i = 10; return i; });
callFunc({
int i = 10;
foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo);
doStuff(withThings, andOtherStuff);
return i;
});
callFunc({
int i = 10;
foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName,
echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName);
doStuff(withThings, andOtherStuff);
return i;
}, more_stuff);
}

View File

@ -0,0 +1,41 @@
unittest
{
{
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
Three charlie, double delta)
{
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
&& foxtrot && golf && hotel && india && juliet)
{
}
}
}
}
unittest
{
if (a)
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version") || !peekIs(tok!"else")))
a();
}
}
unittest
{
callFunc({ int i = 10; return i; });
callFunc({
int i = 10;
foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo);
doStuff(withThings, andOtherStuff);
return i;
});
callFunc({
int i = 10;
foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName,
echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName);
doStuff(withThings, andOtherStuff);
return i;
}, more_stuff);
}

View File

@ -0,0 +1,15 @@
void main(string[] args)
{
for(int i = 0; i < 10; ++i)
{
if(i == 9)
break;
}
while(false)
{
}
foreach(i; 0 .. 9)
{
}
}

View File

@ -0,0 +1 @@
--single_indent=true

View File

@ -0,0 +1,60 @@
class C
{
void f()
{
if (true)
{
f(
map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__LINE__);
g(
map && map && map && map && map && map && map && map && map && map && map && map,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__LINE__);
h(
map || map || map || map || map || map || map || map || map || map || map || map,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__LINE__);
i(
map + map + map + map + map + map + map + map + map + map + map + map + map + map + map + map + map
+ map,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__FILE__,
__LINE__);
}
}
}

View File

@ -0,0 +1,2 @@
--single_indent=true
--keep_line_breaks=true

View File

@ -0,0 +1,31 @@
class C
{
void f()
{
if (true)
{
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
g(
map &&
map,
__FILE__,
__LINE__);
h(
map ||
map,
__FILE__,
__LINE__);
i(
map
+ map,
__FILE__,
__LINE__);
}
}
}

View File

@ -0,0 +1 @@
--keep_line_breaks=true

8
tests/assoc_key_indent.d Normal file
View File

@ -0,0 +1,8 @@
void main()
{
string key;
int[string] var = [
key: 5
];
}

View File

@ -0,0 +1 @@
import std.stdio; void main() { writeln("\eee8Hello"); int a = 5; }

View File

@ -0,0 +1 @@
### This file should not be erased just because it is not formatted correctly

1
tests/foreach_array.args Normal file
View File

@ -0,0 +1 @@
--keep_line_breaks true

53
tests/foreach_array.d Normal file
View File

@ -0,0 +1,53 @@
static foreach (x; [
1,
2,
3,
])
{
}
static foreach_reverse (x; [
1,
2,
3,
])
{
}
void f()
{
foreach (x; [
1,
2,
3,
])
{
}
foreach_reverse (x; [
1,
2,
3,
])
{
}
if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri))
{
send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, []));
}
foreach (x; map([
1,
2,
3,
]))
{
}
foreach (x; foo!(map!([
1,
2,
3,
])))
{
}
}

View File

@ -1,10 +1,12 @@
#!/usr/bin/env bash
argsFile=$1.args
if [ -e ${argsFile} ]; then
args=$(cat ${argsFile})
fi
echo "Args:" ${args}
dfmt --brace_style=allman ${args} $1.d > allman/$1.d.ref
dfmt --brace_style=otbs ${args} $1.d > otbs/$1.d.ref
../bin/dfmt --brace_style=allman ${args} $1.d > allman/$1.d.ref
../bin/dfmt --brace_style=otbs ${args} $1.d > otbs/$1.d.ref
echo "------------------"
echo "allman:"

1
tests/incomplete_alias.d Normal file
View File

@ -0,0 +1 @@
alias u8 = ubyte

11
tests/issue0134.d Normal file
View File

@ -0,0 +1,11 @@
void foo() {
string command;
version (Posix) command ~= " 2> /dev/null 1> /dev/null";
version (Posix) command ~= " 2> /dev/null 1> /dev/null";
unittest
{
version (Posix) command ~= " 2> /dev/null 1> /dev/null";
}
}

17
tests/issue0195.d Normal file
View File

@ -0,0 +1,17 @@
void main()
{
auto myTid = runTask({
auto conn = connectTCP("localhost", 4222);
auto l = Lexer(conn);
foreach (t;
l)
{
}
conn.close();
});
// foo
runEventLoop();
}

1
tests/issue0228.args Normal file
View File

@ -0,0 +1 @@
--end_of_line=crlf

8
tests/issue0228.d Normal file
View File

@ -0,0 +1,8 @@
/* This test relies on ../.gitattributes to contain these lines:
tests/issue0228.d text eol=lf
tests/allman/issue0228.d.ref text eol=crlf
tests/knr/issue0228.d.ref text eol=crlf
tests/otbs/issue0228.d.ref text eol=crlf
*/

15
tests/issue0256.d Normal file
View File

@ -0,0 +1,15 @@
void main() {
S s1 = { a: 3 };
S s2 = { a: 3, b:"test string" };
S s3 = { a: 3, b:"test string", c: {x: 3.14, y: 3 + 4} };
T t = {
someStructMember1: 2,
someStructMember2: 42,
someStructMember3: null, // foobar
someOtherMember1: objA,
someOtherMember2: objB,
someOtherMember3: 0,
somethingMore: null,
someFlagInThisStruct: -1
};
}

15
tests/issue0361.d Normal file
View File

@ -0,0 +1,15 @@
void foo() /**/
in
{
}
body
{
}
void bar() /**/
out
{
}
body
{
}

5
tests/issue0426.d Normal file
View File

@ -0,0 +1,5 @@
import std.stdio;
@safe extern(C) void main() {
writeln("Hello World!");
}

4
tests/issue0430.d Normal file
View File

@ -0,0 +1,4 @@
void f(bool body) {
if (body) {
}
}

38
tests/issue0432.d Normal file
View File

@ -0,0 +1,38 @@
struct S1
{
ulong x;
ulong y;
ulong function(ulong)f;
}
struct S2
{
ulong x;
ulong y;
ulong z;
ulong w;
}
// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer
immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },};
void f1()
{
}
// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer
int function(int) f2 = (x) { return x + 1111; };
immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,};
void f2()
{
}

8
tests/issue0433.d Normal file
View File

@ -0,0 +1,8 @@
int abs(int x) {
if (x < 0)
// x negative, must negate
return -x;
else
// x already non-negative, just return it
return x;
}

4
tests/issue0448.d Normal file
View File

@ -0,0 +1,4 @@
struct S
{
invariant(true);
}

40
tests/issue0451.d Normal file
View File

@ -0,0 +1,40 @@
class C
{
abstract void f1() //
in (true);
abstract void f2() /* */
in (true);
abstract bool f3() //
out (r; r);
abstract bool f4() /* */
out (r; r);
abstract void f5() //
do
{
}
abstract void f6() /* */
do
{
}
abstract bool f7() //
in (true) //
out (r; r) //
do //
{
return true;
}
abstract bool f8() /* */
in (true) /* */
out (r; r) /* */
do /* */
{
return true;
}
}

3
tests/issue0452.d Normal file
View File

@ -0,0 +1,3 @@
@nogc
//
void foo();

9
tests/issue0454.d Normal file
View File

@ -0,0 +1,9 @@
void main()
{
format!"%s" //
("");
format!("%s") //
("");
format!("%s") //
("", argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8, argument9, argument10);
}

9
tests/issue0465.d Normal file
View File

@ -0,0 +1,9 @@
bool asdf(const string owner, const string mail) @safe
{
requestHTTP(url, (scope HTTPClientRequest request) {
request.writeFormBody([owner: owner, mail:
mail]);
}, (scope HTTPClientResponse response) {});
return true;
}

7
tests/issue0476.d Normal file
View File

@ -0,0 +1,7 @@
string BuildForwardCall()
{
return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `)))
{
return (mocked___.` ~ methodString ~ argsPassed ~ `);
}`;
}

1
tests/issue0483.args Normal file
View File

@ -0,0 +1 @@
--align_switch_statements=false

15
tests/issue0483.d Normal file
View File

@ -0,0 +1,15 @@
module tests.issue0483;
void main()
{
switch (0)
{
case 1:
case 2:
label:
case 3:
break;
default:
break;
}
}

Some files were not shown because too many files have changed in this diff Show More