Commit graph

1014 commits

Author SHA1 Message Date
topecongiro
92b54d6490 Add heuristic when rewriting chain with a single child
rustfmt splits chain into multiline when the length of chain exceeds
`chain_one_line_max`. However, currenly this rule only applies when the chain
has more than one child. This can lead to unexpected long chain if the parent
is long. This commit adds heuristic that if the length of parent is longer
than the half of `chain_one_line_max` we use multiline even if there is
only a single child.
2017-05-24 00:06:23 +09:00
topecongiro
ec33121aaf Format source codes 2017-05-23 22:13:29 +09:00
topecongiro
cb4a6a2419 Use correct width when rewriting chain 2017-05-23 22:12:52 +09:00
topecongiro
a83d4876e7 Allow first child to stay on the same line with block parent 2017-05-23 22:12:37 +09:00
topecongiro
f83c22f24f Add trailing comma to a single arg in multiline 2017-05-23 13:26:59 +09:00
topecongiro
b4cd9584b3 Implement combining for tuple and block 2017-05-23 12:51:32 +09:00
topecongiro
2c15204f0c Update tests 2017-05-23 12:51:13 +09:00
topecongiro
29c0ab77ba Implement combining openings and closings 2017-05-23 12:45:09 +09:00
topecongiro
dc8d3aa23a Update tests 2017-05-23 11:39:31 +09:00
topecongiro
77a2e9858b Format source codes 2017-05-23 11:37:33 +09:00
topecongiro
f2ec5a7bac Refactor source codes 2017-05-23 11:37:12 +09:00
topecongiro
520340481d Allow macro rewrite to fail on rhs 2017-05-23 11:37:12 +09:00
topecongiro
13af774e55 Fix weird indentaion in chain 2017-05-23 11:37:12 +09:00
topecongiro
d16a0a399e Implement 'vec![expr; expr]' 2017-05-23 11:32:09 +09:00
Michael Killough
bce1f309b7 Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into config 2017-05-19 16:10:27 +07:00
Ben Boeckel
8ca699ce26 config: fix suffices -> suffixes typo
Fixes #1477.
2017-05-18 08:03:47 -04:00
Seiichi Uchida
c0fae6a82a Merge pull request #1562 from flier/reorder_imports_in_group
reorder imports in group
2017-05-18 17:53:23 +09:00
Michael Killough
c3c2e823cb Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into config 2017-05-18 13:05:19 +07:00
Michael Killough
31c8fb4e76 Add --dump-default-config and --dump-minimal-config.
- `--dump-default-config` outputs the default configuration to the
   specified file as TOML and then exits.
 - `--dump-minimal-config` is checked after formatting files as normal.
   If present, any configuration options that were checked during
   formatting are written to the specified file as TOML.
 - These options were added only to `rustfmt`, not to `cargo fmt`. They
   can be specified when using `cargo fmt` by placing them after `--`.
 - It would have been nice if the filename was optional, so you could
   run just `rusfmt --dump-minimal-config build.rs` to have it output to
   `rustfmt.toml`. However, this doesn't do what you might expect: it
   outputs the config to `build.rs`!
2017-05-18 12:56:49 +07:00
Flier Lu
1077a100a1 reorder imports in group 2017-05-18 13:26:34 +08:00
Michael Killough
3f34ff8229 Return PartialConfig from Config methods.
Leave serialization to the caller, but provide a
`PartialConfig.to_toml()` method, to deal with the fact that
`file_lines` can't be serialized.

Add a simple test.
2017-05-18 12:10:25 +07:00
Michael Killough
222bac1397 Provide config.set().item(value) API.
This API isn't fantastic, but it's the best I can come up with without
something like `concat_idents!()`. There are relatively few places where
config is set, to hopefully the ugliness isn't disastrous.

