Commit Graph

361 Commits

Author SHA1 Message Date
Otavio Salvador
0279b7d02c Replace isatty crate with atty
The `isatty` crate has been deprecated and a replacement has been
released for it called `atty`. It offers a nicer API and the code
change to adapt is trivial.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2018-10-08 14:39:16 -03:00
Seiichi Uchida
6e901c8f37 Format and update test 2018-09-30 08:05:45 +09:00
Nick Cameron
88f3b32e43 Remove unnecessary feature flag 2018-09-25 18:23:17 +12:00
Seiichi Uchida
6aae9d870f Remove an unnecessary attribute 2018-08-26 13:20:07 +09:00
cad97
fc1909d311 Reformat 2018-08-23 17:14:19 -04:00
cad97
04d804c365 Rename CodeMap/FileMap to SourceMap/SourceFile
#2946
2018-08-23 17:10:46 -04:00
Nick Cameron
43f178bd58 Remove Summary 2018-07-24 21:45:15 +12:00
Nick Cameron
d3288841ea Refactoring: factor format_lines and format_project into smaller chunks 2018-07-24 15:17:47 +12:00
Nick Cameron
2af1ed109c Refactoring: factor out format_file and FormatHandler
This effectively separates out formatting from other handling.
2018-07-24 14:05:04 +12:00
Nick Cameron
b9c6754d8c Refactoring: move format_project and Timer out of Session 2018-07-24 10:08:41 +12:00
Nick Cameron
069c4fc508 Refactoring: summary
Move the timer from Summary to Session.

Move Summary from config to formatting.
2018-07-24 08:43:30 +12:00
Nick Cameron
09a8c6d22b Refactoring: move code around in formatting
To try and make cleaner abstractions and to start to separate formatting from
other tasks.
2018-07-24 08:26:33 +12:00
Nick Cameron
71d3d04270 factor out a Session object 2018-07-23 15:37:34 +12:00
Nick Cameron
4153e66e42 Move non-public API from lib.rs to its own module 2018-07-23 12:45:41 +12:00
Nick Cameron
b085113cbe Trigger an internal error if we skip formatting due to a lost comment 2018-07-20 16:05:19 +12:00
Nick Cameron
b27d544478 replace_with_system_newlines doesn't need to be public 2018-07-18 09:16:51 +12:00
Nick Cameron
d911b640d1
Merge pull request #2823 from fwalch/default-newline-style
Change default newline style to "Native"
2018-07-17 11:18:10 +12:00
Nick Cameron
b68fd9e6bf Move pair handling to its own module 2018-07-12 21:37:28 +12:00
Seiichi Uchida
60ce411b53 Format async closure 2018-07-09 23:20:53 +09:00
Florian Walch
363363d066 test: Assert CRLF line endings on Windows 2018-07-02 23:43:59 +02:00
Shohei Wada
036244cdce Fix #2728. 2018-06-19 20:51:49 +09:00
Seiichi Uchida
0ec1533054
Merge pull request #2779 from thibaultdelor/stableApi
Improve end lines handling
2018-06-11 11:38:26 +09:00
Tibo Delor
2e90c4314c
Stop delaying Trailing whitespace error reporting 2018-06-10 14:19:09 +10:00
Tibo Delor
42efae5944
Clean Up code where last whitspace tracking isn't used 2018-06-10 14:07:33 +10:00
Tibo Delor
6b00b8b302
Move newline logic inside the formatting process.
Why?:
 - Conceptually it sounds right
 - Absolutely all write modes where doing it anyway
 - It was done several times in some in case
 - It greatly simplify the code
