Skip to content

Commit 75809dd

Browse files
committed
Fix clippy warnings.
1 parent a3b134d commit 75809dd

File tree

7 files changed

+105
-59
lines changed

7 files changed

+105
-59
lines changed

build.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -228,31 +228,31 @@ fn validate_languages(languages: &[Language]) -> Result<()> {
228228
if let Some(ref block_comments) = lang.block_comments {
229229
for (comment_idx, comment_pair) in block_comments.iter().enumerate() {
230230
if comment_pair.len() == 2 {
231-
let (start, end) = (&comment_pair[0], &comment_pair[1]);
232-
if start.is_empty() {
233-
errors.push(format!(
234-
"{} ('{}'), block comment {}: Block comment start cannot be empty",
235-
position,
236-
lang.name,
237-
comment_idx + 1
238-
));
239-
}
240-
if end.is_empty() {
241-
errors.push(format!(
242-
"{} ('{}'), block comment {}: Block comment end cannot be empty",
243-
position,
244-
lang.name,
245-
comment_idx + 1
246-
));
247-
}
248-
} else {
249-
errors.push(format!(
250-
"{} ('{}'), block comment {}: Block comment must have exactly 2 elements (start, end)",
251-
position,
252-
lang.name,
253-
comment_idx + 1
254-
));
255-
}
231+
let (start, end) = (&comment_pair[0], &comment_pair[1]);
232+
if start.is_empty() {
233+
errors.push(format!(
234+
"{} ('{}'), block comment {}: Block comment start cannot be empty",
235+
position,
236+
lang.name,
237+
comment_idx + 1
238+
));
239+
}
240+
if end.is_empty() {
241+
errors.push(format!(
242+
"{} ('{}'), block comment {}: Block comment end cannot be empty",
243+
position,
244+
lang.name,
245+
comment_idx + 1
246+
));
247+
}
248+
} else {
249+
errors.push(format!(
250+
"{} ('{}'), block comment {}: Block comment must have exactly 2 elements (start, end)",
251+
position,
252+
lang.name,
253+
comment_idx + 1
254+
));
255+
}
256256
}
257257
}
258258
}

src/analysis/analyzer.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,37 @@ impl AnalysisOptions {
3434
}
3535
}
3636

