Closed jhanley634 closed 1 week ago
This PR enhances the source line counter (SLOC) implementation by improving language support, refactoring the comment handling logic, and adding new test cases. The changes focus on making the code more robust and supporting additional file types while maintaining compatibility with the cloc tool's counting methodology.
classDiagram
class LineCounter {
+__init__(in_file: Path)
+__str__() str
+_get_line_types(lines: list[str]) Iterable[LineType]
+expand_comments(lines: Iterable[str]) Iterable[str]
+_get_non_blank_lines(lines: Iterable[str]) Iterable[str]
+_do_shebang(lines: list[str]) Iterable[str]
}
class BashLineCounter {
+__init__(in_file: Path, comment_pattern: str = r"^\\s*#")
+expand_comments(lines: Iterable[str]) Iterable[str]
}
LineCounter <|-- BashLineCounter
class PythonLineCounter {
+expand_comments(lines: Iterable[str]) Iterable[str]
}
LineCounter <|-- PythonLineCounter
class ClocCounts {
<<data>>
}
class TestCloc {
+test_last_line_is_blank()
+test_empty_intersection()
+test_count_diverse_file_types()
+SUPPORTED_LANGUAGES: frozenset
+HASH_MEANS_COMMENT_LANGUAGES: frozenset
+SKIP_LANGUAGE: frozenset
+SKIP: frozenset
}
Change | Details | Files |
---|---|---|
Enhanced comment handling and line processing logic |
|
src/count/sloc.py |
Added support for additional file types and comment styles |
|
src/count/tests/sloc_test.py |
Improved test coverage and file handling |
|
src/count/tests/sloc_test.py src/count/cloc.py |
Updated documentation and presentation |
|
talks/2024-11-12-sloc.md |
Summary by Sourcery
Enhance the line counting logic by improving the handling of shebang lines and supporting custom comment patterns in Bash scripts. Refactor the code to use more efficient data structures and expand the test coverage to include a wider range of file types. Update the documentation to clarify the types of line counts.
Enhancements:
Documentation:
Tests: