Commit Graph

251 Commits

Author SHA1 Message Date
Nick Cameron
b3a4ba570e Merge pull request #1432 from topecongiro/parse-config
Print error and usage when decoding config file failed
2017-04-06 11:30:33 +12:00
topecongiro
6af0968511 Change return type of 'from_toml' from 'Config' to 'Result<Config>'
Closes #1426.
2017-04-03 13:58:46 +09:00
Nick Cameron
20395c5c55 Merge pull request #1430 from fintelia/stdin_lines
The --file_lines argument now supports "stdin"
2017-04-03 08:27:35 +12:00
Jonathan Behrens
6241469a69 Warn about extra files listed in file_lines argument 2017-03-31 13:34:53 -04:00
Jonathan Behrens
56da223dc2 --file_lines argument now supports "stdin" 2017-03-30 19:35:58 -04:00
Emil Gardström
6971b4b5c9 Implemented support for workspaces
closes rust-lang-nursery/rustfmt#1244
2017-03-30 03:29:32 +02: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
e4efa22983 Source formatting fallout 2017-03-28 10:58:41 +13:00
Nick Cameron
488c0b9546 Test and source fallout 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
Nick Cameron
a7612cc773 more fallout 2017-02-23 13:15:48 +13:00
Nick Cameron
ba1202f6b3 test fallout 2017-02-23 13:15:48 +13:00
Casey Rodarmor
4f939ddf0c Don't print config file by default (#1313)
Supress `Using rusftmt config file...` messages unless the --verbose
flag is given.
2017-02-13 12:50:10 +13:00
Ivan Ukhov
56e0c463d5 Process build scripts 2017-01-25 08:29:48 +01:00
Jason Dusek
22ddc36b17 Recognize "rlib" and "cdylib" crates (#1238)
Addresses #828 and https://github.com/lunaryorn/emacs-module.rs/issues/4 and probably numerous others.
2016-12-16 08:56:15 -10:00
Nick Cameron
d3eba76e4d update Serde, etc.
Lots of changes to how closures work
2016-11-21 11:02:18 +13:00
Mason Smith
764100361e cargo-fmt processes bench, test, example files 2016-11-02 02:28:06 -07:00
sinkuu
a3c63fdef9 Run clippy 2016-08-29 08:57:27 +09:00
Daniel Campoverde
6380937b59 Multiple config file names feature (#1101)
* Add multiple configuration file names feature

* Add '.rustfmt.toml' in README file

* Clean up configuration file code

* Make config file names constant

* Use only one blank line
2016-08-01 09:32:35 +12:00
Nick Cameron
ffa5a22d1c Merge pull request #1084 from johannhof/rustfmt-not-found
Show more helpful error if rustfmt is not in PATH.
2016-07-04 21:30:52 +12:00
Johann Hofmann
033741246c
Show more helpful error if rustfmt is not in PATH.
This fixes #1071.
2016-07-04 07:42:18 +02:00
Nick Cameron
ddda46d265 rustup 2016-07-04 15:46:58 +12: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
5361f61110 Include git commit and worktree status in version output (#1060)
This will help in debugging issues as rustfmt gets more users.

If the working tree is clean, output looks like

    $ target/debug/rustfmt -V
    0.5.0 (9f5ed3b)

If the working tree is dirty, output looks like

    $ target/debug/rustfmt -V
    0.5.0 (9f5ed3b worktree dirty)

If git is unavailable, output looks like

    $ target/debug/rustfmt -V
    0.5.0 (git commit unavailable)

To avoid rebuilds on changing tests, the build script will only rerun if
files under src/ are changed. This means the actual git status may show
changed files and this would not show up in the version. This should not
be an issue as files not in src/ should not affect the build output.
2016-06-12 10:38:03 +02:00
Kamal Marhubi
bef5d095a4 rustfmt: Add option to specify line ranges for formatting
This commit adds the `--experimental-file-lines` option to rustfmt. This
allows specifying line ranges to format from the command line.

Refs #434
2016-05-31 01:33:58 +02:00
Nick Cameron
a9c3108c9c Change defaults and update tests and source
New defaults are `Tabbed` for `chain_indent` and `chain_base_indent`, and `5` for `closure_block_indent_threshold`.
2016-04-22 19:18:48 +12:00
Nick Cameron
9761cf71d8 Tests 2016-04-22 18:53:39 +12:00
Kamal Marhubi
27c91ee35b rustfmt: Parse options once instead of once per file argument (#944)
`update_config()` was parsing the `write-mode` option once for each file
argument. This commit parses them once up front into a `CliOptions`
struct, which is then applied to the config before calling `run()`.
2016-04-16 22:34:15 +02:00
Aleksey Kladov
77350e49b5 return non-zero exit code if there were errors 2016-04-15 02:51:50 +03:00
Kamal Marhubi
72427356eb rustfmt: Simplify match in project file lookup loop
This commit changes the match in `lookup_project_file` to use pattern
guards.
2016-04-10 18:42:55 -04:00
Kamal Marhubi
fe5fa874da rustfmt: Make error handling more idiomatic
This commit replaces the `Operation::InvalidInput` variant with
`Result`, and uses the `try!()` macro instead of explicit matching.
2016-04-10 17:58:14 -04:00
Kamal Marhubi
b55e50f387 rustfmt: Move getopts::Options creation to its own function 2016-04-10 17:57:44 -04:00
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
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
84fb2f402e refactor: unify run and run_from_stdin 2016-04-02 22:24:38 +03: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
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
Kamal Marhubi
de1fc319c1 rustfmt: Use struct-like enum variants for Operation 2016-03-02 13:08:08 -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
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
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
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
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
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
26297c56df Merge pull request #615 from JanLikar/version
Add --version switch
2015-12-07 07:32:16 +13:00
Manish Goregaokar
f61ba91c2d Minor clippy fixes 2015-12-04 18:02:19 +05:30
Marcus Klaas
6e1f77664d Unwrap match arms that are simple blocks 2015-11-20 21:05:18 +01: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
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
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
Seo Sanghyeon
faff4bc9e8 Add verbose mode 2015-11-15 15:41:41 +09: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
Jørn Lode
5d07b63ce5 Check if the CWD contains a config (previously it only checked parents) 2015-11-09 21:41:25 +01: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
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
Marcus Klaas
4fa0b0bc57 Print configuration options once in help message 2015-10-24 16:03:10 +02:00
Ravi Shankar
d135217db2 show rustfmt coverage! 2015-10-24 15:22:37 +05:30
defuz
2ec769709f Lookup rustfmt.toml file is relative from input file, not from current directory 2015-10-24 02:14:12 +03: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
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
Scyptnex
00b314618d Refactoring configuration 2015-09-29 09:38:19 +10: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
Aaron Lobb
d773580715 Changed ConfigType trait to only return a string of variants, rather than a vec 2015-09-14 13:43:55 -07:00
Aaron Lobb
cd9e9b5db0 Merged config imports 2015-09-14 13:06:09 -07:00
Aaron Lobb
8b808de6ff Fixed https://github.com/nrc/rustfmt/issues/291; added output to --help runtime option with possible config values 2015-09-14 00:29:15 -07:00
Marcus Klaas
749a9689be Break chains that don't start with path expressions 2015-09-11 00:52:57 +02:00
Sinh Pham
e7a5f9327e Add diff write mode https://github.com/nrc/rustfmt/issues/261 2015-09-10 18:30:07 -04:00
Christoph Burgdorf
56183ce0e9 fix outdated help text 2015-09-04 21:28:37 +02:00
Mika Attila
1f974fca01 Simplify match expression 2015-08-28 23:51:26 +02:00
Mika Attila
ce25165450 Don't pass --write-mode argument to rustc
Fixes regression introduced by
660f41865b
2015-08-28 13:12:27 +02:00
Mika Attila
660f41865b Only exit after running all destructors and flushing stdout 2015-08-28 10:39:58 +02:00
Alex HotShot Newman
39538a0c77 Fix usage of the tool. Provide -h and --help 2015-08-26 15:07:01 -07:00
Simon Bernier St-Pierre
9ead47151e Add project-specific configuration file support 2015-08-25 19:05:30 -04:00
Marcus Klaas
10a80bb8be Add an option to forgo backups 2015-08-19 21:31:27 +02:00
Alex Newman
2f4ef7dd1e Provide information about default.toml 2015-08-18 11:35:18 -07:00
Marcus Klaas
5924b83829 Rustup 2015-06-22 14:52:23 +02:00
Nick Cameron
1a09a6d00a Use config file for constants 2015-05-23 17:53:53 +12:00
Marcus Klaas
4aa3518703 Format required methods on traits 2015-05-12 02:37:05 +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