Closed jhanley634 closed 1 day ago
This PR implements improvements to the source line counting functionality, focusing on better handling of different file types and comment styles. The changes include refactoring the line counter classes, adding XML file support, and introducing a binary search utility to help debug counting discrepancies.
classDiagram
class LineCounter {
+int blank
+int comment
+int code
+__init__(lines: Iterable[str] | Path)
+_get_line_types(lines: list[str])
+expand_comments(lines: Iterable[str])
}
class XmlLineCounter {
+expand_comments(lines: Iterable[str])
}
class BashLineCounter {
}
class PythonLineCounter {
}
LineCounter <|-- XmlLineCounter
LineCounter <|-- BashLineCounter
LineCounter <|-- PythonLineCounter
class DiscrepancyFinder {
+list[str] lines
+str suffix
+bisect(n: int) int
+_counts_equal(n: int) bool
+_get_both_counts(n: int) tuple[ClocCounts, LineCounter]
}
classDiagram
class DiscrepancyFinder {
+list[str] lines
+str suffix
+bisect(n: int) int
+_counts_equal(n: int) bool
+_get_both_counts(n: int) tuple[ClocCounts, LineCounter]
}
class ClocCounts {
}
class LineCounter {
}
DiscrepancyFinder --> ClocCounts
DiscrepancyFinder --> LineCounter
Change | Details | Files |
---|---|---|
Added XML file type support with dedicated comment handling |
|
src/count/sloc.py src/count/tests/sloc_html_test.py |
Refactored line counter initialization and file type handling |
|
src/count/sloc.py |
Added binary search utility for debugging count discrepancies |
|
src/count/bisect.py |
Updated test suite and dependencies |
|
src/count/tests/sloc_test.py requirements.txt pyproject.toml |
Summary by Sourcery
Enhance the line counting functionality by introducing an
XmlLineCounter
for XML files and refactoring the line counting logic to be more flexible. Add new tests to verify the handling of XML, HTML, and PHP files, and introduce a bisect test to identify discrepancies in line counts.New Features:
XmlLineCounter
class to handle XML file line counting, including support for multiline comments.Enhancements:
get_counts
function that selects the appropriate line counter based on file suffix.LineCounter
class to handle input as either a list of lines or a file path, enhancing its versatility.Tests:
sloc_html_test.py
to verify the functionality of theXmlLineCounter
and its handling of HTML and PHP files.TestBisect
class to test the bisect functionality for identifying discrepancies in line counts.