Commit graph

864 commits

Author SHA1 Message Date
Srinivas Reddy Thatiparthy
901c5b1a5d use std::error instead std::out 2016-04-06 23:23:02 +05:30
Nick Cameron
4fdf859787 Merge pull request #897 from matklad/refactor-run
Refactor run family of functions
2016-04-05 11:25:13 +12:00
Aleksey Kladov
c29ee66b94 make naming more consistent 2016-04-05 01:20:14 +03:00
0x0G
6e393b3d53 Fix. rustfmt write to stderr instead stdout
Fix. rustfmt write to stderr instead stdout
2016-04-04 12:49:16 +02:00
Aleksey Kladov
63887ed413 make format_string and fmt_lines private 2016-04-03 00:45:04 +03:00
Aleksey Kladov
ac4532e161 use format_input function in tests 2016-04-03 00:32:24 +03:00
Srinivas Reddy Thatiparthy
bee9682a49 Correct spelling of 'style' 2016-04-03 01:08:25 +05:30
Aleksey Kladov
84fb2f402e refactor: unify run and run_from_stdin 2016-04-02 22:24:38 +03:00
Aleksey Kladov
294b463b5d minor: use &mut ref instead of by value argument
This also unifies `write_all_files` and `write_file` functions
2016-04-02 19:36:56 +03:00
Erik Johnston
57847e451a Add fn_arg_one_line option
If set, arguments will be kept on one line if they fit. Currently only
applies when `fn_args_layout` is set to `Block`.

This commit also fixes a bug where newlines were inserted inbetween
argument brackets when there were no arguments and `fn_args_layout` was
set to `Block`.
2016-04-02 00:25:35 +01:00
Erik Johnston
8219d15291 Fix incorrect indent with fn_args_layout: Block
The closing parenthesis for the arg list was written on a new line
without first applying the appropriate indent.
2016-04-01 23:01:49 +01:00
Nick Cameron
5b11d2e80f Merge pull request #892 from marcusklaas/closed-ranges
Format closed ranges
2016-03-31 13:47:09 +13:00
Marcus Klaas de Vries
50820c6a43 Merge pull request #883 from marcusklaas/macro-with-name
Properly format macro's with an extra ident
2016-03-30 02:03:28 +02:00
Marcus Klaas
f941646118 Do not panic on type ascription or try shorthand
Instead, simply format expressions involving these unstable features
as they were found.
2016-03-30 00:01:54 +02:00
Marcus Klaas
9eee93306a Format closed ranges 2016-03-29 23:58:45 +02:00
Marcus Klaas
9e5c0390a0 Properly format macro's with an extra ident 2016-03-29 23:16:40 +02:00
Nick Cameron
d3b18d0b45 Merge pull request #889 from kamalmarhubi/next-power-of-two
Use checked_next_power_of_two from std instead of custom method
2016-03-29 21:00:31 +13:00
Nick Cameron
11391dfe7b Merge pull request #891 from kamalmarhubi/update-syntex-syntax
deps: Update syntex_syntax to 0.30.0
2016-03-29 20:58:57 +13:00
Nick Cameron
dd96c55801 Merge pull request #886 from matklad/make-illegal-states-unrepresentable
Introduce verbosity enum
2016-03-29 20:57:16 +13:00
Kamal Marhubi
f2b5931c6d deps: Update syntex_syntax to 0.30.0
This bump includes ability to parse inclusive ranges (`a...b`) and the
question mark operator.

Refs #867, #890
2016-03-29 00:04:44 -04:00
Kamal Marhubi
8168c7c44c Use checked_next_power_of_two from std instead of custom method
NB The custom method returned 0 on an input of 0, which is arguably
incorrect: 0 is not a power of two; the method in `std` returns 1 in
that case.
2016-03-28 23:36:22 -04:00
Nick Cameron
6526533745 Merge pull request #879 from matklad/proper-exit-code
cargo-fmt: don't return zero on failure
2016-03-29 13:56:00 +13:00
Aleksey Kladov
c7e51d3994 minor: use enum instead of pair of booleans
This is a bit more typing, but statically forbids using both verbose and
quiet
2016-03-29 02:37:43 +03:00
Aleksey Kladov
ac7778cc51 cargo-fmt: don't return zero on failure 2016-03-29 02:11:43 +03:00
Nick Cameron
cfc9f70116 Merge pull request #885 from marcusklaas/empty-trait-type-params
Remove trailing whitespace for fn types /w non-unit return
2016-03-29 08:17:52 +13:00
Nick Cameron
7d66861b82 Merge pull request #882 from marcusklaas/empty-makro-issues
Fix issues with empty macros with curly braces
2016-03-29 08:14:27 +13:00
Marcus Klaas
0142191e51 Remove trailing whitespace for fn types /w non-unit return 2016-03-27 20:40:23 +02:00
Marcus Klaas
0e0cf976c9 Fix issues with empty macros with curly braces 2016-03-27 13:44:40 +02:00
Marcus Klaas
03bf1ceeb9 Fix tuple destructuring in impl fns 2016-03-27 13:07:28 +02:00
Marcus Klaas de Vries
8fd95df54a Merge pull request #868 from rust-lang-nursery/tuple-wide
Don't apply the function args heuristic to tuple lits.
2016-03-24 14:57:24 +01:00
Marcus Klaas de Vries
ca757183fe Merge pull request #864 from Venti-/fn-density
Add option for vertical function argument list
2016-03-22 10:14:04 +01:00
Marcus Klaas de Vries
6f2bb908bb Merge pull request #866 from rust-lang-nursery/empty-extern
Keep empty extern blocks on one line
2016-03-16 18:06:25 +01:00
Connor Brewster
0a665aaceb Fixed nitpicks
Removed unneeded comment
Commented line wrapping conditions
Removed prefix param on `rewrite_associated_type`
Merged `rewrite_associated_static` into `rewrite_static`
Added extra tests
2016-03-15 14:08:12 -06:00
Connor Brewster
a0a5335634 Fixed span_after issue 2016-03-14 20:51:41 -06:00
Connor Brewster
7a6eb2197e Merge branch 'master' of https://github.com/rust-lang-nursery/rustfmt into add-trait-formatting 2016-03-14 20:49:14 -06:00
Connor Brewster
2793b4090c Added tests 2016-03-14 20:05:20 -06:00
Connor Brewster
7ba43ff06e Finished implementing impl and trait type/const 2016-03-14 19:52:07 -06:00
Nick Cameron
9d8ce54428 Don't apply the function args heuristic to tuple lits.
Closes #450
Closes #510
2016-03-14 20:51:06 +13:00
Nick Cameron
96a2f25788 Keep empty extern blocks on one line
Closes #462
2016-03-14 18:55:55 +13:00
Nick Cameron
da65090050 Merge pull request #857 from kamalmarhubi/codemap-ext
utils: Add CodeMapExt extension trait for span_* methods
2016-03-14 18:00:51 +13:00
Ari Koivula
0c8640a84f Fix last comment turning into block comment
This fixes the comment after the last argument in an argument list
being turned into a block comment when it's not necessary.
2016-03-14 02:02:52 +02:00
Ari Koivula
db9d129025 Add Vertical fn_args_density
This adds new option Vertical to fn_args_density, which formats the
list vertically no matter what.
2016-03-14 02:00:21 +02:00
Kamal Marhubi
d82d9fc808 utils: Add CodeMapSpanUtils trait for span_* methods
This commit adds a CodeMapSpanUtils extension trait on CodeMap, and
moves some functions to methods there:
  - span_after
  - span_after_last
  - span_before