37-
pub fn verbose(mut self, verbose: bool) -> Self {
37+
#[must_use]
38+
pub const fn verbose(mut self, verbose: bool) -> Self {
3839
self.verbose = verbose;
3940
self
4041
}
4142

42-
pub fn respect_gitignore(mut self, respect: bool) -> Self {
43+
#[must_use]
44+
pub const fn respect_gitignore(mut self, respect: bool) -> Self {
4345
self.respect_gitignore = respect;
4446
self
4547
}
4648

47-
pub fn include_hidden(mut self, include: bool) -> Self {
49+
#[must_use]
50+
pub const fn include_hidden(mut self, include: bool) -> Self {
4851
self.include_hidden = include;
4952
self
5053
}
5154

52-
pub fn follow_symlinks(mut self, follow: bool) -> Self {
55+
#[must_use]
56+
pub const fn follow_symlinks(mut self, follow: bool) -> Self {
5357
self.follow_symlinks = follow;
5458
self
5559
}
5660

61+
#[must_use]
5762
pub fn path(&self) -> &Path {
5863
&self.path
5964
}
6065

61-
pub fn is_verbose(&self) -> bool {
66+
#[must_use]
67+
pub const fn is_verbose(&self) -> bool {
6268
self.verbose
6369
}
6470
}
@@ -68,7 +74,8 @@ pub struct CodeAnalyzer {
6874
}
6975

7076
impl CodeAnalyzer {
71-
pub fn new(options: AnalysisOptions) -> Self {
77+
#[must_use]
78+
pub const fn new(options: AnalysisOptions) -> Self {
7279
Self { options }
7380
}
7481

src/analysis/line_classifier.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ pub struct CommentState {
1717
}
1818

1919
impl CommentState {
20+
#[must_use]
2021
pub fn new() -> Self {
2122
Self::default()
2223
}
2324

24-
pub fn enter_block(&mut self, nested: bool) {
25+
pub const fn enter_block(&mut self, nested: bool) {
2526
self.in_block_comment = true;
2627
if nested {
2728
self.block_comment_depth = 1;
2829
}
2930
}
3031

31-
pub fn exit_block(&mut self, nested: bool) {
32+
pub const fn exit_block(&mut self, nested: bool) {
3233
if nested {
3334
self.block_comment_depth = self.block_comment_depth.saturating_sub(1);
3435
if self.block_comment_depth == 0 {
@@ -40,11 +41,12 @@ impl CommentState {
4041
}
4142
}
4243

43-
pub fn enter_nested_block(&mut self) {
44+
pub const fn enter_nested_block(&mut self) {
4445
self.block_comment_depth += 1;
4546
}
4647

47-
pub fn is_in_comment(&self) -> bool {
48+
#[must_use]
49+
pub const fn is_in_comment(&self) -> bool {
4850
self.in_block_comment
4951
}
5052
}

src/analysis/stats.rs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub struct FileStats {
1515
}
1616

1717
impl FileStats {
18-
pub fn new(
18+
#[must_use]
19+
pub const fn new(
1920
path: String,
2021
total_lines: u64,
2122
code_lines: u64,
@@ -27,31 +28,38 @@ impl FileStats {
2728
Self { path, total_lines, code_lines, comment_lines, blank_lines, shebang_lines, size }
2829
}
2930

31+
#[must_use]
3032
pub fn path(&self) -> &str {
3133
&self.path
3234
}
3335

34-
pub fn total_lines(&self) -> u64 {
36+
#[must_use]
37+
pub const fn total_lines(&self) -> u64 {
3538
self.total_lines
3639
}
3740

38-
pub fn code_lines(&self) -> u64 {
41+
#[must_use]
42+
pub const fn code_lines(&self) -> u64 {
3943
self.code_lines
4044
}
4145

42-
pub fn comment_lines(&self) -> u64 {
46+
#[must_use]
47+
pub const fn comment_lines(&self) -> u64 {
4348
self.comment_lines
4449
}
4550

46-
pub fn blank_lines(&self) -> u64 {
51+
#[must_use]
52+
pub const fn blank_lines(&self) -> u64 {
4753
self.blank_lines
4854
}
4955

50-
pub fn shebang_lines(&self) -> u64 {
56+
#[must_use]
57+
pub const fn shebang_lines(&self) -> u64 {
5158
self.shebang_lines
5259
}
5360

54-
pub fn size(&self) -> u64 {
61+
#[must_use]
62+
pub const fn size(&self) -> u64 {
5563
self.size
5664
}
5765
}
@@ -81,50 +89,62 @@ impl LanguageStats {
8189
self.file_list.push(file_stats);
8290
}
8391

84-
pub fn files(&self) -> u64 {
92+
#[must_use]
93+
pub const fn files(&self) -> u64 {
8594
self.files
8695
}
8796

88-
pub fn lines(&self) -> u64 {
97+
#[must_use]
98+
pub const fn lines(&self) -> u64 {
8999
self.lines
90100
}
91101

92-
pub fn code_lines(&self) -> u64 {
102+
#[must_use]
103+
pub const fn code_lines(&self) -> u64 {
93104
self.code_lines
94105
}
95106

96-
pub fn comment_lines(&self) -> u64 {
107+
#[must_use]
108+
pub const fn comment_lines(&self) -> u64 {
97109
self.comment_lines
98110
}
99111

100-
pub fn blank_lines(&self) -> u64 {
112+
#[must_use]
113+
pub const fn blank_lines(&self) -> u64 {
101114
self.blank_lines
102115
}
103116

104-
pub fn shebang_lines(&self) -> u64 {
117+
#[must_use]
118+
pub const fn shebang_lines(&self) -> u64 {
105119
self.shebang_lines
106120
}
107121

108-
pub fn size(&self) -> u64 {
122+
#[must_use]
123+
pub const fn size(&self) -> u64 {
109124
self.size
110125
}
111126

127+
#[must_use]
112128
pub fn files_list(&self) -> &[FileStats] {
113129
&self.file_list
114130
}
115131

132+
#[must_use]
116133
pub fn code_percentage(&self) -> f64 {
117134
utils::percentage(self.code_lines, self.lines)
118135
}
119136

137+
#[must_use]
120138
pub fn comment_percentage(&self) -> f64 {
121139
utils::percentage(self.comment_lines, self.lines)
122140
}
123141

142+
#[must_use]
124143
pub fn blank_percentage(&self) -> f64 {
125144
utils::percentage(self.blank_lines, self.lines)
126145
}
127146

147+
#[must_use]
128148
pub fn shebang_percentage(&self) -> f64 {
129149
utils::percentage(self.shebang_lines, self.lines)
130150
}
@@ -155,56 +175,69 @@ impl AnalysisResults {
155175
self.language_stats.entry(language).or_default().add_file(file_stats);
156176
}
157177

158-
pub fn total_files(&self) -> u64 {
178+
#[must_use]
179+
pub const fn total_files(&self) -> u64 {
159180
self.total_files
160181
}
161182

162-
pub fn total_lines(&self) -> u64 {
183+
#[must_use]
184+
pub const fn total_lines(&self) -> u64 {
163185
self.total_lines
164186
}
165187

166-
pub fn total_code_lines(&self) -> u64 {
188+
#[must_use]
189+
pub const fn total_code_lines(&self) -> u64 {
167190
self.total_code_lines
168191
}
169192

170-
pub fn total_comment_lines(&self) -> u64 {
193+
#[must_use]
194+
pub const fn total_comment_lines(&self) -> u64 {
171195
self.total_comment_lines
172196
}
173197

174-
pub fn total_blank_lines(&self) -> u64 {
198+
#[must_use]
199+
pub const fn total_blank_lines(&self) -> u64 {
175200
self.total_blank_lines
176201
}
177202

178-
pub fn total_shebang_lines(&self) -> u64 {
203+
#[must_use]
204+
pub const fn total_shebang_lines(&self) -> u64 {
179205
self.total_shebang_lines
180206
}
181207

182-
pub fn total_size(&self) -> u64 {
208+
#[must_use]
209+
pub const fn total_size(&self) -> u64 {
183210
self.total_size
184211
}
185212

186-
pub fn language_stats(&self) -> &HashMap<String, LanguageStats> {
213+
#[must_use]
214+
pub const fn language_stats(&self) -> &HashMap<String, LanguageStats> {
187215
&self.language_stats
188216
}
189217

218+
#[must_use]
190219
pub fn languages_by_lines(&self) -> Vec<(&String, &LanguageStats)> {
191220
let mut stats_vec: Vec<_> = self.language_stats.iter().collect();
192221
stats_vec.sort_by_key(|(_, lang_stats)| std::cmp::Reverse(lang_stats.lines));
193222
stats_vec
194223
}
195224

225+
#[must_use]
196226
pub fn code_percentage(&self) -> f64 {
197227
utils::percentage(self.total_code_lines, self.total_lines)
198228
}
199229

230+
#[must_use]
200231
pub fn comment_percentage(&self) -> f64 {
201232
utils::percentage(self.total_comment_lines, self.total_lines)
202233
}
203234

235+
#[must_use]
204236
pub fn blank_percentage(&self) -> f64 {
205237
utils::percentage(self.total_blank_lines, self.total_lines)
206238
}
207239

240+
#[must_use]
208241
pub fn shebang_percentage(&self) -> f64 {
209242
utils::percentage(self.total_shebang_lines, self.total_lines)
210243
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
2+
13
pub mod analysis;
24
pub mod cli;
35
pub mod display;

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
2+
13
use anyhow::{Result, ensure};
24
use clap::Parser;
35
use codestats::{

src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pub(crate) fn pluralize<'a>(count: u64, singular: &'a str, plural: &'a str) -> &'a str {
1+
pub const fn pluralize<'a>(count: u64, singular: &'a str, plural: &'a str) -> &'a str {
22
if count == 1 { singular } else { plural }
33
}
44

5-
pub(crate) fn percentage(part: u64, total: u64) -> f64 {
5+
pub fn percentage(part: u64, total: u64) -> f64 {
66
if total == 0 { 0.0 } else { (part as f64 / total as f64) * 100.0 }
77
}

0 commit comments

Comments
 (0)