2018-06-10 00:25:47 +10:00
Tibo Delor
8c32a9d909
Parse Error return an Error instead of a successful empty response 2018-06-10 00:25:06 +10:00
Seiichi Uchida
c95fa8cbe2 Return None when the formatting of macro failed in format_snippet 2018-06-07 12:33:33 +09:00
Seiichi Uchida
d1477ca1de Add a field in Summary for notiyfing about formatting failure of macro 2018-06-07 12:32:58 +09:00
Nick Cameron
173ae0d7b9 0.8.2 2018-05-28 11:47:21 +12:00
Nick Cameron
632fab4c95 documentation 2018-05-21 15:54:56 +12:00
Nick Cameron
6541be3c6f Replace use_colored_tty with iatty crate 2018-05-21 15:32:27 +12:00
Nick Cameron
9a7fac63c8 Remove format_and_emit_report from the API
Also changes the header/footer stuff
2018-05-21 15:09:17 +12:00
Nick Cameron
95d6b64829 Replace WriteMode with EmitMode and backup bool 2018-05-21 14:14:09 +12:00
Nick Cameron
843c12601a Use our own FileName struct rather than exporting libsyntax's 2018-05-21 12:08:39 +12:00
Nick Cameron
539d4d9665 Refactor CliOptions 2018-05-21 11:27:25 +12:00
Nick Cameron
abb253df8b Rationalise result and error types 2018-05-21 08:58:53 +12:00
Nick Cameron
432b1cb253 Rationalise error types
cc #2639
2018-05-21 08:58:53 +12:00
Nick Cameron
760af6cfc9 Make format_snippet and format_code_block private
cc #2639
2018-05-21 08:58:53 +12:00
Nick Cameron
1452349966 Exit with 1 for license check in --check mode
Closes #2707
2018-05-18 15:30:32 +12:00
Nick Cameron
390a284851 Give a deprecation warning on rustfmt_skip and an error on rustfmt:: other than skip 2018-05-14 18:10:46 +12:00
Nick Cameron
51f566062f Update uses of rustfmt_skip to rustfmt::skip 2018-05-14 16:25:10 +12:00
Nick Cameron
6d0695303a Make some write modes unstable 2018-05-14 10:55:16 +12:00
Nick Cameron
5d9f5aa05a Replace --write-mode with --emit
cc #1976
2018-05-13 14:13:24 +12:00
Nick Cameron
8396da1882 Add --backup flag 2018-05-13 13:18:08 +12:00
Nick Cameron
4d9de48e06 Add --check flag.
cc #1976
2018-05-11 20:26:00 +12:00
Nick Cameron
55ac062da0 Add --quiet flag, remove Plain write mode
cc #1976
2018-05-11 13:50:30 +12:00
Nick Cameron
5dba81bbbf
Merge pull request #2687 from Marwes/issue_2641
fix: Don't insert an extra brace in macros with native newlines
2018-05-09 13:18:27 +12:00
Markus Westerlind
4c9ef93df7 fix: Don't insert an extra brace in macros with native newlines
Due to `format_snippet` formatting the input with \r\n the subtraction
would wouldn't give a length that removed the }

