Skip to content

Commit fb11589

Browse files
Refactor LineCounter: Enhance result building logic to include a 'Total' entry and remove redundant test for no-extension files
1 parent f7a699a commit fb11589

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

extliner/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,25 @@ def count_lines(self, directory: Union[str, Path]) -> Dict[str, Dict[str, int]]:
122122
return self._build_result()
123123

124124
def _build_result(self) -> Dict[str, Dict[str, int]]:
125-
return {
125+
# Build the result dictionary for each extension
126+
result = {
126127
ext: {
127-
"with_spaces": self.with_spaces[ext],
128-
"without_spaces": self.without_spaces[ext],
129-
"file_count": self.file_count[ext],
128+
"with_spaces": self.with_spaces[ext],
129+
"without_spaces": self.without_spaces[ext],
130+
"file_count": self.file_count[ext],
130131
}
131132
for ext in sorted(set(self.with_spaces) | set(self.without_spaces))
133+
if self.with_spaces[ext] > 0 or self.without_spaces[ext] > 0
132134
}
133135

136+
# Add the 'Total' entry at the end
137+
result["Total"] = {
138+
"with_spaces": sum(self.with_spaces.values()),
139+
"without_spaces": sum(self.without_spaces.values()),
140+
"file_count": sum(self.file_count.values()),
141+
}
142+
return result
143+
134144
@staticmethod
135145
def to_json(data: Dict) -> str:
136146
return json.dumps(data, indent=2)

tests/test_linecounter.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ def test_ignore_folder(self):
5959
self.assertIn(".py", result)
6060
self.assertEqual(result[".py"]["with_spaces"], 2) # only visible/script.py counted
6161

62-
def test_no_extension_file(self):
63-
self.create_file("README", "line1\nline2\n")
64-
counter = LineCounter()
65-
result = counter.count_lines(self.base_path)
66-
67-
self.assertIn("no_ext", result)
68-
self.assertEqual(result["no_ext"]["file_count"], 1)
69-
7062
def test_empty_file(self):
7163
self.create_file("empty.py", "")
7264
counter = LineCounter()

0 commit comments

Comments
 (0)