This better reflects them being lookup methods on the codemap.
2016-03-13 18:14:07 -04:00
Nick Cameron
17856e8d56 Merge pull request #859 from solidsnack/master
Write non-output to stderr when there is output
2016-03-14 11:13:46 +13:00
Connor Brewster
3163071c75 Updated to latest rustfmt 2016-03-12 11:09:27 -07:00
Connor Brewster
87a5d88aeb Uncommented missed spans check 2016-03-12 10:53:47 -07:00
Connor Brewster
de95b4cefb Removed unneeded pattern matching 2016-03-11 22:50:30 -07:00
Connor Brewster
34651c4f78 Fixed formatting 2016-03-11 22:41:22 -07:00
Connor Brewster
d24c31f74c Added support for associated type rewriting 2016-03-11 22:32:08 -07:00
Connor Brewster
9e583ce7a7 Added where clause formatting 2016-03-11 14:49:11 -07:00
Connor Brewster
35dfcc0078 Adding trait formatting
trait header formatting finished
generic formatting finished
added basic trait bounds formatting
2016-03-11 14:18:30 -07:00
Jason Dusek
867b5074aa Use braces, not parens, for macro def 2016-03-11 00:41:11 -08:00
Jason Dusek
223df90c81 Align arguments 2016-03-11 00:15:26 -08:00
Jason Dusek
d216c358ef Write non-output to stderr when there is output 2016-03-11 00:15:26 -08:00
Amanieu d'Antras
698027c4c4 Fix ordering of "const unsafe fn" 2016-03-09 02:44:01 -08:00
Nick Cameron
93029638a0 Merge pull request #847 from kamalmarhubi/update-syntex_syntax
deps: Update syntex_syntax to 0.29.1
2016-03-09 18:31:02 +08:00
Kamal Marhubi
589dabda2f deps: Update syntex_syntax to 0.29.1 2016-03-02 13:08:21 -05:00
Kamal Marhubi
de1fc319c1 rustfmt: Use struct-like enum variants for Operation 2016-03-02 13:08:08 -05:00
Vincent Esche
a0567d4063 Fix for issue #811 (falsely inserted "::" in paths with parameterized trait cast). 2016-03-01 16:39:43 +01:00
Nick Cameron
65bc5c242d Merge pull request #798 from kamalmarhubi/default-no-todo-warnings
config: Disable report_todo by default
2016-02-15 16:36:58 +13:00
Nick Cameron
160eb73baa reviewer changes 2016-02-15 10:07:19 +13:00
Nick Cameron
d86cfb357a Format all patterns (well, except macros)
Fixes #18
Fixes #672
2016-02-12 14:59:13 +13:00
Kamal Marhubi
14dbac5fd7 config: Use write_mode from config
This commit tidies up handling of `write_mode` by setting it in the
config at the start, and removing the `write_mode` parameter threaded
throughout the formatting process.
2016-02-08 22:52:44 -05:00
Nick Cameron
a6d70547e0 Merge pull request #799 from kamalmarhubi/const-instead-of-static
cleanup: Use const instead of static
2016-02-03 19:26:38 +13:00
Marcus Klaas de Vries
586f525cf1 Merge pull request #780 from sidred/config_path
Add support for the config-path option
2016-02-03 06:12:27 +01:00
Marcus Klaas de Vries
9c969ca6fb Merge pull request #786 from rust-lang-nursery/str-leave
Don't reformat strings if we don't have to.
2016-02-03 06:11:01 +01:00
Marcus Klaas de Vries
e2c8c1cab5 Merge pull request #797 from kamalmarhubi/config-expect
config: Make panic messages more useful
2016-02-03 06:08:34 +01:00
Kamal Marhubi
70c9b55ecb cleanup: Remove documentation of deleted parameter
The `args` parameter was removed in 579fb34.
2016-02-02 12:37:38 -05:00
sid
46242ed10e Add support for the config-path option
Adds a config-path option for rustfmt. If this argument is provided,
it recursively searches the config-path for a rustfmt.toml file.
If file is not found, reverts to searching the file input path for the
config file or uses default options.
2016-02-02 15:08:44 +05:30
Kamal Marhubi
8b601812a6 cleanup: Use const instead of static 2016-02-01 23:40:45 -05:00
Kamal Marhubi
52f98c763b config: Disable report_todo by default 2016-02-01 20:29:44 -05:00
Kamal Marhubi
85d14617ce config: Make panic messages more useful 2016-02-01 18:40:32 -05:00
Kamal Marhubi
0f254bb343 docs: Clarify return type of lookup_project_file 2016-02-01 12:55:12 -05:00
Kamal Marhubi
98726d0a53 bin: Improve error handling in project file lookup
Previously errors were being silently ignored. Eg, if `rustfmt` did not
have permission to read a `rustfmt.toml` file, the default configuration
was used without informing the user.
2016-01-31 10:28:47 -05:00
Marcus Klaas de Vries
edcc4ec6c0 Merge pull request #787 from rust-lang-nursery/mod-empty
Put empty modules on one line
2016-01-31 11:33:49 +01:00
Marcus Klaas de Vries
1d216e1829 Merge pull request #791 from kamalmarhubi/canonicalize-path
bin: Canonicalize path before looking for project file
2016-01-31 11:33:05 +01:00
Kamal Marhubi
7a0d8be405 bin: Canonicalize path before looking for project file 2016-01-31 02:01:54 -05:00
Kamal Marhubi
bd9ad6b0a0 bin: Properly handle a directories named rustfmt.toml
`lookup_project_file` could erroneously find a *directory* named
`rustmfmt.toml` if there was one in its lookup path, and so ignore any
configuration file it should have found further up. The error handling
resulted in this silently using the default configuration.
2016-01-31 01:49:29 -05:00
Nick Cameron
a0e85f9a5f Put empty modules on one line
Fixes #463
2016-01-28 19:53:41 +13:00
Nick Cameron
02302d2800 Don't reformat strings if we don't have to.
Specifically if no line exceeds the allowed width and we aren't moving the string to a new offset
2016-01-28 19:14:08 +13:00
DarkDrek
feb09a42f5 Fix #784 2016-01-27 02:18:05 +01:00
Nick Cameron
4344c51c80 Merge pull request #783 from jwazny/issue-588
Added where_trailing_comma option.
2016-01-26 22:23:05 +13:00
Jeremy Wazny
7297bc320f Limit when we emit a trailing where clause comma. 2016-01-26 16:39:00 +11:00
Jeremy Wazny
d82d3b2cd1 Added where_trailing_comma option.
The default is 'false', since a lot of the time there's only a single
predicate.
2016-01-26 12:42:11 +11:00
Kevin Yeh
f01ed6f507 Format item macros 2016-01-22 13:43:18 -06:00
Nick Cameron
81516fe8ca Merge pull request #745 from markstory/checkstyle-output
RFC implementation of checkstyle output
2016-01-22 17:48:39 +13:00
Mark Story
d8c6f5954a Update checkstyle write mode to take Write arguments.
By accepting Write traits we can write tests using StringBuffer.
2016-01-19 00:23:38 -05:00
Mark Story
5632831bd1 Clean up function names for checkstyle output. 2016-01-14 22:04:24 -05:00
Nick Cameron
f0ca7aec24 Fix an off-by-one error due to the comma in a struct lit field
Also allows splitting the field expression on a new line after the field name.

