Commit Graph

48 Commits

Author SHA1 Message Date
Caleb Cartwright
065258659d feat: implement 2024 Style Edition for expr overflows 2024-08-27 20:49:15 -05:00
Caleb Cartwright
aa8a53f687 refactor: switch idempotence/system tests to style_edition
Updates all the various files utilized in the system and
idempotence tests to directly use the corresponding
'style_edition' configuration as opposed to keeping
the original 'version' values and relying on the mapping.
2024-07-28 19:37:36 -05:00
IVIURRAY
bf967319e2
Add config option generated_marker_line_search_limit (#5993)
`generated_marker_line_search_limit` allows users to configure how many
lines rustfmt should search for an `@generated` marker comment when
`format_generated_files=false`

---------

Co-authored-by: Jordan Eldredge <jordan@jordaneldredge.com>
2024-01-20 11:14:50 -05:00
Yacin Tmimi
fe8b72d98e implement single_line_let_else_max_width
This allows users to configure the maximum length of a single line
`let-else` statements. `let-else` statements that otherwise meet the
requirements to be formatted on a single line will have their divergent
`else` block formatted over multiple lines if they exceed this length.

**Note**: `single_line_let_else_max_widt` will be introduced as a stable
configuration option.
2023-07-01 01:06:35 -05:00
Yacin Tmimi
0cb294f05c Deprecate and Rename fn_args_layout -> fn_params_layout
fn_args_layout is now deprecated.

This option was renamed to better communicate that it affects the layout
of parameters in function signatures and not the layout of arguments in
function calls.

Because the `fn_args_layout` is a stable option the renamed option is
also stable, however users who set `fn_args_layout` will get a warning
message letting them know that the option has been renamed.
2022-07-12 19:33:53 -05:00
sec65
33c60740d3
Add width for codeblocks in comments (#5372)
* add doc_comment_code_block_width configuration

* updated config docu

* Updated docu and changed tests to config folder
2022-06-16 22:15:16 -05:00
Tom Milligan
4f3f87fb9a group_imports: test and document non-consecutive imports 2022-04-11 17:46:33 -05:00
123vivekr
0dba01aee1 Add short_item_threshold config option
Allow custom short item threshold values via config
2022-03-21 16:56:09 -05:00
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
Matt
073cc3891f Option to create groups for std, external crates, and other imports
Backport of 17d90ca.
2020-11-18 21:37:42 -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
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
rchaser53
c2534f5324 fix "internal error: left behind trailing whitespace" with long lines 2019-02-01 19:58:38 +09: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
Nick Cameron
9c34986bab Add some tests I forgot about earlier 2018-08-01 10:41:16 +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
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
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
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
Seiichi Uchida
279acda4c4 Remove same_line_attributes config option 2018-01-11 16:52:28 +09:00
David Alber
aa70bbe377 Moving test files to satisfy verify_config_test_names test 2017-12-28 10:29:48 -08:00
David Alber
6939e21f43 Moving config option tests to subdirectory
This was done by running the following.

```sh
for f in `find . -name "configs-*.rs"`; do
    topdir=`echo $f | cut -d/ -f2`;
    configname=`echo $f | cut -d/ -f3 | cut -d- -f2`;
    testname=`echo $f | cut -d/ -f3 | cut -d- -f3`;
    mkdir -p $topdir/configs/$configname;
    git mv $f $topdir/configs/$configname/$testname;
done
```
2017-12-28 10:29:48 -08:00