Fixes #2641
2018-05-08 20:34:44 +02:00
topecongiro
bd25c7d0f7 Cargo fmt 2018-05-08 06:25:48 +09:00
Nick Cameron
4bbd5c4ae5
Merge pull request #2681 from topecongiro/issue-2680
Error on self_tests when there are lines that exceed max width
2018-05-07 11:20:33 +12:00
topecongiro
51c07f4335 Fix up lines exceeding max width 2018-05-06 16:17:09 +09:00
topecongiro
1f738ea208 Cargo fmt 2018-05-06 15:22:29 +09:00
Nick Cameron
d8982e5efe Suppress warning about unused attribute 2018-05-02 10:18:14 +12:00
Ryan Leung
fb9a5add9b add rustc_target to dependencies (#2660) 2018-04-28 16:08:58 +09:00
Tibo
b7df23c3d5
Replace completely std::error with failure crate 2018-04-26 13:48:48 +10:00
Tibo
5581be2616
Use failure for FormattingError 2018-04-26 12:18:30 +10:00
Seiichi Uchida
ac8ae00625
Cargo update and clippy (#2643) 2018-04-25 07:21:23 +09:00
Nick Cameron
866900449a Make some more stuff private
0.6
2018-04-20 22:10:48 +12:00
Nick Cameron
ca610d35b3 Refactor to make a sensible public API
0.5 - lots of breaking changes

cc #2639
2018-04-20 21:52:02 +12:00
David Barsky
f9532ba8d7 Implemented rough draft of check write mode. (#2539)
* Add rough draft of `check` mode. Not unit tested.

* Added assert-cli; simple test case for `--write-mode=check`

* Lightly documented `check` WriteMode

* wrote clearer phrasing for config::options::WriteMode::Check

* Implemented default for WriteMode where default is Overwrite

* Simplified exit code handling

* updated README.md as per @nrc' comment

* collapsed exit-code handling

* Removed write_mode from Summary, introduced partial option parsing earlier

* Handle write-mode parsing in a slightly better way.
2018-04-20 11:14:11 +12:00
Seiichi Uchida
8b731db6ba Output xml header and footer only once 2018-04-12 13:45:12 +09:00
Nick Cameron
f14671131e Make error_on_line_overflow false by default
And improve docs, the error message, etc.

I think false is the better default since such errors should only occur due to a bug in Rustfmt and therefore most users should not be notified of it happening (although to be clear, it might be a 'bug' which only occurs with pathological input and therefore we won't fix it). The error has proven to be confusing and annoying in the past.

Closes #1080
2018-04-09 16:47:55 +12:00
Nick Cameron
b7ba6f70b1
Merge pull request #2576 from topecongiro/merge-imports
Use normalized form to format use items
2018-04-05 17:39:22 +12:00
Seiichi Uchida
ec1907b2a4 Do not indent or unindent inside string literal
Closes #2588.
2018-04-05 12:52:43 +09:00
Shotaro Yamada
ed46a777c8 Use str::repeat 2018-04-01 22:29:26 +09:00
Seiichi Uchida
f6c0a0f4ed Cargo fmt 2018-03-31 14:23:40 +09:00
Taylor Cramer
72d8c9143b Allow stabilization of match_default_bindings 2018-03-26 22:29:01 +02:00
Nick Cameron
ff9ab51617
Merge pull request #2550 from sinkuu/chars_count_index
Don't index a string with chars().count()/position()
2018-03-22 16:26:48 +13:00
Nick Cameron
0bc0241d2a
Merge pull request #2548 from topecongiro/match-mod
Do not collapse block around expr with condition on match arm
2018-03-22 15:40:36 +13:00
Shotaro Yamada
4757321277 Don't index a string with chars().count() 2018-03-22 08:33:18 +09:00
Seiichi Uchida
88589f2ad8 Add matches module
`matches` module contains `rewrite_match` and related stuffs.
2018-03-21 22:21:08 +09:00
Nick Cameron
bf9f175336 reviewer comments and rebase fallout 2018-03-20 09:27:31 +13:00
Nick Cameron
50c95a074a cargo fmt 2018-03-20 09:27:31 +13:00
topecongiro
a03b3b7d6f Cargo update
Remove `rustc-ap-rustc_errors` from dependencies since it
is re-exported from `rustc-ap-syntax`.
2018-03-16 08:52:36 +09:00
Seiichi Uchida
eda626cfc9 Call syntax::with_globals before using a parser 2018-03-15 18:55:52 +09:00
Nick Cameron
a0e063a6e1
Merge pull request #2522 from topecongiro/ignore-config-option
Add ignore config option
2018-03-12 16:25:31 +13:00
Nick Cameron
bcaeab7a5e
Merge pull request #2527 from topecongiro/issue-2526
Check whether '\\'' is char literal or lifetime
2018-03-12 11:25:40 +13:00
Nick Cameron
af5d3cc87b
Merge pull request #2524 from topecongiro/issue-2523
Do not unindent code block in comments with unformattable macro
2018-03-12 11:21:09 +13:00
Seiichi Uchida
86a427fe32 Check whether '\\'' is char literal or lifetime 2018-03-10 01:19:38 +09:00
topecongiro
eaab592cb8 Avoid unindenting code block in comment with unformattable macro
`format_code_block` formats the given `code_snippet` by enclosing it inside
`fn main` block. Previously we did not add indentation to the `code_snippet`
before formatting it. This works fine as long as we can format the given
`code_snippet`, but when the code block has unformattable macro, they gets
unindented. This commit fixes it by adding proper indentation before formatting
the `code_snippet`.

For example, when formatting the following code block,

```rust
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
```

previously we enclosed it like this:

```rust
fn main() {
some_macro!(pub fn foo() {
    println!("Don't unindent me!");
});
}
```

with this PR, we will enclose it like this:

```rust
fn main() {
    some_macro!(pub fn foo() {
        println!("Don't unindent me!");
    });
}
```

Closes #2523.
2018-03-09 17:10:20 +09:00
Seiichi Uchida
ae629abc41 Add overflow module
This commit adds `overflow` module. This module provides two APIs.
`rewrite_with_parens` is basically the same as `rewrite_call_inner`.
`rewrite_with_angle_brackets` is used for rewriting generics and types.
2018-03-09 14:07:43 +09:00
Seiichi Uchida
84ad70c151 Add ignore config option
For example, with the following config file, rustfmt will ignore `src/types.rs`,
`src/foo/bar.rs` and every file under `examples/` directory.

```toml
[ignore]
files = [
    "src/types.rs",
    "src/foo/bar.rs",
]
directories = [
    "examples",
]
```
2018-03-09 13:37:52 +09:00
Nick Cameron
1780d68761 Catch panics in the parser before they crash rustfmt
Closes #753
2018-03-09 14:59:52 +13:00
Seiichi Uchida
a6b574bfa7 Cargo update and cargo clippy 2018-03-08 18:10:23 +09:00
David Lukes
ad76741bca Move license template parsing into config phase 2018-03-05 13:13:55 +01:00
David Lukes
d012d52b4d Parse template with state machine instead of regex
This allows occurrences of `{` and `}` within `{}` placeholders in the
template, and also for having literal `{` and `}` in the template by
means of escaping (`\{`).

Unbalanced, unescaped `}` at the toplevel is a syntax error which
currently triggers a panic; I'll add proper error handling as I move the
license template parsing code into the config parsing phase.
2018-03-05 13:11:21 +01:00
David Lukes
2eebe614c7 Attempt at checking for license (#209)
I'm not quite sure how best to handle loading the license template from
a path -- I mean obviously I know *how* to do it, but I'm not sure where
to fit it in the codebase :) So this first attempt puts the license
template directly into the config file.

These are my misgivings about the license template config option as a
path to a file (I'd love feedback if some of these are wrong or can be
easily circumvented!):

1. I thought the obvious choice for the type of `license_template` in
`create_config!` should be `PathBuf`, but `PathBuf` doesn't implement
`FromStr` (yet? see https://github.com/rust-lang/rust/issues/44431), so
it would have to be wrapped in a tuple struct, and I went down that road
for a little while but then it seemed like too much ceremony for too
little gain.

2. So a plain `String` then (which, mind you, also means the same
`doc_hint()`, i.e. `<string>`, not `<path>` or something like that). The
fact that it's a valid path will be checked once we try to read the
file.

3. But where in the code should the license template be read? The
obvious choice for me would be somewhere in `Config::from_toml()`, but
since `Config` is defined via the `create_config!` macro, that would
mean tight coupling between the macro invocation (which defines the
configuration option `license_template`) and its definition (which would
rely on the existence of that option to run the template loading code).

4. `license_template` could also be made a special option which is
hardwired into the macro. This gets rid of the tight coupling, but
special-casing one of the config options would make the code harder to
navigate.

5. Instead, the macro could maybe be rewritten to allow for config
options that load additional resources from files when the config is
being parsed, but that's beyond my skill level I'm afraid (and probably
overengineering the problem if it's only ever going to be used for this
one option).

6. Finally, the file can be loaded at some later point in time, e.g. in
`format_lines()`, right before `check_license()` is called. But to
face a potential *IO* error at so late a stage, when the source files
have already been parsed... I don't know, it doesn't feel right.

BTW I don't like that I'm actually parsing the license template as late
as inside `check_license()` either, but for much the same reasons, I
don't know where else to put it. If the `Config` were hand-rolled
instead of a macro, I'd just define a custom `license_template` option
and load and parse the template in the `Config`'s init. But the way
things are, I'm a bit at a loss.

However, if someone more familiar with the project would kindly provide
a few hints as to how the path approach can be done in a way that is as
clean as possible in the context of the codebase, I'll be more than
happy to implement it! :)
2018-03-05 13:11:21 +01:00
Nick Cameron
4f522794ae Tidy up and pass tests 2018-03-02 15:07:13 +13:00
Nick Cameron
39301ae5f2 Go back to a non-workspace structure
Kinda reverts https://github.com/rust-lang-nursery/rustfmt/pull/2419
2018-03-02 14:58:23 +13:00
topecongiro
4af2aa3a9e Create rustfmt_core crate 2018-02-07 22:48:05 +09:00
Nick Cameron
c9e250a1ab
Merge pull request #2417 from topecongiro/issue-2415
Avoid orphan in chain with punctuation
2018-02-06 21:23:14 +13:00
topecongiro
5e0c6f9716 Avoid orphan in chain with punctuation 2018-02-06 09:36:29 +09:00
topecongiro
7f949a5018 Explicitly disable colored output when it is not supported 2018-02-06 09:29:00 +09:00
Seiichi Uchida
f815858420 Use correct offset when unindenting code block
When using hard tabs, we should only remove '\t'.
2018-02-04 17:21:10 +09:00
Nick Cameron
7c3a422742 Update libsyntax crates 2018-02-02 14:18:30 +13: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
4c9ab8b405 Cargo fmt with modules reordering enabled 2018-01-29 22:00:07 +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
Seiichi Uchida
dfc67a5df7 Cargo clippy 2018-01-26 14:53:28 +09:00