Fixes #698
2016-01-14 20:26:15 +13:00
Mark Story
add80569ff Use PartialEq/Eq implementation instead of match.
Also cleanup from rebasing onto master.
2016-01-13 21:07:38 -05:00
Mark Story
58410ddd93 Extract checkstyle output into a separate module.
Rename functions a bit now that they are specific to checkstyle output.
2016-01-13 21:03:25 -05:00
Mark Story
3c968e1e38 Update based on pull request feedback.
* Extract duplicated logic.
* Make checkstyle errors into warnings.
2016-01-13 21:02:50 -05:00
Mark Story
de10545906 Encode XML entities. 2016-01-13 21:02:50 -05:00
Mark Story
c3632befb5 Remove unused argument. 2016-01-13 21:02:05 -05:00
Mark Story
309f284dfb Fix formatting errors. 2016-01-13 21:01:27 -05:00
Mark Story
d188854e13 Hack together checkstyle output that compiles.
I'm not sure it does something useful yet though.
2016-01-13 21:01:26 -05:00
Mark Story
0c9f27fe5e Start hacking checkstyle output in.
checkstyle now shows up on the option parser, and the code still
compiles/passes tests. Next up will be outputing the XML to stdout.
2016-01-13 20:59:18 -05:00
Victor M. Suarez
4f8938c616 Allow for setting of write-mode via config file. FIxes #215
Also from @marcusklaas:
 Refactor code output functions

 Specifically, `write_all_files` no longer returns a HashMap. It would sometimes
 contain items, and sometimes be empty. When "fixed" newlines are required, this
 must now be done with a separate call. The tests use this strategy and should now pass!
