Commit graph

1071 commits

Author SHA1 Message Date
Nick Cameron
a7b8dcc60d Simplify --version info 2017-05-25 16:39:44 +12:00
Nick Cameron
393ba27311 Remove dependency on Itertools 2017-05-25 16:23:07 +12:00
Nick Cameron
80f3b3c9c4 Remove multimap dep 2017-05-25 15:59:06 +12:00
topecongiro
c8ad521c9f Decide whether args fit in a single line inside rewrite_call_args 2017-05-25 06:10:00 +09:00
Nick Cameron
93c556c6ba Merge pull request #1578 from topecongiro/poor/macro
Use original code snippet for macro which contains invalid syntax
2017-05-24 11:43:10 +12:00
topecongiro
e3eec44690 Return original snippet when macro contains invalid syntax 2017-05-24 07:24:31 +09:00
topecongiro
04bb5d8929 Format source codes 2017-05-24 00:07:02 +09:00
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
topecongiro
ac6e6dfd5d Refactor rewrite_pat_expr 2017-05-09 17:33:28 +09:00
Nick Cameron
35e1ca73fc Merge pull request #1519 from topecongiro/poor-formatting/if-else
Remove visual_indent when rewriting else block
2017-05-09 15:21:29 +12:00
Nick Cameron
da261ef9d3 Merge pull request #1520 from topecongiro/allow-match
Apply closure exception to match in args
2017-05-09 15:21:06 +12:00
topecongiro
0248e9869d Apply closure exception to match in args 2017-05-09 08:28:05 +09:00
topecongiro
f36411c339 Remove visual_indent when rewriting else block 2017-05-09 08:11:05 +09:00
topecongiro
2776615dc9 Replace 'try!' with '?' 2017-05-08 13:14:23 +09:00
topecongiro
d062d79fb5 Use block indent when visual indent failed 2017-05-08 08:07:18 +09:00
Nick Cameron
459b4449a6 Merge pull request #1442 from topecongiro/poor-formatting/trailing-comma
Remove comma from function definition with a single argument
2017-05-08 10:45:03 +12:00
Nick Cameron
e5f8a725db Merge pull request #1511 from topecongiro/bug/closure-fallback
Add fallback path inside rewrite_closure
2017-05-08 10:30:49 +12:00
Nick Cameron
2d88c7569f Merge pull request #1513 from topecongiro/refactoring
Add methods to Shape
2017-05-08 10:29:02 +12:00
topecongiro
4a28be486e Refactor Shape 2017-05-08 07:24:32 +09:00
topecongiro
e923df4146 Add indented and with_max_width 2017-05-08 07:24:12 +09:00
topecongiro
5e832acdc4 Allow config-path to point to a file 2017-05-08 07:02:23 +09:00
topecongiro
2ee8e730a6 Add fallback path 2017-05-07 13:13:44 +09:00
Jonathan Behrens
b1c9832c9b
Respect file_lines within write_snippet() function 2017-05-06 17:59:51 -04:00
Jonathan Behrens
7c6479358b
Respect file_lines within format_lines() function 2017-05-06 15:14:44 -04:00
Nick Cameron
75a13868da Block format control flow discriminant expressions and binops
Fixes #1450

Adds control_style option
2017-05-05 14:37:13 +12:00
topecongiro
e7c6d34854 Use SeperatorTactic::Never for a single argument 2017-05-04 14:47:50 +09:00
Nick Cameron
8579c1db0e Merge pull request #1495 from topecongiro/poor-formatting/closure
Fix weird indentation inside closures
2017-05-04 17:15:58 +12:00
Nick Cameron
c89c01efc0 Merge pull request #1500 from shioju/master
Format macros in trait item position
2017-05-04 10:00:03 +12:00
Sheng Hau
51815effbe Format macros in trait item position 2017-05-04 00:10:03 +08:00
topecongiro
58d957be3f Check format failures explicitly in visit_block 2017-05-04 00:21:51 +09:00
est31
11cc56b06b Format fix 2017-05-03 17:16:58 +02:00
est31
6e46a827b6 Simplifications 2017-05-03 17:11:34 +02:00
est31
78d4ef1992 Drop rustc-serialize, use serde, update toml dependency 2017-05-03 10:23:50 +02:00
topecongiro
f5da9d779f Format source codes 2017-05-03 11:26:25 +09:00
topecongiro
e91d498b8f Keep a chain with length chain_one_line_max in a single line 2017-05-03 11:24:08 +09:00
topecongiro
2c1d896f60 Split a long chain with a single child 2017-05-03 11:22:36 +09:00
topecongiro
3f703fd33d Use block indent when visual indent failed inside closure block 2017-05-03 11:21:31 +09:00
Nick Cameron
59d66c3ae8 Merge pull request #1453 from topecongiro/bug/empty-struct-with-comment
Handle empty tuple struct def with comment properly
2017-05-02 13:49:15 +12:00
topecongiro
93dae1a34d Add test for empty tuple struct with comment 2017-05-02 10:21:39 +09:00
topecongiro
2e00c117e5 Handle empty tuple struct def properly 2017-05-02 10:21:39 +09:00
Seiichi Uchida
19599b9a01 Use block when arm exceeds max_width 2017-05-02 10:15:31 +09:00
Vincent Esche
42dbe482e3 Made type_punctuation_density apply too all + in types 2017-05-02 01:03:46 +02:00
Nick Cameron
e809dcbf3b Merge pull request #1491 from regexident/where_density
Add todo on equal output for `where_density = Tall` or `Vertical`
2017-05-02 10:50:32 +12:00
Nick Cameron
7fb288f0b3 Merge pull request #1487 from topecongiro/issue1470
Use block indent when visual indent exceeds max_width
2017-05-02 10:45:23 +12:00
Nick Cameron
c546f1b396 Merge pull request #1454 from topecongiro/match
Format nested mathces properly.
2017-05-02 10:40:31 +12:00
Nick Cameron
2223b64f86 Merge pull request #1486 from topecongiro/refactoring
Refactor source codes
2017-05-02 10:30:11 +12:00
Vincent Esche
5ae74cab8f Add todo on equal output for where_density = Tall or Vertical 2017-05-01 22:01:19 +02:00
Nick Cameron
c6f1dd4fb5 Remove generics_style option 2017-05-02 07:56:46 +12:00
Seiichi Uchida
c7e9bcadaa Use block indent when visual indent exceeds max_width 2017-05-01 18:52:43 +09:00
topecongiro
9dc643a6ae Remove TODO from 'format_tuple_struct' 2017-05-01 15:57:08 +09:00
topecongiro
68c5915176 Remove TODO from 'rewrite_generics' 2017-05-01 15:57:08 +09:00