Commit Graph

1514 Commits

Author SHA1 Message Date
Nick Cameron
08f631de43 Merge pull request #1582 from topecongiro/poor/fn_call_style_block
Decide whether args fit in a single line inside rewrite_call_args
2017-05-25 10:50:17 +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
Nick Cameron
cb464a919a Merge pull request #1576 from topecongiro/chain/float-first-child
Allow first child to stay on the same line with block parent when rewriting chain
2017-05-24 08:47:10 +12: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
Nick Cameron
7c8432f05b Merge pull request #1572 from topecongiro/nested-block
Nesting of block indented expressions
2017-05-23 18:35:21 +12: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
Seiichi Uchida
eb8d67196c Merge pull request #1565 from topecongiro/issue-1563
Implement vec![expr; expr] and avoid unnecessary indent in chain
2017-05-23 12:44:47 +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
Nick Cameron
068b8b3b5c Merge pull request #1558 from mjkillough/config
Add a flag to emit which options are used
2017-05-22 12:13:22 +12: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
Nick Cameron
fdf950b009 Merge pull request #1569 from mathstuf/example-typos
Configurations: fix typos in example signatures
2017-05-19 11:57:44 +12:00
Nick Cameron
443cd1cb2f Merge pull request #1568 from mathstuf/suffixes-typo
config: fix `suffices` -> `suffixes` typo
2017-05-19 11:57:15 +12:00
Ben Boeckel
59cefa988a Configurations: fix typos in example signatures 2017-05-18 08:17:09 -04: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
Nick Cameron
330605db8c Merge pull request #1560 from topecongiro/issue-1441
Use multiline when signature does not fit single line
2017-05-18 10:51:21 +12:00
Nick Cameron
219822ba3f Bump version of strings.rs and cargo update 2017-05-18 07:59:09 +12:00
topecongiro
cfff3bd91e Use multiline when signature does not fit single line 2017-05-17 16:31:09 +09:00
Nick Cameron
bf9b3fa1d7 Add note about libsyntax branch to README 2017-05-17 19:07:25 +12:00
Nick Cameron
6a70e9c22c Merge pull request #1559 from topecongiro/poor/chain
Allow the last element in chain to go multiline
2017-05-17 17:43:42 +12:00
Nick Cameron
15323fc38b Merge pull request #1557 from mjkillough/issue_1366
Add test for issue #1366.
2017-05-17 09:58:49 +12: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
dcd3c0ed2e Add test for issue #1366.
As the comments in the issue state: it appears to work now, so this test
should just stop any regressions.

The second example in the issue description will format to the first,
which is then a fixed-point.
2017-05-16 16:17:46 +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
Nick Cameron
09e5051dee Merge pull request #1556 from topecongiro/issue-1555
Only add offset for unary op
2017-05-16 09:55:07 +12:00
Seiichi Uchida
762db5138e Format source codes 2017-05-15 22:55:45 +09:00