Skip to content

Commit fead1ab

Browse files
fix: πŸ› Fix check command (#56)
1 parent 9f2b392 commit fead1ab

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

β€Žcodelimit/commands/check.pyβ€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
from pygments.util import ClassNotFound
88

99
from codelimit.common.CheckResult import CheckResult
10-
from codelimit.common.Configuration import Configuration
11-
from codelimit.common.Scanner import is_excluded, scan_file
10+
from codelimit.common.Scanner import is_excluded, scan_file, generate_exclude_spec
1211
from codelimit.common.lexer_utils import lex
1312
from codelimit.languages import Languages
1413

1514

1615
def check_command(paths: list[Path], quiet: bool):
1716
check_result = CheckResult()
18-
excludes_spec = PathSpec.from_lines("gitignore", Configuration.exclude)
17+
excludes_spec = generate_exclude_spec(Path.cwd())
1918
for path in paths:
2019
if path.is_file():
2120
_handle_file_path(path, check_result, excludes_spec)
@@ -25,7 +24,7 @@ def check_command(paths: list[Path], quiet: bool):
2524
dirs[:] = [d for d in dirs if not d[0] == "."]
2625
for file in files:
2726
abs_path = Path(os.path.join(root, file))
28-
rel_path = abs_path.relative_to(path.absolute())
27+
rel_path = abs_path.relative_to(Path.cwd())
2928
if is_excluded(rel_path, excludes_spec):
3029
continue
3130
check_file(abs_path, check_result)

β€Žcodelimit/common/Scanner.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def scan_path(path: Path, cached_report: Union[Report, None] = None,
8383
add_file_entry_callback: Union[Callable[[SourceFileEntry], None], None] = None,
8484
) -> Codebase:
8585
result = Codebase(str(path.resolve().absolute()))
86-
excludes_spec = _generate_exclude_spec(path)
86+
excludes_spec = generate_exclude_spec(path)
8787
for root, dirs, files in os.walk(path.absolute()):
8888
files = [f for f in files if not f[0] == "."]
8989
dirs[:] = [d for d in dirs if not d[0] == "."]
@@ -180,7 +180,7 @@ def scan_file(tokens: list[Token], language: Language) -> list[Measurement]:
180180
return measurements
181181

182182

183-
def _generate_exclude_spec(root: Path) -> PathSpec:
183+
def generate_exclude_spec(root: Path) -> PathSpec:
184184
excludes = DEFAULT_EXCLUDES.copy()
185185
excludes.extend(Configuration.exclude)
186186
gitignore_excludes = _read_gitignore(root)

β€Žtests/common/test_Scanner.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test_is_excluded():
8686
excludes_spec = PathSpec.from_lines("gitignore", DEFAULT_EXCLUDES)
8787

8888
assert is_excluded(Path("venv/foo/bar.py"), excludes_spec)
89+
assert is_excluded(Path("tests/test_utils.py"), excludes_spec)
8990
assert not is_excluded(Path("foo/bar.py"), excludes_spec)
9091

9192
excludes_spec = PathSpec.from_lines("gitignore", ["output"])

0 commit comments

Comments
Β (0)