Change previous occurences of `config.item = value` to this new API,
rather than using `config.override_value()`. Undo the changes to
`override_value()`, as it's no longer important to propogate the error
to the caller. Add a test for the new interface.
2017-05-18 11:42:32 +07:00
Michael Killough
9e26575ed8 Use unreachable!() instead of panic!(). 2017-05-18 11:09:11 +07:00
Michael Killough
6098f7f924 Remove ConfigTracker - inline in Config.
Use an individual `Cell<bool>` on each config item, rather than
maintaining a set of config names that were accessed. Add a simple unit
test.
2017-05-18 11:07:49 +07:00
topecongiro
cfff3bd91e Use multiline when signature does not fit single line 2017-05-17 16:31:09 +09:00
topecongiro
d7b6f1199f Format source codes 2017-05-16 23:24:38 +09:00
topecongiro
feff6248c4 Allow last child in chain to go multiline 2017-05-16 23:24:00 +09:00
Michael Killough
7a4955f705 Add methods to serialize Config to TOML.
Two different modes:

 - Serialize the full Config object. This is useful as
   `Config::default().to_toml()` to output a rustfmt.toml with defaults
   (#317).
 - Serialize only the options that have been accessed. This could be
   useful to output a minimal rustfmt.toml for a project. (If the
   default value of any unused config item changes, you'll then get the
   new default when you come to use it).

This commit doesn't expose this anywhere - deciding a sensible CLI is a
bit trickier.

This commit also has very simple error reporting (Result<String,
String>) - once the CLI is decided, a more sensible method of reporting
errors might become obvious.
2017-05-16 18:08:24 +07:00
Michael Killough
4d879662a9 Track which config items are accessed.
Required by #865. This doesn't introduce any method to view which
parameters are accessed.

We record which config items are accessed even if we don't intend to
output them, as we assume it will be a relatively cheap operation.
2017-05-16 18:05:40 +07:00
Michael Killough
c0bdbfa531 Switch to accessing config items via method.
Preparation for #865, which proposes adding a flag which outputs which
config options are used during formatting.

This PR should not make any difference to functionality. A lot of this
was search-and-replace.

Some areas worthy of review/discussion:

 - The method for each config item returns a clone of the underlying
   value. We can't simply return an immutable reference, as lots of
   places in the code expect to be able to pass the returned value as
   `bool` (not `&bool). It would be nice if the `bool` items could
   return a copy, but the more complex types a borrowed reference... but
   unfortunately, I couldn't get the macro to do this.
 - A few places (mostly tests and `src/bin/rustfmt.rs`) were overriding
   config items by modifying the fields of the `Config` struct directly.
   They now use the existing `override_value()` method, which has been
   modified to return a `Result` for use by `src/bin/rustfmt.rs`. This
   benefits of this are that the complex `file_lines` and `write_mode`
   strings are now parsed in one place (`Config.override_value`) instead
   of multiple. The disadvantages are that it moves the compile-time
   checks for config names to become run-time checks.
2017-05-16 15:47:09 +07:00
Seiichi Uchida
762db5138e Format source codes 2017-05-15 22:55:45 +09:00
Seiichi Uchida
79ba34c607 Use offset_left for rewrite_unary_prefix 2017-05-15 22:55:01 +09:00
Nick Cameron
d1682b3473 Merge pull request #1510 from fintelia/better-filelines
Better file_lines
2017-05-15 09:19:18 +12:00
Nick Cameron
ebb26db68b Merge pull request #1551 from topecongiro/else-if-early-line-break
Forbid early line breaks inside else if
2017-05-15 08:59:03 +12:00
Nick Cameron
0ebd5775d7 Merge pull request #1550 from topecongiro/issue-1547
Prevent rewriting closure block to expr inside macro
2017-05-15 08:46:14 +12:00
Nick Cameron
65e151279d Merge pull request #1552 from guanqun/give-specific-errors
add more specific reason why it fails to parse
2017-05-14 18:08:27 +12:00
Guanqun Lu
7783b4c0b6 add more specific reason why it fails to parse 2017-05-14 13:19:06 +08:00
Jonathan Behrens
9f83f29187
Refactor file range checking 2017-05-13 13:14:24 -04:00
Seiichi Uchida
5383b6cc17 Format source code 2017-05-13 21:08:10 +09:00
Seiichi Uchida
819a13030f Use precise width when rewriting else if 2017-05-13 21:07:36 +09:00
Seiichi Uchida
7ec78711f2 Prevent rewriting closure block to expr inside macro 2017-05-13 18:32:25 +09:00
Seiichi Uchida
d0a094eefb Merge pull request #1546 from topecongiro/bug/range-full
Add a missing trailing comma before elipses
2017-05-13 17:40:47 +09:00
topecongiro
4aa64674c9 Add a missing trailing comma before elipses 2017-05-13 07:23:34 +09:00
Seiichi Uchida
56515dd4d6 Merge pull request #1543 from topecongiro/field-attr
Support struct_field_attributes
2017-05-12 20:08:36 +09:00
topecongiro
744fa427e2 Support struct_field_attributes 2017-05-12 17:58:38 +09:00
topecongiro
384ce46eef Use vertical layout when args len is larger than fn_call_width 2017-05-12 16:30:26 +09:00
topecongiro
ba1a7b9e7f Try multi-line only when fn_call_style is Block and rewriting function call 2017-05-12 10:33:05 +09:00
Nick Cameron
1eec103516 Merge pull request #1523 from topecongiro/poor-formatting/fn_call_style
Use multiline when args exceeds max_width in fn_call_style = "block"
2017-05-10 08:27:24 +12:00
topecongiro
30a8050559 Use multiline when args exceeds max_width in fn_call_style = "block" 2017-05-10 00:27:57 +09:00
topecongiro
9d96c33d59 Inherit alignment to last else 2017-05-09 17:33:45 +09:00