Skip to content

Commit 21fd6a5

Browse files
committed
Document all the things, ensure it will forever be documented
1 parent 4e2d1fa commit 21fd6a5

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

src/author.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
use hashbrown::HashMap;
22
use std::fmt;
33

4+
/// An author of a git commit.
45
#[derive(Debug)]
56
pub struct Author {
7+
/// Name of the author.
68
pub name: String,
9+
/// Total count of commits by author.
710
pub total_commits: usize,
11+
/// Total count of curses used by author.
812
pub total_curses: usize,
13+
/// HashMap of all the curses the author used.
914
pub curses: HashMap<String, usize>,
1015
}
1116

@@ -20,6 +25,7 @@ impl fmt::Display for Author {
2025
}
2126

2227
impl Author {
28+
/// Initialize a new author from a name.
2329
pub fn new(name: impl Into<String>) -> Self {
2430
Author {
2531
name: name.into(),
@@ -29,6 +35,7 @@ impl Author {
2935
}
3036
}
3137

38+
/// Update a previously used curse or add a new one.
3239
pub fn update_occurrence(&mut self, curse: &str) {
3340
self.curses
3441
.get_mut(curse)
@@ -38,6 +45,7 @@ impl Author {
3845
})
3946
}
4047

48+
/// `git-anger-management` knows if you've been naughty or not
4149
pub fn is_naughty(&self) -> bool {
4250
!self.curses.is_empty()
4351
}

src/core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ lazy_static! {
55
pub static ref CURSES: HashSet<&'static str> = CURSES_FILE.lines().collect();
66
}
77

8+
/// Cleans a string and returns a list containing the cleaned up words.
9+
///
10+
/// Of note here is that the implementation splits on any character that is not
11+
/// a letter, even if it is in the middle of a "word". This should not be a
12+
/// problem.
813
pub fn split_into_clean_words(input: &str) -> impl Iterator<Item = &str> {
914
input
1015
.split(|c: char| !char::is_alphabetic(c))
1116
.filter(|w| !w.is_empty())
1217
}
1318

19+
/// Checks if a word is naughty.
1420
pub fn naughty_word(word: &str) -> bool {
1521
CURSES.contains(&word)
1622
}

src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
2-
//#![deny(missing_docs)]
3-
//#![deny(missing_debug_implementations)]
2+
#![deny(missing_docs)]
3+
#![deny(missing_debug_implementations)]
44
#![forbid(unsafe_code)]
55
#![doc(html_root_url = "https://docs.rs/git-anger-management/0.4.0")]
6-
76
//! # git-anger-management
87
//!
98
//! ## What
109
//!
11-
//! Have you ever wondered how much you or your co-workers actually curse in your
12-
//! commit messages? Worry no more, `git-anger-management` is here to help you.
13-
//! Simply run it against your repository and it'll tell you who is the naughtiest
14-
//! of them all.
10+
//! Have you ever wondered how much you or your co-workers actually curse in
11+
//! your commit messages? Worry no more, `git-anger-management` is here to help
12+
//! you. Simply run it against your repository and it'll tell you who is the
13+
//! naughtiest of them all.
1514
//!
1615
//! ## Why
1716
//!
1817
//! Some times the only way to vent at the ridiculous crap we make is to write
19-
//! really angry commit messages, I do it all the time. And I wanted to know just
20-
//! how angry I get.
18+
//! really angry commit messages, I do it all the time. And I wanted to know
19+
//! just how angry I get.
2120
//!
2221
//! # Installation
2322
//!
2423
//! Make sure you have Rust installed (I recommend installing via
25-
//! [rustup](https://rustup.rs/)), then run `cargo install git-anger-management`.
26-
//! You can now check how naughty you are by running `git anger-management` in the
27-
//! directory where you want to check naughtiness.
24+
//! [rustup](https://rustup.rs/)), then run `cargo install
25+
//! git-anger-management`. You can now check how naughty you are by running `git
26+
//! anger-management` in the directory where you want to check naughtiness.
2827
//!
2928
//! Output should look something like this:
3029
//!

src/repo.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ use author::Author;
22
use hashbrown::HashMap;
33
use std::fmt;
44

5+
/// A simple representation of a git repository.
56
#[derive(Debug)]
67
pub struct Repo {
8+
/// Name of the repository.
79
pub name: String,
10+
/// Count of the total amount of commits in the repository.
811
pub total_commits: usize,
12+
/// Count of the total amount of curses used in the commits.
913
pub total_curses: usize,
14+
/// HashMap of all the naughty words used by the authors.
1015
pub curses: HashMap<String, usize>,
16+
/// HashMap of all the authors that have been committed.
1117
pub authors: HashMap<String, Author>,
1218
}
1319

@@ -22,6 +28,7 @@ impl fmt::Display for Repo {
2228
}
2329

2430
impl Repo {
31+
/// Creates a new and empty repository.
2532
pub fn new(name: impl Into<String>) -> Self {
2633
Repo {
2734
name: name.into(),
@@ -32,6 +39,8 @@ impl Repo {
3239
}
3340
}
3441

42+
/// Checks if an author exists and creates a new author if she/he doesn't
43+
/// exist.
3544
pub fn author(&mut self, author_name: &str) -> &mut Author {
3645
if !self.authors.contains_key(author_name) {
3746
self.authors
@@ -42,6 +51,7 @@ impl Repo {
4251
self.authors.get_mut(author_name).expect("exists")
4352
}
4453

54+
/// Counts all the naughty words used by authors.
4555
pub fn count_curses(&mut self) {
4656
for author in self.authors.values() {
4757
for (curse, count) in &author.curses {

tests/version-numbers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ fn test_readme_deps() {
99
#[test]
1010
fn test_html_root_url() {
1111
assert_html_root_url_updated!("src/lib.rs");
12-
}
12+
}

0 commit comments

Comments
 (0)