Skip to content

Commit 9406d47

Browse files
committed
Merge pull request #4 from clog-tool/rustfmt
chore: reformat using rustfmt
2 parents c8b23dd + 0eb4115 commit 9406d47

File tree

8 files changed

+73
-60
lines changed

8 files changed

+73
-60
lines changed

rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn_brace_style = "PreferSameLine"
2+
struct_trailing_comma = "Never"
3+
struct_lit_trailing_comma = "Never"
4+
struct_lit_multiline_style = "ForceMulti"
5+
enum_trailing_comma = false

src/clog.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct Clog {
7070
/// The regex used to get closes issue links
7171
pub closes_regex: Regex,
7272
/// The format to output the changelog in (Defaults to Markdown)
73-
pub out_format: ChangelogFormat,
73+
pub out_format: ChangelogFormat
7474
}
7575

7676
impl fmt::Debug for Clog {
@@ -150,7 +150,7 @@ impl Clog {
150150
git_dir: None,
151151
git_work_tree: None,
152152
regex: regex!(r"^([^:\(]+?)(?:\(([^:\)]*?)?\))?:(.*)"),
153-
closes_regex: regex!(r"(?:Closes|Fixes|Resolves)\s((?:#(\d+)(?:,\s)?)+)"),
153+
closes_regex: regex!(r"(?:Closes|Fixes|Resolves)\s((?:#(\d+)(?:,\s)?)+)")
154154
}
155155
}
156156

