From 4ab40091d8b15e72a1a38e071bd7bf6f7682388c Mon Sep 17 00:00:00 2001 From: Dmytro Lynda Date: Tue, 26 Aug 2025 17:12:46 +0200 Subject: [PATCH 1/2] CM-52106 - Add .cycodeignore support --- cycode/cli/files_collector/walk_ignore.py | 1 + tests/cli/files_collector/test_walk_ignore.py | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cycode/cli/files_collector/walk_ignore.py b/cycode/cli/files_collector/walk_ignore.py index 35855ff4..261d90ac 100644 --- a/cycode/cli/files_collector/walk_ignore.py +++ b/cycode/cli/files_collector/walk_ignore.py @@ -6,6 +6,7 @@ _SUPPORTED_IGNORE_PATTERN_FILES = { # oneday we will bring .cycodeignore or something like that '.gitignore', + '.cycodeignore', } _DEFAULT_GLOBAL_IGNORE_PATTERNS = [ '.git', diff --git a/tests/cli/files_collector/test_walk_ignore.py b/tests/cli/files_collector/test_walk_ignore.py index 12b9d428..ffcf46cb 100644 --- a/tests/cli/files_collector/test_walk_ignore.py +++ b/tests/cli/files_collector/test_walk_ignore.py @@ -52,17 +52,22 @@ def _create_mocked_file_structure(fs: 'FakeFilesystem') -> None: fs.create_file('/home/user/project/.git/HEAD') fs.create_file('/home/user/project/.gitignore', contents='*.pyc\n*.log') + fs.create_file('/home/user/project/.cycodeignore', contents='*.cs') fs.create_file('/home/user/project/ignored.pyc') + fs.create_file('/home/user/project/ignored.cs') fs.create_file('/home/user/project/presented.txt') fs.create_file('/home/user/project/ignored2.log') fs.create_file('/home/user/project/ignored2.pyc') + fs.create_file('/home/user/project/ignored2.cs') fs.create_file('/home/user/project/presented2.txt') fs.create_dir('/home/user/project/subproject') fs.create_file('/home/user/project/subproject/.gitignore', contents='*.txt') + fs.create_file('/home/user/project/subproject/.cycodeignore', contents='*.cs') fs.create_file('/home/user/project/subproject/ignored.txt') fs.create_file('/home/user/project/subproject/ignored.log') fs.create_file('/home/user/project/subproject/ignored.pyc') + fs.create_file('/home/user/project/subproject/ignored.cs') fs.create_file('/home/user/project/subproject/presented.py') @@ -72,23 +77,27 @@ def test_collect_top_level_ignore_files(fs: 'FakeFilesystem') -> None: # Test with path inside the project path = normpath('/home/user/project/subproject') ignore_files = _collect_top_level_ignore_files(path) - assert len(ignore_files) == 2 - assert normpath('/home/user/project/subproject/.gitignore') in ignore_files + assert len(ignore_files) == 4 assert normpath('/home/user/project/.gitignore') in ignore_files + assert normpath('/home/user/project/subproject/.gitignore') in ignore_files + assert normpath('/home/user/project/.cycodeignore') in ignore_files + assert normpath('/home/user/project/subproject/.cycodeignore') in ignore_files # Test with path at the top level with no ignore files path = normpath('/home/user/.git') ignore_files = _collect_top_level_ignore_files(path) assert len(ignore_files) == 0 - # Test with path at the top level with a .gitignore + # Test with path at the top level with ignore files path = normpath('/home/user/project') ignore_files = _collect_top_level_ignore_files(path) - assert len(ignore_files) == 1 + assert len(ignore_files) == 2 assert normpath('/home/user/project/.gitignore') in ignore_files + assert normpath('/home/user/project/.cycodeignore') in ignore_files # Test with a path that does not have any ignore files fs.remove('/home/user/project/.gitignore') + fs.remove('/home/user/project/.cycodeignore') path = normpath('/home/user') ignore_files = _collect_top_level_ignore_files(path) assert len(ignore_files) == 0 @@ -110,19 +119,24 @@ def test_walk_ignore(fs: 'FakeFilesystem') -> None: path = normpath('/home/user/project') result = _collect_walk_ignore_files(path) - assert len(result) == 5 + assert len(result) == 7 # ignored globally by default: assert normpath('/home/user/project/.git/HEAD') not in result assert normpath('/home/user/project/.cycode/config.yaml') not in result # ignored by .gitignore in project directory: assert normpath('/home/user/project/ignored.pyc') not in result assert normpath('/home/user/project/subproject/ignored.pyc') not in result + # ignored by .cycodeignore in project directory: + assert normpath('/home/user/project/ignored.cs') not in result + assert normpath('/home/user/project/subproject/ignored.cs') not in result # ignored by .gitignore in subproject directory: assert normpath('/home/user/project/subproject/ignored.txt') not in result # ignored by .cycodeignore in project directory: assert normpath('/home/user/project/ignored2.log') not in result assert normpath('/home/user/project/ignored2.pyc') not in result assert normpath('/home/user/project/subproject/ignored.log') not in result + # ignored by .cycodeignore in subproject directory: + assert normpath('/home/user/project/ignored2.cs') not in result # presented after both .gitignore and .cycodeignore: assert normpath('/home/user/project/.gitignore') in result assert normpath('/home/user/project/subproject/.gitignore') in result @@ -133,7 +147,7 @@ def test_walk_ignore(fs: 'FakeFilesystem') -> None: path = normpath('/home/user/project/subproject') result = _collect_walk_ignore_files(path) - assert len(result) == 2 + assert len(result) == 3 # ignored: assert normpath('/home/user/project/subproject/ignored.txt') not in result assert normpath('/home/user/project/subproject/ignored.log') not in result From 88479793f985876b2a50e83372d05c18d61c681a Mon Sep 17 00:00:00 2001 From: Dmytro Lynda Date: Tue, 26 Aug 2025 17:33:22 +0200 Subject: [PATCH 2/2] CM-52106 - Clean up a redundant comment --- cycode/cli/files_collector/walk_ignore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cycode/cli/files_collector/walk_ignore.py b/cycode/cli/files_collector/walk_ignore.py index 261d90ac..f0e8edd6 100644 --- a/cycode/cli/files_collector/walk_ignore.py +++ b/cycode/cli/files_collector/walk_ignore.py @@ -4,7 +4,7 @@ from cycode.cli.logger import logger from cycode.cli.utils.ignore_utils import IgnoreFilterManager -_SUPPORTED_IGNORE_PATTERN_FILES = { # oneday we will bring .cycodeignore or something like that +_SUPPORTED_IGNORE_PATTERN_FILES = { '.gitignore', '.cycodeignore', }