Skip to content

Commit 632fab4

Browse files
committed
documentation
1 parent 6541be3 commit 632fab4

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

src/checkstyle.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use std::path::Path;
1313

1414
use rustfmt_diff::{DiffLine, Mismatch};
1515

16+
/// The checkstyle header - should be emitted before the output of Rustfmt.
17+
///
18+
/// Note that emitting checkstyle output is not stable and may removed in a
19+
/// future version of Rustfmt.
1620
pub fn header() -> String {
1721
let mut xml_heading = String::new();
1822
xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
@@ -21,6 +25,10 @@ pub fn header() -> String {
2125
xml_heading
2226
}
2327

28+
/// The checkstyle footer - should be emitted after the output of Rustfmt.
29+
///
30+
/// Note that emitting checkstyle output is not stable and may removed in a
31+
/// future version of Rustfmt.
2432
pub fn footer() -> String {
2533
"</checkstyle>\n".to_owned()
2634
}

src/config/file_lines.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct LineRange {
2727
pub hi: usize,
2828
}
2929

30+
/// Defines the name of an input - either a file or stdin.
3031
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
3132
pub enum FileName {
3233
Real(PathBuf),

src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ create_config! {
146146
make_backup: bool, false, false, "Backup changed files";
147147
}
148148

149+
/// Load a config by checking the client-supplied options and if appropriate, the
150+
/// file system (including searching the file system for overrides).
149151
pub fn load_config<O: CliOptions>(
150152
file_path: Option<&Path>,
151153
options: Option<O>,

src/config/options.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ configuration_option_enum! { ReportTactic:
167167
Never,
168168
}
169169

170+
// What Rustfmt should emit. Mostly corresponds to the `--emit` command line
171+
// option.
170172
configuration_option_enum! { EmitMode:
171173
// Emits to files.
172174
Files,
@@ -180,10 +182,11 @@ configuration_option_enum! { EmitMode:
180182
ModifiedLines,
181183
// Checks if a diff can be generated. If so, rustfmt outputs a diff and quits with exit code 1.
182184
// This option is designed to be run in CI where a non-zero exit signifies non-standard code
183-
// formatting.
185+
// formatting. Used for `--check`.
184186
Diff,
185187
}
186188

189+
// Client-preference for coloured output.
187190
configuration_option_enum! { Color:
188191
// Always use color, whether it is a piped or terminal output
189192
Always,
@@ -194,6 +197,7 @@ configuration_option_enum! { Color:
194197
}
195198

196199
impl Color {
200+
/// Whether we should use a coloured terminal.
197201
pub fn use_colored_tty(&self) -> bool {
198202
match self {
199203
Color::Always => true,
@@ -203,6 +207,7 @@ impl Color {
203207
}
204208
}
205209

210+
// How chatty should Rustfmt be?
206211
configuration_option_enum! { Verbosity:
207212
// Emit more.
208213
Verbose,
@@ -322,6 +327,8 @@ impl ::std::str::FromStr for IgnoreList {
322327
}
323328
}
324329

330+
/// Maps client-supplied options to Rustfmt's internals, mostly overriding
331+
/// values in a config with values from the command line.
325332
pub trait CliOptions {
326333
fn apply_to(self, config: &mut Config);
327334
fn config_path(&self) -> Option<&Path>;

src/config/summary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use std::default::Default;
1212
use std::time::{Duration, Instant};
1313

14+
/// A summary of a Rustfmt run.
1415
#[derive(Debug, Default, Clone, Copy)]
1516
pub struct Summary {
1617
// Encountered e.g. an IO error.
@@ -25,7 +26,7 @@ pub struct Summary {
2526
// Failed a check, such as the license check or other opt-in checking.
2627
has_check_errors: bool,
2728

28-
// Formatted code differs from existing code (--check only).
29+
/// Formatted code differs from existing code (--check only).
2930
pub has_diff: bool,
3031

3132
// Keeps track of time spent in parsing and formatting steps.
@@ -106,6 +107,7 @@ impl Summary {
106107
|| self.has_diff)
107108
}
108109

110+
/// Combine two summaries together.
109111
pub fn add(&mut self, other: Summary) {
110112
self.has_operational_errors |= other.has_operational_errors;
111113
self.has_formatting_errors |= other.has_formatting_errors;

src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,38 @@ pub(crate) type FileMap = Vec<FileRecord>;
102102

103103
pub(crate) type FileRecord = (FileName, String);
104104

105+
/// The various errors that can occur during formatting. Note that not all of
106+
/// these can currently be propagated to clients.
105107
#[derive(Fail, Debug)]
106108
pub enum ErrorKind {
107-
// Line has exceeded character limit (found, maximum)
109+
/// Line has exceeded character limit (found, maximum).
108110
#[fail(
109111
display = "line formatted, but exceeded maximum width \
110112
(maximum: {} (see `max_width` option), found: {})",
111113
_0,
112114
_1
113115
)]
114116
LineOverflow(usize, usize),
115-
// Line ends in whitespace
117+
/// Line ends in whitespace.
116118
#[fail(display = "left behind trailing whitespace")]
117119
TrailingWhitespace,
118-
// TODO or FIXME item without an issue number
120+
/// TODO or FIXME item without an issue number.
119121
#[fail(display = "found {}", _0)]
120122
BadIssue(Issue),
121-
// License check has failed
123+
/// License check has failed.
122124
#[fail(display = "license check failed")]
123125
LicenseCheck,
124-
// Used deprecated skip attribute
126+
/// Used deprecated skip attribute.
125127
#[fail(display = "`rustfmt_skip` is deprecated; use `rustfmt::skip`")]
126128
DeprecatedAttr,
127-
// Used a rustfmt:: attribute other than skip
129+
/// Used a rustfmt:: attribute other than skip.
128130
#[fail(display = "invalid attribute")]
129131
BadAttr,
132+
/// An io error during reading or writing.
130133
#[fail(display = "io error: {}", _0)]
131134
IoError(io::Error),
135+
/// The user mandated a version and the current version of Rustfmt does not
136+
/// satisfy that requirement.
132137
#[fail(display = "Version mismatch")]
133138
VersionMismatch,
134139
}
@@ -204,6 +209,9 @@ impl FormattingError {
204209
}
205210
}
206211

212+
/// Reports on any issues that occurred during a run of Rustfmt.
213+
///
214+
/// Can be reported to the user via its `Display` implementation of `print_fancy`.
207215
#[derive(Clone)]
208216
pub struct FormatReport {
209217
// Maps stringified file paths to their associated formatting errors.
@@ -266,10 +274,13 @@ impl FormatReport {
266274
.sum()
267275
}
268276

277+
/// Whether any warnings or errors are present in the report.
269278
pub fn has_warnings(&self) -> bool {
270279
self.warning_count() > 0
271280
}
272281

282+
/// Print the report to a terminal using colours and potentially other
283+
/// fancy output.
273284
pub fn fancy_print(
274285
&self,
275286
mut t: Box<term::Terminal<Output = io::Stderr>>,
@@ -758,6 +769,8 @@ pub enum Input {
758769
Text(String),
759770
}
760771

772+
/// The main entry point for Rustfmt. Formats the given input according to the
773+
/// given config. `out` is only necessary if required by the configuration.
761774
pub fn format_input<T: Write>(
762775
input: Input,
763776
config: &Config,

0 commit comments

Comments
 (0)