Commit Graph

54 Commits

Author SHA1 Message Date
Martinez
599b2fd9c4
Add One option to group_imports (#4966)
* Add Together option to group_imports

* Rename option to One

* Rename files from Together to One
2021-10-23 11:01:48 -05:00
Seiichi Uchida
d4ffd1efa4 Support @generated marker to skip code formatting
This is a copy of #4296 with these changes:
* file is not reopened again to find if the file is generated
* first five lines are scanned for `@generated` marker instead of one
* no attempt is made to only search for marker in comments

`@generated` marker is used by certain tools to understand that the
file is generated, so it should be treated differently than a file
written by a human:
* linters should not be invoked on these files,
* diffs in these files are less important,
* and these files should not be reformatted.

This PR proposes builtin support for `@generated` marker.

I have not found a standard for a generated file marker, but:
* Facebook [uses `@generated` marker](https://tinyurl.com/fb-generated)
* Phabricator tool which was spawned from Facebook internal tool
  [also understands `@generated` marker](https://git.io/JnVHa)
* Cargo inserts `@generated` marker into [generated Cargo.lock files](https://git.io/JnVHP)

My personal story is that rust-protobuf project which I maintain
was broken twice because of incompatibilities/bugs in rustfmt marker
handling: [one](https://github.com/stepancheg/rust-protobuf/issues/493),
[two](https://github.com/stepancheg/rust-protobuf/issues/551).
(Also, rust-protobuf started generating `@generated` marker
[6 years ago](https://git.io/JnV5h)).

While rustfmt AST markers are useful to apply to a certain AST
elements, disable whole-file-at-once all-tools-at-once text level
marker might be easier to use and more reliable for generated code.
2021-09-14 21:22:26 -05:00
Caleb Cartwright
b305d62e5b fix: correct arm leading pipe check (#4880)
In the event a pattern starts with a leading pipe
the pattern span will contain, and begin with, the pipe.

This updates the process to see if a match arm contains
a leading pipe by leveraging this recent(ish) change to
the patterns in the AST, and avoids an indexing bug that
occurs when a pattern starts with a non-ascii char in the
old implementation.
2021-07-25 22:53:32 -05:00
Joseph Birr-Pixton
58157bb4b7 Add some basic tests for chain_width use 2021-04-21 21:27:50 -05:00
Caleb Cartwright
a168d92f9a tests: augment heuristics tests 2021-04-21 21:27:50 -05:00
Geoffry Song
71863753bd Rename merge_imports to imports_granularity and add a Module option.
This renames the existing `true`/`false` options to `Crate`/`Never`, then adds a
new `Module` option which causes imports to be grouped together by their
originating module.
2021-01-17 11:48:47 -06:00
meiomorphism
003786228d fix: don't force a newline after an empty where clause
Fixes #4547.
2020-11-25 21:32:46 -06:00
Matt
073cc3891f Option to create groups for std, external crates, and other imports
Backport of 17d90ca.
2020-11-18 21:37:42 -06:00
Aaron Hill
46ab14437e Don't flatten a block containing a single macro call
We no longer flatten a block that looks like this:

```rust
match val {
    pat => { macro_call!() }
}
```

Currently, rust ignores trailing semicolons in macro expansion in
expression position (see https://github.com/rust-lang/rust/issues/33953)

If this is changed, flattening a block with a macro call may break the
user's code - the trailing semicolon will no longer parse if the macro
call occurs immediately on the right-hand side of the match arm
(e.g. `pat => macro_call!()`)
2020-11-05 20:45:11 -06:00
Caleb Cartwright
4908ee19c3 tests: add tests for leading pipe config 2020-09-24 09:43:31 -05:00
Caleb Cartwright
00e199c974
backport new syntax to rustfmt 1.x (#4105)
* feat: support raw reference operator

* feat: support const opt-out syntax

* feat: support half open range syntax
2020-03-31 15:28:01 +09:00
Stéphane Campinas
5327c3633f handle field attributes when aligning a struct's fields (#3513) 2019-10-19 16:56:32 +09:00
Valentine Valyaeff
15a28f79b8 Another fix for merge_imports (#3769) 2019-09-04 23:02:10 +09:00
Seiichi Uchida
c0e616bc1d
Implement closing-block procedure without relying on missed_span module (#3691) 2019-07-17 23:07:12 +09:00
Caleb Cartwright
aa0c9dd212 tests: add normalize_doc_attributes config tests (#3630) 2019-06-16 23:46:25 +09:00
Stéphane Campinas
87565c42ce
Merge pull request #3607 from topecongiro/issue-3493
Ignore sub-modules when skip-children is used
2019-06-08 09:50:12 +02:00
topecongiro
788a4cbe4f
Add a test for #3493 2019-06-08 14:52:49 +09:00
Stéphane Campinas
e6b60a40d5 stabilise fn_args_density (#3581) 2019-06-03 22:26:48 +09:00
topecongiro
7fc4e418bf Tweak test settings 2019-03-17 12:33:18 +09:00
Alexander Regueiro
7a3b7c9275 Various cosmetic improvements (#3403) 2019-02-19 11:56:42 +09:00
Seiichi Uchida
bfcfaf1743
Merge pull request #3308 from topecongiro/issue-2835
Prioritize single_line_fn and empty_item_single_line over brace_style
2019-02-04 00:11:01 +09:00
rchaser53
c2534f5324 fix "internal error: left behind trailing whitespace" with long lines 2019-02-01 19:58:38 +09:00
topecongiro
0142e961ad Prioritize single_line_fn and empty_item_single_line over brace_style
When either one of these two options are set to `true`, each should take
precedence over the brace_style option.

This commit does not introduce any formatting change to the default
configuration, so no version gate is required.
2019-02-01 00:22:47 +09:00
Nick Cameron
378994b858 Add a version option 2018-11-27 14:18:14 +13:00
Ivan Molodetskikh
cbaed838d5
No trailing comma in struct literals (Visual) 2018-10-06 10:59:47 +03:00
moxian
65ae0b9a09 Change enum align semantics to care about absolute length, rather than difference.
If we're only aligning enum discriminants that are "not too far apart
(length-wise)", then this works really well for enums with
consistently-long or consistently-short idents, but not for the mixed
ones.
However, consistently-long idents is somewhate of an uncommon case and
overlong idents may be allowed to be formatted suboptimally if that
makes mixed-length idents work better (and it does in this case).
2018-09-26 18:47:17 +00:00
moxian
cc22869fb4 Add option to vertically align enum discriminants. 2018-09-26 14:35:38 +00:00
Seiichi Uchida
594774b4e5 Update tests 2018-09-19 23:19:24 +09:00
Nick Cameron
9c34986bab Add some tests I forgot about earlier 2018-08-01 10:41:16 +12:00
Nick Cameron
4fa2969c39 fixup tests 2018-07-24 15:46:39 +12:00
Michael Bebenita
c2ae39e77a Add max_width option for all heuristics.
This is useful when working with very small max_widths like 79 chars.
2018-07-17 13:17:36 -04:00
Seiichi Uchida
0204dcbd98 Update tests 2018-06-05 19:58:21 +09:00
csmoe
d46852b3f7 fix tests 2018-05-31 18:34:06 +08:00
Nick Cameron
d726492e65 Remove spaces_within_parens_and_brackets
cc #1974
2018-05-18 16:35:09 +12:00
Nick Cameron
51f566062f Update uses of rustfmt_skip to rustfmt::skip 2018-05-14 16:25:10 +12:00
topecongiro
680c65dc97 Update tests to use the absolute position for small parent heuristic 2018-05-08 06:23:14 +09:00
Nick Cameron
17b04f181d
Merge pull request #2677 from csmoe/remove_nested_parens_opt
Add remove nested parens option
2018-05-06 14:01:17 +12:00
csmoe
5b121582e5 add config test 2018-05-06 09:23:45 +08:00
csmoe
8c8676cd30 fix merge_mix 2018-05-03 10:26:53 +08:00
topecongiro
3432807ac2 Temporarily fix tests
cc #2655.
2018-04-28 14:07:10 +09:00
Nick Cameron
aa4419019a Update tests 2018-04-11 10:46:49 +12:00
Seiichi Uchida
94f5a05a6a Add reorder_impl_items config option 2018-04-05 12:49:16 +09:00
Nick Cameron
4f522794ae Tidy up and pass tests 2018-03-02 15:07:13 +13:00
topecongiro
4af2aa3a9e Create rustfmt_core crate 2018-02-07 22:48:05 +09:00
Seiichi Uchida
9273a72420 Add tests for reorder_extern_crates 2018-02-04 12:07:51 +09:00
Nick Cameron
b7f01769f9
Merge branch 'master' into init-shorthand 2018-02-01 15:20:01 +13:00
Nick Cameron
918e79bb5a
Merge pull request #2380 from topecongiro/reorder-mods
[RFC] Reorder modules alphabetically
2018-02-01 15:18:34 +13:00
Seiichi Uchida
c9c346a89f Add 'use_field_init_shorthand' config option 2018-01-29 22:15:20 +09:00
Seiichi Uchida
56c6d73d82 Reorder modules
Add `reorder_modules` config option.

Two things we must keep in mind when reordering modules:
1. We should not reorder modules with attributes, as doing so could
   potentially break the code (e.g. `#[macro_use]`).
2. We should not reorder inline modules e.g. `mod foo { /* .. */ }`.
   We should only reorder module declarations e.g. `mod foo;`.

Some open questions:
1. Should we bring modules with `pub` in front of those without `pub`
   so that they stand out from others?
2. Instead of keeping modules with attributes in the same place,
   can we bring them in front of others? Is this safe?
2018-01-29 21:59:15 +09:00
David Alber
69f27673df Extending spaces_around_ranges to ranges in match arm patterns 2018-01-21 16:50:17 -08:00