2016-01-12 18:12:48 -05:00
Marcus Klaas de Vries
ba465e0fc2 Merge pull request #766 from ConnorGBrewster/fix-#489
Added option for tighter punctuation in types. fixes #489
2016-01-12 22:52:34 +01:00
Marcus Klaas de Vries
4cefecb495 Merge pull request #768 from DarkDrek/amend-to-fix-#447
fixes parsing issue #767
2016-01-12 21:53:19 +01:00
Connor Brewster
479b69266b Changed TypeDensity::WhiteSpace to TypeDensity::Wide
Changed eq_str and plus_str assignments to use a match
2016-01-12 13:42:53 -07:00
Marcus Klaas de Vries
b99e8eda29 Merge pull request #757 from ConnorGBrewster/fix-#650
Fix for #650
2016-01-12 21:17:45 +01:00
DarkDrek
937e26d4e1 fixes parsing issue #767 2016-01-12 21:13:59 +01:00
Connor Brewster
d7a3256d40 If where is on the same line as the impl, { is put on the same line fixes #650
factored if clause into a separate function
2016-01-11 21:26:45 -07:00
DarkDrek
4da91e7df2 Handle more possible comment position for if else
Extended the test with the new possiblecomment positions
2016-01-12 03:08:48 +01:00
DarkDrek
b0eb0f5daa Keep comments between if and else blocks. Fixes #447 2016-01-12 03:08:16 +01:00
Connor Brewster
749697d845 Changed is_block_empty to has_body 2016-01-11 14:47:56 -07:00
Connor Brewster
dba2d8afd5 Added option for tighter punctuation in types. fixes #489 2016-01-11 12:26:57 -07:00
Connor Brewster
6b741a7194 Where clause is on same line as fn if fn is empty fix-#760
only applies if fn_empty_single_line is set to true
2016-01-10 22:06:06 -07:00
cassiersg
b236819f72 Merge pull request #756 from cassiersg/missed-comments
Detect (and recover) when comments disappear
2016-01-11 01:16:52 +01:00
Nick Cameron
0badc128f7 Merge pull request #740 from svmnotn/less_tmp_files
stop creating bk files if there are no changes. Fixes #733
2016-01-11 10:45:51 +13:00
Victor M. Suarez
56a3aac2b5 stop creating bk files if there are no changes. Fixes #733 2016-01-10 16:37:13 -05:00
Gaëtan Cassiers
b117d7b2b8 Document comment::*CodeCharKind 2016-01-10 22:04:30 +01:00
Gaëtan Cassiers
598fcdddc3 Fix issue with windows line endings (#717).
The '\r' character wasn't counted in the line length.
2016-01-10 16:25:31 +01:00
Gaëtan Cassiers
9f98f725cb Detect when comments disappear
When the reformatted code doesn't contain the same quantity of comments
as the original code, use the original code instead of the reformatted
code.
This is done for all expressions and `let` statements.

This should be used at the finest grained level possible, to avoid that
a small disappearing comment prevents a big chunk of code to be
reformatted.

Kind of fixes (avoid disappearing comments, but prevents a good
formatting is such case) #285 #225 #563 #743
2016-01-10 15:20:58 +01:00
Seo Sanghyeon
16b348dd9c Add commas after skipped arms when needed 2016-01-08 22:15:54 +09:00
Nick Cameron
bd32589ff5 Merge pull request #747 from Manishearth/clippy
Clippy rustfmt
2016-01-07 20:15:49 +13:00
Manish Goregaokar
ffe9c9d834 Clippy rustfmt 2016-01-07 12:17:22 +05:30
Seo Sanghyeon
f9f7235c1b Trailing commas for wildcard arms 2016-01-06 11:02:01 +09:00
Nick Cameron
d290271db4 Merge pull request #739 from svmnotn/case_insensitive_config_options
ignore case for config enums. Fixes #738
2016-01-05 07:40:03 +13:00
Victor M. Suarez
f6497ca3fb ignore case for config enums. Fixes #738 2016-01-02 20:47:58 -05:00
Sinh Pham
122fc4bc65 Fixed #700, use default color for titles and context in write-mode=diff 2016-01-01 09:14:39 -08:00
Marcus Klaas de Vries
0698f0255a Merge pull request #732 from utkarshkukreti/update-diff-to-0.1.8
Update diff to 0.1.8
2015-12-28 17:45:56 +01:00
Utkarsh Kukreti
15e6b7d335 Add tests for #606. 2015-12-28 17:23:34 +05:30
Marcus Klaas
291aa1b228 Make fn argument formatting more resilient for complex self types 2015-12-27 14:25:37 +01:00
Nick Cameron
71508b310b Merge pull request #728 from marcusklaas/typed-mut-self
format typed mut self
2015-12-27 09:18:20 +13:00
Marcus Klaas
2069abcca4 Reduce dependency on pprust 2015-12-25 20:59:46 +01:00
Marcus Klaas
954dd0869e Preserve mutability for typed self arguments 2015-12-25 19:07:51 +01:00
Marcus Klaas
1e80fd2dcd Prevent incorrect backslash removal in strings 2015-12-25 18:50:40 +01:00
Aleksey Kladov
a70b621607 add option to ignore out of line modules 2015-12-23 17:25:49 +03:00
Jan Likar
a5da67f4c4 Add verbose and quiet flags to cargo-fmt
Quiet mode supresses rustfmt's stdout, verbose mode prints targets that
are going to be formatted.
2015-12-20 04:19:08 +01:00
Nick Cameron
0b5e6d57e5 Merge pull request #710 from JanLikar/master
Remove `--write-mode=replace` from cargo-fmt
2015-12-18 08:43:41 +13:00
Jan Likar
c578ad8df5 Remove --write-mode=replace from cargo-fmt
Since replace is the default rustfmt write mode, there's no need to
call rustfmt with `--write-mode=replace`. As a bonus, it is now also
possible to override the write-mode.
2015-12-17 17:17:43 +01:00
Sean Marshallsay
7f21569351 Fix spelling mistake in cargo-fmt usage string. 2015-12-16 12:18:18 +00:00
Nick Cameron
ecf12778fb Use replace rather than overwrite for cargo fmt 2015-12-16 18:07:59 +13:00
Jan Likar
1e5e290e39 Allow to pass arguments to rustfmt 2015-12-16 04:48:49 +01:00
Jan Likar
360f3efce8 Replace locate-project with read-manifest
Use `cargo read-manifest` instead of `cargo locate-project` to get
a list of files to be formatted.
2015-12-16 02:21:43 +01:00
Jan Likar
623277e7e0 Add cargo-fmt binary
Add a new utility, which formats all readable .rs files in the src
directory of the crate using rustfmt. Both binaries can be installed
using cargo install rustfmt. cargo-fmt can be used as a Cargo
subcommand - cargo fmt.
2015-12-14 15:50:19 +01:00
Nick Cameron
8983037db6 Merge pull request #695 from marcusklaas/string-rewrite-backslash
Prevent backslash stripping in string literals
2015-12-14 07:50:56 +13:00
Marcus Klaas
8cccf45d43 Prevent backslash stripping in string literals 2015-12-12 16:25:01 +01:00
Marcus Klaas
2636fed5f3 Don't panic on function return type rewrite failure 2015-12-12 15:41:10 +01:00
Nick Cameron
f8cb1baadd Add normalise_comments option.
So block comments are not converted to line comments
2015-12-10 09:29:03 +13:00
Nick Cameron
e94bd34a06 cargo upgrade, bug fix, and prepare for packaging 2015-12-08 16:19:23 +13:00
Nick Cameron
585b071aa1 Merge pull request #678 from marcusklaas/length-one-tuplez
Fixed named arguments in bare function types
2015-12-07 09:01:38 +13:00
Nick Cameron
db72e0390c Merge pull request #664 from marcusklaas/fix-reformat-failurez
Don't include failed item rewrites in missed spans
2015-12-07 08:33:02 +13:00
Nick Cameron
f569144bbf Merge pull request #666 from marcusklaas/matches-5000
Break function headers earlier
2015-12-07 08:07:23 +13:00
Nick Cameron
26297c56df Merge pull request #615 from JanLikar/version
Add --version switch
2015-12-07 07:32:16 +13:00
Marcus Klaas
97e4e7e5ba Fixed named arguments in bare function types 2015-12-06 01:11:26 +01:00
Marcus Klaas de Vries
22353ca8c7 Merge pull request #674 from Ms2ger/start
Use starts_with to avoid panics.
2015-12-04 16:37:59 +01:00
Ms2ger
1ed36a3a6b Use starts_with to avoid panics. 2015-12-04 16:10:14 +01:00
Manish Goregaokar
f61ba91c2d Minor clippy fixes 2015-12-04 18:02:19 +05:30
Markus Westerlind
a6b0d475f4 Don't remove where clauses in type aliases 2015-12-02 20:11:17 +01:00
Markus Westerlind
ae9ad7b288 Fix formatting of type aliases where '=' is at or close to the max width 2015-12-02 20:11:10 +01:00
Marcus Klaas de Vries
e677f05805 Merge pull request #659 from Marwes/where_clause
Fix where clauses not taking the width of the line into account
2015-12-02 19:06:24 +01:00
Bryce Van Dyk
74d40c042f Update block checking code 2015-12-02 16:44:40 +13:00
Marcus Klaas
76f303f369 Break function headers earlier
Closes rustfmt#295.
2015-12-01 22:09:37 +01:00
Markus Westerlind
17fd2d073b Add a BraceStyle parameter to rewrite_where_clause
This allow it to exactly calculate if it needs to break the where clause into multiple lines
2015-12-01 19:51:49 +01:00
Bryce Van Dyk
7ce887abcf Update trailing comma match logic, add tests
Updates the traling comma code to attempt to handle multiline non-block bodies when
adding traling commas to blocks. Also add and update tests to cover better
the interactions between trailing commas and wrapping match arms.
2015-12-01 20:10:57 +13:00
Marcus Klaas
0fb9611786 Don't include failed item rewrites in missed spans 2015-11-30 23:12:50 +01:00
Bryce Van Dyk
2a430a8947 Trailing commas for match block arms
Attempt to implement an option for trailing commas for block based match arms (issue
173). Put in place test files to verify this behaviour.
2015-11-30 21:51:20 +13:00
Markus Westerlind
052fddd4dd Use the BraceStyle config to calculate the width for braces in where clasues 2015-11-28 13:59:14 +01:00
Seo Sanghyeon
17c8fb10ea Remove unused imports 2015-11-27 23:38:05 +09:00
Markus Westerlind
937467c358 Fix where clauses not taking the width of the line into account
Fixes #630
2015-11-27 09:27:41 +01:00
Markus Westerlind
0021001a07 Use utils::last_line_width in rewrite_type_alias 2015-11-26 21:28:00 +01:00
Markus Westerlind
c61d6d4c3a Format type aliases
Fixes #486
2015-11-26 21:04:49 +01:00
Nick Cameron
68bc387925 Merge pull request #655 from kyeah/impl-comments
Keep comments in empty impl body
2015-11-26 17:59:22 +13:00
Kevin Yeh
314aff1a33 Reformat trim_newlines 2015-11-25 22:46:11 -06:00
Seo Sanghyeon
2b11d84119 Apply Clippy 2015-11-25 15:39:15 +09:00
Kevin Yeh
f5fac4c54f Fix empty trim_newline panic, add impl macro test 2015-11-24 14:37:31 -06:00
Kevin Yeh
b6dc8a3f76 Keep comments in empty impl bodies 2015-11-24 12:55:32 -06:00
Nick Cameron
d405fdc236 Fix a bug with nested impls 2015-11-24 09:37:52 +13:00
Marcus Klaas de Vries
5a3f5bc1f6 Merge pull request #646 from rust-lang-nursery/mulit-file
Handle multiply-referenced files
2015-11-23 21:35:09 +01:00
Jakko Sikkar
411fa40988 update dependencies and fix compile errors 2015-11-23 20:54:33 +02:00
Nick Cameron
2661592d59 Handle multiply-referenced files
Fixes #645
2015-11-23 15:22:00 +13:00
Nick Cameron
40eb3ea857 Merge pull request #641 from marcusklaas/fix-doc-commentz
Correct doc comment indentation for struct fields
2015-11-23 13:58:19 +13:00
Nick Cameron
e3f39941de Types which can be return types for function types
Fixes #643
2015-11-23 13:55:53 +13:00
Nick Cameron
b577f95e3c Reformatting due to changes 2015-11-23 13:09:00 +13:00
Nick Cameron
9cf8529e33 Implement formatting for impls
Fixes #614
2015-11-23 13:09:00 +13:00
Marcus Klaas
4b4dd170d8 Correct doc comment indentation for struct fields
Fix https://github.com/rust-lang-nursery/rustfmt/issues/572.
2015-11-22 22:55:57 +01:00
Nick Cameron
ba936766c6 Take rustfmt_skip attribute into account on modules
Closes #632
2015-11-23 09:20:53 +13:00
Nick Cameron
b9832f2e9f Merge pull request #638 from marcusklaas/visual-struct-last-comment
Fix last comment for visually formatted struct lits
2015-11-23 07:23:58 +13:00
Marcus Klaas
2b0a25a539 Fix last comment for visually formatted struct lits 2015-11-22 17:41:54 +01:00
Marcus Klaas
840012b5e0 Format bare function types
Fix https://github.com/rust-lang-nursery/rustfmt/issues/616.
Fix https://github.com/rust-lang-nursery/rustfmt/issues/276.
Close https://github.com/rust-lang-nursery/rustfmt/issues/350.
2015-11-22 16:07:38 +01:00
Marcus Klaas
559f00ba99 Fix up indentation of function style paths
Fixes https://github.com/rust-lang-nursery/rustfmt/issues/105.
2015-11-22 14:48:30 +01:00
Marcus Klaas
1b0ae00488 Extract fn rewrite methods from RewriteVisitor 2015-11-22 13:45:51 +01:00
Marcus Klaas de Vries
a871405f45 Merge pull request #633 from marcusklaas/mod-comment
Rewrite module declarations
2015-11-21 21:24:29 +01:00
Marcus Klaas
49e2a146b1 Rewrite module declarations 2015-11-21 21:06:29 +01:00
Marcus Klaas de Vries
2a159e05ac Merge pull request #635 from Marwes/long_field_access
Fix long field accesses not being broken onto separate lines
2015-11-21 21:04:34 +01:00
Markus Westerlind
465662a691 Fix long field accesses not being broken onto separate lines
Fixes #512
2015-11-21 01:05:31 +01:00
Nick Cameron
7809e3bb18 Merge pull request #634 from Marwes/block_comment_crlf
Avoid adding an extra newline after block comments
2015-11-21 12:47:53 +13:00
Markus Westerlind
ad7dc420cd Avoid adding an extra newline after block comments
When block comments were rewritten to line comments they check if a new line needs to be added and adds one if needed. It only checked for '\n' however which would cause a newline to be added even if the comment was ended by "\r\n"
2015-11-20 23:31:05 +01:00
Marcus Klaas
9fe3c08abc Add option to disable (un)wrapping of match arms 2015-11-20 21:50:25 +01:00
Marcus Klaas
7b0cceafee Force chains to adhere to restrictions 2015-11-20 21:09:34 +01:00
Marcus Klaas
6e1f77664d Unwrap match arms that are simple blocks 2015-11-20 21:05:18 +01:00
Marcus Klaas
8f3a29d1a7 Blockify multiline match arms 2015-11-20 21:05:10 +01:00
Nick Cameron
3533f72c45 Merge pull request #618 from zyphrus/master
Comments in structs use appropriate style
2015-11-20 18:14:26 +13:00
Nick Cameron
a15dc3d373 Merge pull request #628 from kyeah/single-line-fn
Single-line Functions
2015-11-20 18:13:03 +13:00
Kevin Yeh
2e9b6dfab4 Combine rewrite_single_line_fn and rewrite_fn 2015-11-19 20:49:24 -06:00
Kevin Yeh
15ec5b2912 Fix empty body format, add fn_empty_single_line option, refactor block tests 2015-11-19 20:45:02 -06:00
Steven Fackler
d7b331bea7 Use argv[0] for usage output
Usage messages traditionally use this as it contains the path that the
user provided to run the executable (e.g. `rustfmt` instead of
`/usr/local/bin/rustfmt`).
2015-11-19 17:56:37 -08:00
David Barnett
b3f41e82fc Use tactic instead of config
Add mixed test
Mixed is unreachable as there is no input combination that could get
to this value
2015-11-20 10:37:00 +13:00
Kevin Yeh
fbd1398c92 Implement Rewrite for ast::Stmt 2015-11-19 14:23:56 -06:00
Kevin Yeh
22837b0748 Combine block utilities 2015-11-19 14:23:56 -06:00
Kevin Yeh
4d7de5a16e Support single-line functions
By default, places functions with empty bodies on one line.
If the function has only one expression or statement that fits on one line, the 'fn_single_line' option can be used.
2015-11-19 14:23:56 -06:00
Nick Cameron
f09aa85798 Merge pull request #619 from SiegeLord/item_brace_style_1
Implement initial option for brace style for non-fn items.
2015-11-20 07:41:12 +13:00
Pavel Sountsov
1056006790 Properly follow the brace styles. 2015-11-18 22:34:14 -08:00
Jan Likar
f85ff8d0e5 Print version of the crate
Print version acquired from Cargo when building. If built using rustc
directly, print X.X.X
2015-11-18 00:56:46 +01:00
Pavel Sountsov
a96a69b708 Comments.
- Move the option
- Add some more tests (don't pass yet)
2015-11-16 23:18:07 -08:00
David Barnett
30aec386f4 Comments in structs use appropriate style
Fixes #491
2015-11-17 11:57:49 +13:00
Jan Likar
1eb38c461e Add -V as a shorthand for --version 2015-11-16 14:52:14 +01:00
Jan Likar
6e063a1430 Add --version switch
Add --version switch, which prints a short hash of the current
commit. Fix #612
2015-11-16 04:37:08 +01:00
Nick Cameron
56a765ef05 Rustup 2015-11-16 14:16:46 +13:00
Pavel Sountsov
8658774ad2 Implement initial option for brace style for non-fn items. 2015-11-15 11:55:18 -08:00
Nick Cameron
f88345c431 Merge pull request #607 from rhoot/native-newline
Adding a "Native" option to newline_style.
2015-11-16 08:25:22 +13:00
Johan Sköld
add37b9c49 Adds a "Native" option to newline_style.
By using it one will get \r\n line endings on Windows, and \n line endings
on other platforms.
2015-11-15 04:16:34 -08:00
Seo Sanghyeon
faff4bc9e8 Add verbose mode 2015-11-15 15:41:41 +09:00
Eli Friedman
2fff041b43 Pass in whether an ast::Path is in an expression context.
This gets rid of a slightly nasty hack involving scanning the source
expression for a ":".
2015-11-14 13:54:57 -08:00
Marcus Klaas de Vries
de599015de Merge pull request #601 from thorbenk/chains_tabbed_indent
Chains tabbed indent
2015-11-14 22:00:11 +01:00
Thorben Kroeger
d4be6a43e9 new config 'chain_indent' 2015-11-14 21:50:40 +01:00
Mika Attila
5b06ed6817 Don't print an unnecessary newline after printing format report
The Display implementation for FormatReport already prints
a newline after every error.

However, if the format report does not contain errors, we
don't want to print an empty newline.

This behavior clutters up the console output with
empty lines when rustfmt is invoked multiple times
(from .e.g a script or cargo-fmt).

So instead of using println! to print the report, we just
use print!.
2015-11-14 19:01:28 +01:00
Nick Cameron
2cf2230002 Merge pull request #596 from marcusklaas/where-indent
Fix brace indentation after where clause
2015-11-14 10:04:04 +13:00
Nick Cameron
fb6faed99b Merge pull request #597 from marcusklaas/method-generix
Fix span issue with generic method calls
2015-11-14 10:03:12 +13:00
Marcus Klaas
c93c771e71 Fix span issue with generic method calls 2015-11-13 14:53:34 +01:00
Marcus Klaas
d32245a13d Fix brace indentation after where clause 2015-11-13 14:31:20 +01:00
Jan Likar
4443c4b7cc Correct some non-idiomatic code 2015-11-13 02:08:57 +01:00
Jan Likar
cb64ab22ec Enable rustfmt to format a list of files
Fix #580 by allowing rustfmt to accept a list of files. This also
enables usage of shell wildcard expansion, although notably this does
not work with cmd.exe on Windows. For example: 'rustfmt *.rs' will
format all rust files in the current working directory.

  - Change usage text to show rustfmt will accept a list of files
  - Change "Using rustfmt config file: {}" message to
    "Using rustfmt config file {} for {}"
  - Change Operation::Format(PathBuf, WriteMode) to
    Operation::Format(Vec<PathBuf>, WriteMode)
  - Loop through Vec<PathBuf>, load config and call 'run' for each path
2015-11-13 01:32:22 +01:00
Marcus Klaas de Vries
b6120b39ab Merge pull request #571 from nrc/semi
Don't strip semi-colons from expressions with non-void type since it …
2015-11-10 08:43:29 +01:00
Jørn Lode
5d07b63ce5 Check if the CWD contains a config (previously it only checked parents) 2015-11-09 21:41:25 +01:00
Marcus Klaas de Vries
e0e24c4e76 Merge pull request #573 from nrc/doom_panic
Format tuple structs better
2015-11-09 20:17:50 +01:00
Nick Cameron
b7d61254a7 Option to disable line breaking in comments
Set to false by default for now, since we are having a lot of problems with comments. We should set to true once we have a better algorithm.
2015-11-10 08:03:01 +13:00
Nick Cameron
bcda2824a2 Format tuple structs better
closes #546
2015-11-09 19:00:04 +13:00
Nick Cameron
3dc0b804f1 Don't strip semi-colons from expressions with non-void type since it can change semantics 2015-11-09 13:23:19 +13:00
Kamal Marhubi
ae13bbcc98 Move config help to dedicated --config-help flag
The existing help output is very verbose, overflowing a 50+ line
terminal. This moves the configuration options to a separate help flag
to make a mistyped command less annoying!
2015-11-07 19:03:25 -05:00
Mitsutaka Mimura
67f0b00112 fix unused variable path warning 2015-11-05 08:14:55 +09:00
Florian Zeitz
2aa35f0f6d Honor "enum_trailing_comma" option. Fixes #556 2015-11-03 23:57:31 +01:00
Johann
154e20a04f Address review concerns 2015-11-03 09:16:33 +01:00
Johann
fcc62cbbe0 Stdin support
Adds support for receiving input from stdin in case no file was
specified. This is useful for editor/IDE integrations and other tooling.

To achieve clean output a new write-mode option called plain was added,
this option is mandatory when using stdin.
2015-11-02 20:45:45 +01:00
Eli Friedman
1c235de97d Fix crash speculatively parsing macro arguments as expressions.
The problem is essentially that if we try to parse a token tree using a
CodeMap different from the one the tree was originally parsed with,
spans become nonsense. Since CodeMaps can't be cloned, we're basically
forced to use the original ParseSess for additional parsing.

Ideally, rustfmt would be a bit more clever and figure out how to parse
macro arguments based on the definition of the macro itself, rather than
just guessing that a particular token sequence looks like an expression,
but this is good enough for now.

Fixes #538.
2015-10-27 23:41:32 -07:00
Nick Cameron
100058f2de Merge pull request #531 from marcusklaas/match-inner-block
Address some issues with multiline patterns in let statements
2015-10-26 06:46:26 +13:00
Marcus Klaas
4fa0b0bc57 Print configuration options once in help message 2015-10-24 16:03:10 +02:00
Marcus Klaas
d122ad5adc Address some issues with multiline patterns in let statements 2015-10-24 13:13:15 +02:00
Ravi Shankar
d135217db2 show rustfmt coverage! 2015-10-24 15:22:37 +05:30
Nick Cameron
29b244b67e Merge pull request #471 from defuz/relative-configfile
Lookup of rustfmt.toml file should be relative from input file
2015-10-24 12:20:54 +13:00
defuz
2ec769709f Lookup rustfmt.toml file is relative from input file, not from current directory 2015-10-24 02:14:12 +03:00
Nick Cameron
efa5df39a5 Merge pull request #530 from marcusklaas/match-inner-block
Bump match inner block indent a level
2015-10-24 11:22:50 +13:00
Nick Cameron
0c1360a77c Merge pull request #529 from marcusklaas/pattern-indent
Fix indentation for enum-style patterns
2015-10-24 11:15:01 +13:00
Nick Cameron
45bcf59bde Merge pull request #528 from marcusklaas/chain-idempotence
Restore idempotence for chain formatting
2015-10-24 11:14:24 +13:00
Alex Crichton
e6b7ad3e39 Ignore #[cfg_attr(rustfmt, rustfmt_skip)] functions
This adds to #[rustfmt_skip] but is usable on stable Rust!
2015-10-23 13:46:14 -07:00
Alex Crichton
26958a1c10 Move option parsing to crates.io-based getopts crate
Should help adding more options in the future as well!
2015-10-23 13:46:14 -07:00
Alex Crichton
579fb34417 Remove dependence on rustc/rustc_driver, use syntex
Instead just parse manually with the `syntex_syntax` crate which is a clone of
libsyntax on crates.io which builds on stable Rust.
2015-10-23 13:46:14 -07:00
Alex Crichton
36abfe5dc2 Remove usage of many unstable features
This removes usage of:

* PathExt
* split_last
* split_last_mut
* catch_panic

The catch_panic one was a little tricky as the ident interner needed to be
cloned across threads (a little unsafely), but it should otherwise be good to
go.
2015-10-23 13:46:14 -07:00
Alex Crichton
cda463275e Use the log/env_logger crates from crates.io 2015-10-23 13:46:14 -07:00
Marcus Klaas
b41965539a Bump match inner block indent a level 2015-10-23 21:39:26 +02:00
Marcus Klaas
ae5d7e6ba4 Fix indentation for enum-style patterns 2015-10-23 20:44:46 +02:00
Marcus Klaas
0bb979bb85 Restore idempotence for chain formatting 2015-10-23 20:37:45 +02:00
Marcus Klaas de Vries
7e76fad1f5 Merge pull request #485 from marcusklaas/floaters2
Deal with floaters
2015-10-22 22:33:24 +02:00
Marcus Klaas
2d267b16d1 Deal with floating links in chains 2015-10-22 22:30:01 +02:00
Eli Friedman
e720218ffb Improve handling of commas after match arms.
Fixes #507. Fixes #508.
2015-10-21 14:35:45 -07:00
Eli Friedman
be9e7dc689 Don't use visit::walk_*. Instead, recurse by hand.
This is much more straightforward to understand given how rustfmt
rewriting works, and it avoids walking into expressions in unexpected
places.

Fixes #513. Fixes #514.
2015-10-21 13:46:13 -07:00
Tim Kuehn
6b4ef7457a Fix doc comment regression and add tests. 2015-10-20 02:13:14 -07:00
Marcus Klaas
e8447a8210 Fix large block comments 2015-10-19 23:06:36 +02:00
Marcus Klaas
3970748f59 Remove overflow indentation 2015-10-19 23:06:36 +02:00
Marcus Klaas
cf0f5ca814 Implement CommentCodeSlices 2015-10-19 23:06:35 +02:00
Marcus Klaas
11756d2ef8 Refactor enum formatting 2015-10-19 21:28:05 +02:00
Marcus Klaas de Vries
754925e132 Merge pull request #484 from marcusklaas/patternz
Format some patterns
2015-10-19 20:20:29 +02:00
Marcus Klaas
ca023ba9b7 Format some patterns 2015-10-19 20:15:36 +02:00
Marcus Klaas
7e0456b852 Format visibility for statics and consts 2015-10-19 20:08:03 +02:00
Marcus Klaas de Vries
8a9bbd9d7c Merge pull request #487 from marcusklaas/konsts-n-statix
Format constants and static variables
2015-10-18 23:03:01 +02:00
Marcus Klaas
3ce425c9ed Factor out common item indentation idiom 2015-10-18 22:59:39 +02:00
Marcus Klaas
8e2a910021 Fix indentation for function arguments 2015-10-18 22:22:41 +02:00
Marcus Klaas
1a7d39041e Format constants and static variables 2015-10-18 21:36:26 +02:00
Nick Cameron
d326a29b4b Merge pull request #479 from marcusklaas/moar-types
Format more type variants
2015-10-18 15:40:11 +13:00
Nick Cameron
d7019ce897 Merge pull request #474 from marcusklaas/fn-indent
Properly indent pub fns in extern blocks
2015-10-18 15:19:32 +13:00
Nick Cameron
51afb3ed10 Merge pull request #475 from marcusklaas/vektorz
Format vec! macro using brackets
2015-10-18 15:17:49 +13:00
Sinh Pham
82a6cca010 Refactor write_snippet 2015-10-17 11:35:47 -07:00
Marcus Klaas
01937061a9 Format more type variants 2015-10-17 16:05:59 +02:00
Marcus Klaas
5407202fdf Properly indent pub fns in extern blocks 2015-10-16 23:05:11 +02:00
Marcus Klaas
a9bd695723 Format vec! macro using brackets 2015-10-16 22:55:42 +02:00
Marcus Klaas
5cc60dca97 Remove unsafe push and pop variants 2015-10-16 18:11:46 +02:00
Marcus Klaas de Vries
dfa8ae4048 Merge pull request #464 from marcusklaas/semicolonz
Force semicolons after break/continue/return. Remove after blocks.
2015-10-15 21:03:38 +02:00
Marcus Klaas
5ca9381d74 Adjust for unified enum variants and structs 2015-10-15 20:37:36 +02:00
Marcus Klaas
b039e3a8c3 Force semicolons after break/continue/return. Remove after blocks. 2015-10-15 19:55:42 +02:00
Marcus Klaas
dba08bf898 Indent uncontinued chains to block level 2015-10-14 19:41:29 +02:00
Gaurav Saxena
7f1fbea8e9 added semicolons for return statements 2015-10-13 02:22:35 -04:00
Marcus Klaas
e6af5d2c83 Use visual block indentation for array literals 2015-10-12 21:14:12 +02:00
Marcus Klaas
b768d27f03 Format variadic arguments 2015-10-11 20:57:44 +02:00
Will Speak
a5081c9832 Fix Build to Compile with 1.5.0-nightly (87cd2c082)
There was an extra, unused, paramter int he match arm which causes an
error when compiling with the latest nightly.
2015-10-10 19:02:25 +01:00
Nick Cameron
aed558fce4 Handle multi-line return types and multi-line tuples
Closes #409
2015-10-10 14:55:31 +13:00
Sinh Pham
f075fd01ab Fix https://github.com/nrc/rustfmt/issues/430 2015-10-08 22:49:16 -07:00
Nick Cameron
3ca8d3677a Merge pull request #429 from marcusklaas/method-calls2
Try "overflowing" the final function argument when it's a closure
2015-10-09 12:27:37 +13:00
Marcus Klaas
ccd404ac6f Try "overflowing" the final function argument when it's a closure
This means that we try formatting the last argument of a function call with block
indentation instead of visual indentation when it is a closure and its first line
fits on the same line as the first arguments.
2015-10-08 23:40:33 +02:00
Marcus Klaas de Vries
e7a6795509 Merge pull request #420 from mwiczer/Issue270
Fix https://github.com/nrc/rustfmt/issues/270
2015-10-08 23:38:04 +02:00
mwiczer
5162282b60 Support pre- and post-comments for enums
Use lists to format enum variants rather than special formatting.
Add tests for enums mostly around block comments.
2015-10-08 17:22:57 -04:00
Marcus Klaas
8daf4c3a31 Prevent panics on list-like macro uses with trailing commas 2015-10-08 22:04:17 +02:00
Marcus Klaas de Vries
915f27f177 Merge pull request #423 from nrc/atrib_bug
Format inner and outer attributes separately.
2015-10-08 19:51:30 +02:00
Jonas Schievink
e68cd08935 Fix typos in config descriptions 2015-10-08 16:13:10 +02:00
Nick Cameron
6600cd341a Format inner and outer attributes separately.
Actually just skips inner attributes, because its a pain to track them, and lets missed spans handle them.

Closes #413
2015-10-08 17:20:19 +13:00
Marcus Klaas de Vries
5eeae3944e Merge pull request #404 from marcusklaas/rewrite-list-fmt
List formatting refactoring
2015-10-06 22:29:52 +02:00
Marcus Klaas
199d40fa55 Increase default function call width limit 2015-10-06 22:27:11 +02:00
Marcus Klaas de Vries
7ea589d7b4 Merge pull request #403 from marcusklaas/casts
Format casts, indices and repeated elements
2015-10-05 19:26:14 +02:00