Commit Graph

343 Commits

Author SHA1 Message Date
topecongiro
34b4a9d3c4 Add struct_field_align_threshold for vertical alignment 2017-07-03 18:54:41 +09:00
topecongiro
bd991851c8 Format source codes 2017-07-03 18:54:26 +09:00
topecongiro
7eafad96ad Implement Spanned for ast::StructField and ast::Field 2017-07-03 18:48:21 +09:00
Nick Cameron
5f1bab26c4 Move to Libsyntax 2017-06-14 14:01:56 +12:00
topecongiro
c4d84b44ba Avoid overflow 2017-06-14 00:06:48 +09:00
Nick Cameron
18ccd0190e Rebasing 2017-06-13 14:49:47 +12:00
Nick Cameron
1f512948a0 Reformat source code using new defaults 2017-06-13 14:41:49 +12:00
topecongiro
6e3394e635 Use with_emitter instead of with_tty_emitter 2017-06-13 09:18:14 +09:00
topecongiro
762639e7fd Reset the error count of parser from the previous file 2017-06-10 14:34:50 +09:00
est31
727963afe4 Update syntex_syntax
Bases on commit to switch to libsyntax by @nrc
2017-06-06 07:31:47 +02:00
topecongiro
a9f529cba4 Format source codes 2017-06-04 19:35:29 +09:00
Seiichi Uchida
10c3632078 Format source codes 2017-06-01 12:08:25 +09: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
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
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
d1682b3473 Merge pull request #1510 from fintelia/better-filelines
Better file_lines
2017-05-15 09:19:18 +12:00
topecongiro
2776615dc9 Replace 'try!' with '?' 2017-05-08 13:14:23 +09: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
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
est31
78d4ef1992 Drop rustc-serialize, use serde, update toml dependency 2017-05-03 10:23:50 +02:00
topecongiro
9dc643a6ae Remove TODO from 'format_tuple_struct' 2017-05-01 15:57:08 +09:00
topecongiro
883db2f952 Refactor Shape 2017-05-01 15:57:08 +09:00
Evgeny Duzhakov
bb7b002b23 format_lines: fix line_len for config.max_width 2017-04-18 14:31:53 +03:00
Mike Boutin
a0efdf2de9 Do not count \r as part of line width.
Resolves #1335. Does not attempt to handle a `\r` not followed by a `\n` nor
attempt to handle Unicode intricacies (#6) including zero-width or multi-byte
characters.
2017-04-02 11:09:29 -04:00
Nick Cameron
5305bc8436 test fallout 2017-03-28 11:25:59 +13:00
Nick Cameron
5fb1140688 fallout - source reformatting 2017-03-28 11:14:47 +13:00
Nick Cameron
4bb31a7231 Block indenting for struct lit patterns
Now follows struct_lit_style (and most other struct_lit_ options).

Required a fair bit of refactoring and bug fixes.

Fixes #1311
2017-03-22 09:25:26 +13:00
Nick Cameron
33b83ae7df Formatting fallout
Also fixes a minor bug when we break a line after `if` and used to leave a trailing space
2017-03-07 09:50:41 +13:00
Andy Librian
63114f3cac added unit tests for Indent and Shape (#1353) 2017-03-06 07:50:04 +13:00
Nick Cameron
db10a0b9b2 Merge pull request #1325 from C4K3/master
Add error_on_line_overflow option
2017-02-23 14:46:24 +13:00
Nick Cameron
9eb78a3333 Fallout 2017-02-23 13:15:48 +13:00
Nick Cameron
b35906dbce WIP 2017-02-21 16:35:05 +13:00
Sebastian Blunt
f6ccbd71c3
Add error_on_line_overflow option
Makes it configurable whether to error if unable to get all lines within
the max_width.
2017-02-19 19:56:37 +01:00
Craig M. Brandenburg
f2c867d067 New disable_all_formatting config option (#1297)
* New `disable_all_formatting` config option

* Resolve code review comments
2017-02-07 17:11:47 +13:00
Nick Cameron
428339fdc3 Refactor indent and width into Shape struct 2017-01-31 08:35:23 +13:00
Nick Cameron
e018712612 process cfg'ed off modules
Fixes #1229
Fixes #1277
2017-01-20 08:20:49 +13:00
Stepan Koltsov
1c22d85db5 Better message for LineOverflow error (#1268)
(with current length and configured limit)
2017-01-09 15:57:11 +13:00
Nick Cameron
d3eba76e4d update Serde, etc.
Lots of changes to how closures work
2016-11-21 11:02:18 +13:00
Nick Cameron
4418fab4f2 Update to latest Syntex
+ Cargo update
+ 0.6.2 release
2016-09-16 15:28:02 +12:00
sinkuu
a3c63fdef9 Run clippy 2016-08-29 08:57:27 +09:00
Johann Hofmann
8260d277c8
Return failure exit code on found diffs (fix #906)
This changes rustfmt to return exit code 4
when run with write mode diff and differences between
the formatted code and the original code are found.

Useful for CI to make sure your contributors actually ran rustfmt.
2016-06-21 23:01:15 +02:00
Kamal Marhubi
c311b30cac Add type to represent collection of lines in files
This commit adds a type to represent lines in files, and adds it to the
`Config` struct. It will be used for restricting formatting to specific
lines.

Refs #434
2016-05-31 01:24:38 +02:00
Kamal Marhubi
bd10af127e utils: Move codemap related utilities to a dedicated module
This commit adds a `codemap` module, and moves the `CodemapSpanUtils`
added in #857 to it. This is preparation for adding more `Codemap`
specific utilities.

Refs #434
2016-05-31 00:49:26 +02:00
Kamal Marhubi
7f0d87cc51 Derive Debug for the Input enum 2016-05-31 00:43:48 +02:00
Kamal Marhubi
66cac1f3e9 Handle pub(restricted) (#1013)
* Handle pub(restricted)

This commit properly handles pub(restricted) as introduced in RFC 1422
[0]. The syntax support was added in #971, but they were not correctly
formatted.

[0] https://github.com/rust-lang/rfcs/blob/master/text/1422-pub-restricted.md

Fixes #970

* Drop #[inline] attribute on format_visibility

* Make newly non-failing functions return String

The change to `format_visibiilty` means that `format_header` and
`format_unit_struct` can no longer fail. Their return type is updated to
reflect that.
2016-05-28 00:58:25 +02:00
Nick Cameron
ff3ff5aa87 Handle parser errors better 2016-05-18 09:58:51 +12:00
Nick Cameron
9b05461666 Write each file as it is formatted (#991)
The old behaviour stored everything in memory until we were finished. Now we write as soon as we can.

This gives better behaviour when formatting large programs, since there is some progress indication. It also opens the door to optimising memory use by not storing everything in memory unless it is required (which it still might be). That is left as future work though.
2016-05-15 11:41:05 +02:00
Marcus Klaas
eae2921e14 Bootstrap it. Hard. 2016-05-12 21:50:43 +02:00
Daniel Campbell
4a2db3ec6c Changed modules & visitor mods to public, set filemap::write_file public 2016-05-06 12:44:18 +12:00
Micah Chalmer
70611bf9ac Always skip children when using Plain write mode
Outputting child module contents in the "Plain" write mode does not make
sense, since there is no way to differentiate code that came from a
child module from that which came from the parent file.
2016-04-28 01:44:45 -04:00
Nick Cameron
9188ec0f7f Bail out on recovered errors. (#965)
Closes #915
Closes #930
Closes #931
2016-04-27 21:08:44 +02:00
Aleksey Kladov
847bad603e Don't print empty lines to stderr (#940) 2016-04-15 16:52:21 +02:00
Aleksey Kladov
77350e49b5 return non-zero exit code if there were errors 2016-04-15 02:51:50 +03:00
Aleksey Kladov
b1efb3a39e don't silence error unnecessary
This `if` was used to separate error output from the formatting output, when they both used stdout. It was useful for integration with tools, which can submit input to stdin and read pretty printed result from stdout without worrying about errors intermingled with the actual result. 

But now we write errors to `stderr`, so the problem disappears and we can safely remove this `if`.

Errors should never pass silently, unless explicitly silenced.
2016-04-14 01:39:39 +03:00
Srinivas Reddy Thatiparthy
58b022c56a Change stdout to stderr (#925) 2016-04-13 21:22:45 +02:00
Aleksey Kladov
dc1fc4be0f unify format_string and format_file 2016-04-11 22:56:54 +03:00
Srinivas Reddy Thatiparthy
901c5b1a5d use std::error instead std::out 2016-04-06 23:23:02 +05:30
Aleksey Kladov
c29ee66b94 make naming more consistent 2016-04-05 01:20:14 +03: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
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
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
589dabda2f deps: Update syntex_syntax to 0.29.1 2016-03-02 13:08:21 -05: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
Kamal Marhubi
70c9b55ecb cleanup: Remove documentation of deleted parameter
The `args` parameter was removed in 579fb34.
2016-02-02 12:37:38 -05: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
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
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
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
Aleksey Kladov
a70b621607 add option to ignore out of line modules 2015-12-23 17:25:49 +03:00
Nick Cameron
ecf12778fb Use replace rather than overwrite for cargo fmt 2015-12-16 18:07:59 +13:00
Marcus Klaas
97e4e7e5ba Fixed named arguments in bare function types 2015-12-06 01:11:26 +01:00
Seo Sanghyeon
2b11d84119 Apply Clippy 2015-11-25 15:39:15 +09:00
Nick Cameron
2661592d59 Handle multiply-referenced files
Fixes #645
2015-11-23 15:22:00 +13:00
Marcus Klaas
6e1f77664d Unwrap match arms that are simple blocks 2015-11-20 21:05:18 +01:00
Seo Sanghyeon
faff4bc9e8 Add verbose mode 2015-11-15 15:41:41 +09: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
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
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
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
Marcus Klaas
ca023ba9b7 Format some patterns 2015-10-19 20:15:36 +02:00
Marcus Klaas
199d40fa55 Increase default function call width limit 2015-10-06 22:27:11 +02:00
Marcus Klaas
965ea09664 Split ListTactic decision logic from write_list 2015-10-04 20:40:14 +02:00
Tim Kuehn
6c6e7194c2 Fix 1-tuple regression.
Add test to prevent future regressions.
2015-10-01 11:06:49 -07:00
Marcus Klaas de Vries
afee62e476 Merge pull request #370 from marcusklaas/match-arm-delining
Improve heuristics for match arm body placement
2015-09-27 12:00:57 +02:00
Marcus Klaas
2d4a0cbe3b Fix match arm indentation bug 2015-09-26 23:18:57 +02:00
Nick Cameron
617eed353c Changes to rustfmt source 2015-09-26 18:29:48 +12:00
Nick Cameron
99d71a164a Changes to source formatting 2015-09-26 13:58:12 +12:00
Pavel Sountsov
03e1b27826 Add Indent::none(), remove make_indent. 2015-09-19 10:36:45 -07:00
Pavel Sountsov
d4108a3029 Initial implementation of hard tab indentation. 2015-09-19 10:36:45 -07:00
Marcus Klaas
e72d488281 Refactor test code
No longer use callbacks or thread::catch_panic; reduce stdout spew; guard against rustfmt breaking the column limit.
2015-09-18 22:34:46 +02:00
Marcus Klaas
110f7206e6 Split formatting function from side effects
This makes rustfmt more usable as a library.
2015-09-18 22:31:33 +02:00
Marcus Klaas
f751356910 Format macro invocations 2015-09-16 20:26:14 +02:00
Nick Cameron
a29023a191 Remove a few unnecessary rustfmt_skips 2015-09-15 11:46:27 +12:00
Marcus Klaas
03c660633f Refine chain breaking heuristics
Don't make a single line chain when it is was multi line in the source; allow overflow of the last chain element onto the next lines without breaking the chain.
2015-09-11 00:53:01 +02:00
Marcus Klaas
c680bb4030 Implement basic chain formatting 2015-09-11 00:52:16 +02:00
Sinh Pham
e7a5f9327e Add diff write mode https://github.com/nrc/rustfmt/issues/261 2015-09-10 18:30:07 -04:00
Nick Cameron
8750399ef4 Merge pull request #248 from sinhpham/unicode_string_lit
Unicode string lit
2015-09-07 08:01:06 +12:00
Andre Bogus
d6c652e33c code improvements suggested by clippy 2015-09-04 23:39:33 +02:00
Sinh Pham
61f642f6f8 Support unicode in string literals. 2015-09-03 23:41:25 -04:00
Nick Cameron
fae93abbda Support struct-like layouts for fn args 2015-09-02 09:41:08 +12:00
Marcus Klaas
120fd2426e Format assignment 2015-08-25 21:43:13 +02:00
Nick Cameron
43ad7ad7a0 Re-jig binop formatting
and misc other fixes from the reviews.
2015-08-20 08:18:02 +12:00
Nick Cameron
81f2e449d7 Handle span error with continue
This should be properly addressed by #184, but requires a change to the rustc parser, so this patch just works around the issue.
2015-08-20 08:11:14 +12:00
Nick Cameron
a43e2b5ae8 Formatting 2015-08-20 08:11:14 +12:00
Marcus Klaas
8e22a73cb7 Add option to override single configuration lines for tests 2015-08-19 21:51:03 +02:00
Marcus Klaas
10a80bb8be Add an option to forgo backups 2015-08-19 21:31:27 +02:00
Gaëtan Cassiers
5b5927996f Kill ChangeSet and replace remaining part by FileMap
Also fix style issues
Cargo update to get fixes of strings.rs (was cause of a misformatted
function call).
2015-08-02 13:33:01 +02:00
Gaëtan Cassiers
0eab4bf430 Remove ChangeSet of FmtVisitor 2015-08-02 13:12:51 +02:00
Gaëtan Cassiers
0e10329dc7 Separate modules and files listing of reformatting
As suggested in #141
Closes #156
2015-08-02 13:07:27 +02:00
Nick Cameron
8461e8a0a8 Merge pull request #147 from marcusklaas/even-more-expr
Format if expressions & loops
2015-07-25 09:51:59 +12:00
Marcus Klaas
c4101de53d Refactor some things; add extra tests. 2015-07-24 19:00:14 +02:00
Nick Cameron
c10c732425 Simplify CompilerCalls impl 2015-07-23 08:07:57 +12:00
Marcus Klaas
2fa6220f57 Format all the loops! 2015-07-19 23:43:32 +02:00
Nick Cameron
979d0c9756 Resolve some warnings 2015-07-17 18:26:10 +12:00
Nick Cameron
c3375078e5 Merge pull request #137 from nrc/struct-lit-opt
Options for formatting struct literals
2015-07-17 06:57:01 +12:00
Nick Cameron
9ab1587a98 Don't apologise if its not our fault in warnings 2015-07-16 14:17:07 +12:00
Nick Cameron
7518f68861 Add an option to format struct lits with either block or visual indent 2015-07-16 14:05:05 +12:00
Gaëtan Cassiers
3de366d282 Format modules into separate files 2015-07-03 11:12:21 +02:00
Marcus Klaas
482f200b0b Update import list formatting
Include comments and sort items alphabetically.
2015-06-26 03:43:12 +02:00
Marcus Klaas
0ef5db9496 Format tuple-like structs 2015-06-23 16:54:42 +02:00
Marcus Klaas
d7b49fd76c Remove global mutable config to allow for concurrency 2015-06-23 13:26:04 +02:00
Gaëtan Cassiers
c012d311c4 A basic impl of Rewrite for ast::Expr 2015-06-23 02:15:46 +02:00
Marcus Klaas
5924b83829 Rustup 2015-06-22 14:52:23 +02:00
Marcus Klaas
d335d04575 Implement checks for unnumbered TODOs and FIXMEs 2015-06-12 20:58:23 +02:00
Gaëtan Cassiers
4d6d0b81a7 Fix mod ordering + formatting 2015-06-08 20:23:24 +02:00
Gaëtan Cassiers
adedba45a8 Use impl_enum_decodable for SeparatorTactic 2015-06-08 19:40:22 +02:00
Marcus Klaas
227322ddba Add macro for enum implementations of Decodable 2015-06-04 14:08:32 +02:00
Nick Cameron
e7adf64155 Format structs 2015-05-25 17:07:55 +12:00
Nick Cameron
6a5ef17eb1 Add config.rs which I forgot for the last commit
Closes #73
2015-05-23 22:25:36 +12:00
Nick Cameron
1a09a6d00a Use config file for constants 2015-05-23 17:53:53 +12:00
Alex HotShot Newman
2fbb445b67 Remove old box syntax 2015-05-20 11:20:15 -07:00
Oliver Schneider
cd3b032e11 prevent bogus whitespace error messages due to \r 2015-05-04 14:32:48 +02:00
Oliver Schneider
1655583b02 handle windows newlines 2015-05-04 12:50:24 +02:00
Oliver Schneider
62e583d4cf split main function and test function into their own files
small modifications to make executable and test compile properly
2015-05-01 22:28:58 +02:00
Oliver Schneider
e6e7ce178f main.rs -> lib.rs 2015-05-01 22:24:53 +02:00