Skip to content

Commit 4d2df05

Browse files
authored
fix: prevent duplicate files when --files-changed-only=false (#164)
I found that the glob pattern for some extensions hit multiple files more than once. ```py pathlib.Path(".").rglob("*.c") # matches demo.c and demo.cpp ``` Worse, the duplicates were being analyzed more than once. So, this offer a performance improvement as well.
1 parent 1b4a252 commit 4d2df05

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cpp_linter/common_fs/file_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def list_source_files(self) -> List[FileObj]:
166166
:returns: A list of `FileObj` objects without diff information.
167167
"""
168168

169-
files = []
169+
files = set()
170170
for ext in self.extensions:
171171
for rel_path in Path(".").rglob(f"*.{ext}"):
172172
for parent in rel_path.parts[:-1]:
@@ -176,8 +176,8 @@ def list_source_files(self) -> List[FileObj]:
176176
file_path = rel_path.as_posix()
177177
logger.debug('"./%s" is a source code file', file_path)
178178
if self.is_source_or_ignored(rel_path.as_posix()):
179-
files.append(FileObj(file_path))
180-
return files
179+
files.add(file_path)
180+
return [FileObj(f) for f in files]
181181

182182

183183
class TidyFileFilter(FileFilter):

0 commit comments

Comments
 (0)