pub struct LocCounter { /* private fields */ }Expand description
Counts lines of code using a consistent methodology across all analysis modes.
§Line Counting Rules
- Physical Lines: Raw line count from file
- Code Lines: Lines containing executable code (excludes comments, blanks)
- Comment Lines: Lines that are primarily comments
- Blank Lines: Lines containing only whitespace
§File Filtering
Files are excluded if they match:
- Test file patterns:
*_test.rs,tests/**/* - Generated file markers:
@generated,DO NOT EDIT - Custom exclusion patterns from config
§Examples
use debtmap::metrics::loc_counter::LocCounter;
use std::path::Path;
let counter = LocCounter::default();
let count = counter.count_file(Path::new("src/lib.rs")).unwrap();
println!("Code lines: {}", count.code_lines);Implementations§
Source§impl LocCounter
impl LocCounter
Sourcepub fn new(config: LocCountingConfig) -> Self
pub fn new(config: LocCountingConfig) -> Self
Create a new LOC counter with custom configuration
Sourcepub fn count_file(&self, path: &Path) -> Result<LocCount, Error>
pub fn count_file(&self, path: &Path) -> Result<LocCount, Error>
Count lines in a single file with auto-detected language (Spec 201)
Sourcepub fn count_content(&self, content: &str) -> LocCount
pub fn count_content(&self, content: &str) -> LocCount
Count lines in file content (pure function) - backward compatible
Uses conservative comment detection (Unknown language).
For accurate counting, use count_content_with_language instead.
Sourcepub fn count_content_with_language(
&self,
content: &str,
language: Option<LocLanguage>,
) -> LocCount
pub fn count_content_with_language( &self, content: &str, language: Option<LocLanguage>, ) -> LocCount
Count lines in file content with language-aware comment detection (Spec 201)
This method correctly handles:
- Multi-line block comments (
/* ... */) - Nested block comments in Rust
- Rust attributes (
#[...]) as code, not comments - Python
#comments
Sourcepub fn should_include(&self, path: &Path) -> bool
pub fn should_include(&self, path: &Path) -> bool
Determine if file should be included in LOC count
Sourcepub fn is_test_file(&self, path: &Path) -> bool
pub fn is_test_file(&self, path: &Path) -> bool
Check if path is a test file
Sourcepub fn is_generated(&self, path: &Path) -> bool
pub fn is_generated(&self, path: &Path) -> bool
Check if path is a generated file
Sourcepub fn count_from_file_paths(&self, files: &[PathBuf]) -> ProjectLocCount
pub fn count_from_file_paths(&self, files: &[PathBuf]) -> ProjectLocCount
Count LOC for an entire project from file metrics
This ensures each file is counted exactly once by using a HashMap to track unique files.
Trait Implementations§
Source§impl Clone for LocCounter
impl Clone for LocCounter
Source§fn clone(&self) -> LocCounter
fn clone(&self) -> LocCounter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LocCounter
impl Debug for LocCounter
Source§impl Default for LocCounter
impl Default for LocCounter
Source§fn default() -> LocCounter
fn default() -> LocCounter
Auto Trait Implementations§
impl Freeze for LocCounter
impl RefUnwindSafe for LocCounter
impl Send for LocCounter
impl Sync for LocCounter
impl Unpin for LocCounter
impl UnsafeUnpin for LocCounter
impl UnwindSafe for LocCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EnsureExt<T> for T
impl<T> EnsureExt<T> for T
Source§fn ensure<P, E>(self, predicate: P, error: E) -> Validation<T, NonEmptyVec<E>>where
P: Predicate<T>,
fn ensure<P, E>(self, predicate: P, error: E) -> Validation<T, NonEmptyVec<E>>where
P: Predicate<T>,
Source§fn ensure_with<P, E, F>(
self,
predicate: P,
error_fn: F,
) -> Validation<T, NonEmptyVec<E>>
fn ensure_with<P, E, F>( self, predicate: P, error_fn: F, ) -> Validation<T, NonEmptyVec<E>>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more