@@ -304,7 +304,7 @@ impl Clog {
304304
let cfg_file = if file.as_ref().is_relative() {
305305
debugln!("file is relative");
306306
let cwd = match env::current_dir() {
307-
Ok(d) => d,
307+
Ok(d) => d,
308308
Err(..) => return Err(Error::CurrentDirErr),
309309
};
310310
Path::new(&cwd).join(file.as_ref())
@@ -329,7 +329,7 @@ impl Clog {
329329
let mut toml_outfile = None;
330330
let mut toml_infile = None;
331331
let mut toml_changelog = None;
332-
let mut toml_format= None;
332+
let mut toml_format = None;
333333

334334
if let Ok(ref mut toml_f) = File::open(cfg_file) {
335335
debugln!("Found file");
@@ -345,51 +345,52 @@ impl Clog {
345345

346346
let toml_table = match toml.parse() {
347347
Some(table) => table,
348-
None => {
348+
None => {
349349
return Err(Error::ConfigParseErr);
350350
}
351351
};
352352

353353
let clog_table = match toml_table.get("clog") {
354354
Some(table) => table,
355-
None => {
355+
None => {
356356
return Err(Error::ConfigFormatErr);
357357
}
358358
};
359359

360-
toml_from_latest = clog_table.lookup("from-latest-tag").unwrap_or(&Value::Boolean(false)).as_bool();
360+
toml_from_latest =
361+
clog_table.lookup("from-latest-tag").unwrap_or(&Value::Boolean(false)).as_bool();
361362
toml_repo = match clog_table.lookup("repository") {
362363
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
363-
None => Some("".to_owned())
364+
None => Some("".to_owned()),
364365
};
365366
toml_subtitle = match clog_table.lookup("subtitle") {
366367
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
367-
None => Some("".to_owned())
368+
None => Some("".to_owned()),
368369
};
369370
toml_link_style = match clog_table.lookup("link-style") {
370371
Some(val) => match val.as_str().unwrap_or("github").parse::<LinkStyle>() {
371372
Ok(style) => Some(style),
372-
Err(..) => {
373+
Err(..) => {
373374
return Err(Error::LinkStyleErr);
374375
}
375376
},
376-
None => Some(LinkStyle::Github)
377+
None => Some(LinkStyle::Github),
377378
};
378379
toml_outfile = match clog_table.lookup("outfile") {
379380
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
380-
None => None
381+
None => None,
381382
};
382383
toml_infile = match clog_table.lookup("infile") {
383384
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
384-
None => None
385+
None => None,
385386
};
386387
toml_changelog = match clog_table.lookup("changelog") {
387388
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
388-
None => None
389+
None => None,
389390
};
390391
toml_format = match clog_table.lookup("output-format") {
391392
Some(val) => Some(val.as_str().unwrap_or("").to_owned()),
392-
None => None
393+
None => None,
393394
};
394395
match toml_table.get("sections") {
395396
Some(table) => {
@@ -401,11 +402,11 @@ impl Clog {
401402
self.section_map.insert(sec.to_owned(), alias_vec);
402403
}
403404
}
404-
},
405-
None => ()
405+
}
406+
None => (),
406407
}
407-
},
408-
None => ()
408+
}
409+
None => (),
409410
};
410411
} else {
411412
debugln!("File didn't exist");
@@ -438,7 +439,7 @@ impl Clog {
438439
if let Some(format) = toml_format {
439440
match format.parse::<ChangelogFormat>() {
440441
Ok(val) => self.out_format = val,
441-
Err(..) => return Err(Error::ConfigFormatErr),
442+
Err(..) => return Err(Error::ConfigFormatErr),
442443
}
443444
}
444445

@@ -752,7 +753,7 @@ impl Clog {
752753
pub fn get_commits(&self) -> Commits {
753754
let range = match &self.from[..] {
754755
"" => "HEAD".to_owned(),
755-
_ => format!("{}..{}", self.from, self.to)
756+
_ => format!("{}..{}", self.from, self.to),
756757
};
757758

758759
let output = Command::new("git")
@@ -772,7 +773,7 @@ impl Clog {
772773
.collect()
773774
}
774775

775-
fn parse_raw_commit(&self, commit_str:&str) -> Commit {
776+
fn parse_raw_commit(&self, commit_str: &str) -> Commit {
776777
let mut lines = commit_str.split('\n');
777778

778779
let hash = lines.next().unwrap_or("").to_owned();
@@ -785,8 +786,8 @@ impl Clog {
785786
let component = caps.at(2);
786787
let subject = caps.at(3);
787788
(subject, component, commit_type)
788-
},
789-
None => (Some(""), Some(""), self.section_for("unk").clone())
789+
}
790+
None => (Some(""), Some(""), self.section_for("unk").clone()),
790791
};
791792
let closes = lines.filter_map(|line| self.closes_regex.captures(line))
792793
.map(|caps| caps.at(2).unwrap_or("").to_owned())
@@ -901,7 +902,7 @@ impl Clog {
901902
format!("--git-dir={}", self.git_dir.clone().unwrap().to_str().unwrap())
902903
} else {
903904
// user only supplied a git dir i.e. /home/user/mycode/.git
904-
let mut g = self.git_dir.clone().unwrap();
905+
let mut g = self.git_dir.clone().unwrap();
905906
g.push(".git");
906907
format!("--git-dir={}", g.to_str().unwrap())
907908
}
@@ -959,8 +960,8 @@ impl Clog {
959960
ChangelogFormat::Markdown => {
960961
let mut writer = MarkdownWriter::new(&mut out_buf);
961962
self.write_changelog_with(&mut writer)
962-
},
963-
ChangelogFormat::Json => {
963+
}
964+
ChangelogFormat::Json => {
964965
let mut writer = JsonWriter::new(&mut out_buf);
965966
self.write_changelog_with(&mut writer)
966967
}
@@ -1000,8 +1001,8 @@ impl Clog {
10001001
ChangelogFormat::Markdown => {
10011002
let mut writer = MarkdownWriter::new(&mut file);
10021003
try!(self.write_changelog_with(&mut writer));
1003-
},
1004-
ChangelogFormat::Json => {
1004+
}
1005+
ChangelogFormat::Json => {
10051006
let mut writer = JsonWriter::new(&mut file);
10061007
try!(self.write_changelog_with(&mut writer));
10071008
}
@@ -1048,8 +1049,8 @@ impl Clog {
10481049
ChangelogFormat::Markdown => {
10491050
let mut writer = MarkdownWriter::new(&mut file);
10501051
try!(self.write_changelog_with(&mut writer));
1051-
},
1052-
ChangelogFormat::Json => {
1052+
}
1053+
ChangelogFormat::Json => {
10531054
let mut writer = JsonWriter::new(&mut file);
10541055
try!(self.write_changelog_with(&mut writer));
10551056
}
@@ -1071,8 +1072,8 @@ impl Clog {
10711072
ChangelogFormat::Markdown => {
10721073
let mut writer = MarkdownWriter::new(&mut out_buf);
10731074
try!(self.write_changelog_with(&mut writer));
1074-
},
1075-
ChangelogFormat::Json => {
1075+
}
1076+
ChangelogFormat::Json => {
10761077
let mut writer = JsonWriter::new(&mut out_buf);
10771078
try!(self.write_changelog_with(&mut writer));
10781079
}
@@ -1113,12 +1114,12 @@ impl Clog {
11131114
/// });
11141115
/// ```
11151116
pub fn write_changelog_with<W>(&self, writer: &mut W) -> WriterResult
1116-
where W: FormatWriter {
1117+
where W: FormatWriter {
11171118
debugln!("Writing changelog from writer");
11181119
let sm = SectionMap::from_commits(self.get_commits());
11191120

11201121
try!(writer.write_changelog(self, &sm));
11211122

11221123
Ok(())
11231124
}
1124-
}
1125+
}

src/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ impl fmt::Display for Error {
6060
impl StdError for Error {
6161
fn description(&self) -> &str {
6262
match *self {
63-
Error::ConfigParseErr => "error parsing config file",
63+
Error::ConfigParseErr => "error parsing config file",
6464
Error::ConfigFormatErr => "incorrect format for config file",
65-
Error::CurrentDirErr => "cannot get current directory",
66-
Error::TomlReadErr => "cannot read TOML config file",
67-
Error::LinkStyleErr => "unrecognized link-style field",
68-
Error::CreateFileErr => "cannot create output file",
69-
Error::WriteErr => "cannot write to output file or stream",
70-
Error::UnknownErr => "unknown fatal error",
71-
Error::IoErr => "fatal i/o error with output file"
65+
Error::CurrentDirErr => "cannot get current directory",
66+
Error::TomlReadErr => "cannot read TOML config file",
67+
Error::LinkStyleErr => "unrecognized link-style field",
68+
Error::CreateFileErr => "cannot create output file",
69+
Error::WriteErr => "cannot write to output file or stream",
70+
Error::UnknownErr => "unknown fatal error",
71+
Error::IoErr => "fatal i/o error with output file",
7272
}
7373
}
7474

7575
fn cause(&self) -> Option<&StdError> {
7676
match *self {
77-
_ => None
77+
_ => None,
7878
}
7979
}
8080
}

src/fmt/json_writer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ impl<'a> JsonWriter<'a> {
8484
"\"date\":\"{}\"}},",
8585
date
8686
)
87-
},
88-
Err(_) => {
87+
}
88+
Err(_) => {
8989
write!(
9090
self.0,
9191
"\"date\":null}},",
@@ -95,8 +95,10 @@ impl<'a> JsonWriter<'a> {
9595
}
9696

9797
/// Writes a particular section of a changelog
98-
fn write_section(&mut self, options: &Clog, section: &BTreeMap<&String, &Vec<Commit>>)
99-
-> WriterResult {
98+
fn write_section(&mut self,
99+
options: &Clog,
100+
section: &BTreeMap<&String, &Vec<Commit>>)
101+
-> WriterResult {
100102
if section.len() == 0 {
101103
write!(self.0, "\"commits\":null").unwrap();
102104
return Ok(())
@@ -173,14 +175,14 @@ impl<'a> FormatWriter for JsonWriter<'a> {
173175
debugln!("Writing JSON changelog");
174176
write!(self.0, "{{").unwrap();
175177
if let Some(..) = self.write_header(options).err() {
176-
debugln!("Error writing JSON header");
178+
debugln!("Error writing JSON header");
177179
return Err(Error::WriteErr);
178180
}
179181

180182
write!(self.0, "\"sections\":").unwrap();
181183
let mut s_it = sm.sections.iter().peekable();
182184
if s_it.peek().is_some() {
183-
debugln!("There are sections to write");
185+
debugln!("There are sections to write");
184186
write!(self.0, "[").unwrap();
185187
while let Some((sec, compmap)) = s_it.next() {
186188
debugln!("Writing section: {}", &*sec);

src/fmt/md_writer.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a> MarkdownWriter<'a> {
6464
fn write_header(&mut self, options: &Clog) -> io::Result<()> {
6565
let subtitle = match options.subtitle.len() {
6666
0 => options.subtitle.to_owned(),
67-
_ => format!(" {}", options.subtitle)
67+
_ => format!(" {}", options.subtitle),
6868
};
6969

7070
let version_text = if options.patch_ver {
@@ -82,8 +82,8 @@ impl<'a> MarkdownWriter<'a> {
8282
"<a name=\"{}\"></a>\n{} ({})\n\n",
8383
options.version, version_text, date
8484
)
85-
},
86-
Err(_) => {
85+
}
86+
Err(_) => {
8787
write!(
8888
self.0,
8989
"<a name=\"{}\"></a>\n{} ({})\n\n",
@@ -94,9 +94,14 @@ impl<'a> MarkdownWriter<'a> {
9494
}
9595

9696
/// Writes a particular section of a changelog
97-
fn write_section(&mut self, options: &Clog, title: &str, section: &BTreeMap<&String, &Vec<Commit>>)
98-
-> WriterResult {
99-
if section.len() == 0 { return Ok(()) }
97+
fn write_section(&mut self,
98+
options: &Clog,
99+
title: &str,
100+
section: &BTreeMap<&String, &Vec<Commit>>)
101+
-> WriterResult {
102+
if section.len() == 0 {
103+
return Ok(())
104+
}
100105

101106
if let Err(..) = self.0.write(&format!("\n#### {}\n\n", title)[..].as_bytes()) {
102107
return Err(Error::WriteErr);

src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ pub trait FormatWriter {
5151
/// Writes a changelog from a given `clog::SectionMap` which can be thought of as an "AST" of
5252
/// sorts
5353
fn write_changelog(&mut self, options: &Clog, section_map: &SectionMap) -> WriterResult;
54-
}
54+
}

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Commit {
1414
/// Any issues this commit breaks
1515
pub breaks: Vec<String>,
1616
/// The commit type (or alias)
17-
pub commit_type: String
17+
pub commit_type: String
1818
}
1919

2020
/// A convienience type for multiple commits

src/link_style.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl LinkStyle {
3535
match *self {
3636
LinkStyle::Github => format!("{}/issues/{}", link, issue.as_ref()),
3737
LinkStyle::Gitlab => format!("{}/issues/{}", link, issue.as_ref()),
38-
LinkStyle::Stash => format!("{}", issue.as_ref()) // Stash doesn't support issue links
38+
LinkStyle::Stash => format!("{}", issue.as_ref()),
3939
}
4040
}
4141
}
@@ -58,7 +58,7 @@ impl LinkStyle {
5858
match *self {
5959
LinkStyle::Github => format!("{}/commit/{}", link, hash.as_ref()),
6060
LinkStyle::Gitlab => format!("{}/commit/{}", link, hash.as_ref()),
61-
LinkStyle::Stash => format!("{}/commits/{}", link, hash.as_ref())
61+
LinkStyle::Stash => format!("{}/commits/{}", link, hash.as_ref()),
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)