Skip to content

Commit 98070af

Browse files
authored
CM-52106 - Add .cycodeignore support (#332)
1 parent af953f3 commit 98070af

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

cycode/cli/files_collector/walk_ignore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from cycode.cli.logger import logger
55
from cycode.cli.utils.ignore_utils import IgnoreFilterManager
66

7-
_SUPPORTED_IGNORE_PATTERN_FILES = { # oneday we will bring .cycodeignore or something like that
7+
_SUPPORTED_IGNORE_PATTERN_FILES = {
88
'.gitignore',
9+
'.cycodeignore',
910
}
1011
_DEFAULT_GLOBAL_IGNORE_PATTERNS = [
1112
'.git',

tests/cli/files_collector/test_walk_ignore.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,22 @@ def _create_mocked_file_structure(fs: 'FakeFilesystem') -> None:
5252
fs.create_file('/home/user/project/.git/HEAD')
5353

5454
fs.create_file('/home/user/project/.gitignore', contents='*.pyc\n*.log')
55+
fs.create_file('/home/user/project/.cycodeignore', contents='*.cs')
5556
fs.create_file('/home/user/project/ignored.pyc')
57+
fs.create_file('/home/user/project/ignored.cs')
5658
fs.create_file('/home/user/project/presented.txt')
5759
fs.create_file('/home/user/project/ignored2.log')
5860
fs.create_file('/home/user/project/ignored2.pyc')
61+
fs.create_file('/home/user/project/ignored2.cs')
5962
fs.create_file('/home/user/project/presented2.txt')
6063

6164
fs.create_dir('/home/user/project/subproject')
6265
fs.create_file('/home/user/project/subproject/.gitignore', contents='*.txt')
66+
fs.create_file('/home/user/project/subproject/.cycodeignore', contents='*.cs')
6367
fs.create_file('/home/user/project/subproject/ignored.txt')
6468
fs.create_file('/home/user/project/subproject/ignored.log')
6569
fs.create_file('/home/user/project/subproject/ignored.pyc')
70+
fs.create_file('/home/user/project/subproject/ignored.cs')
6671
fs.create_file('/home/user/project/subproject/presented.py')
6772

6873

@@ -72,23 +77,27 @@ def test_collect_top_level_ignore_files(fs: 'FakeFilesystem') -> None:
7277
# Test with path inside the project
7378
path = normpath('/home/user/project/subproject')
7479
ignore_files = _collect_top_level_ignore_files(path)
75-
assert len(ignore_files) == 2
76-
assert normpath('/home/user/project/subproject/.gitignore') in ignore_files
80+
assert len(ignore_files) == 4
7781
assert normpath('/home/user/project/.gitignore') in ignore_files
82+
assert normpath('/home/user/project/subproject/.gitignore') in ignore_files
83+
assert normpath('/home/user/project/.cycodeignore') in ignore_files
84+
assert normpath('/home/user/project/subproject/.cycodeignore') in ignore_files
7885

7986
# Test with path at the top level with no ignore files
8087
path = normpath('/home/user/.git')
8188
ignore_files = _collect_top_level_ignore_files(path)
8289
assert len(ignore_files) == 0
8390

84-
# Test with path at the top level with a .gitignore
91+
# Test with path at the top level with ignore files
8592
path = normpath('/home/user/project')
8693
ignore_files = _collect_top_level_ignore_files(path)
87-
assert len(ignore_files) == 1
94+
assert len(ignore_files) == 2
8895
assert normpath('/home/user/project/.gitignore') in ignore_files
96+
assert normpath('/home/user/project/.cycodeignore') in ignore_files
8997

9098
# Test with a path that does not have any ignore files
9199
fs.remove('/home/user/project/.gitignore')
100+
fs.remove('/home/user/project/.cycodeignore')
92101
path = normpath('/home/user')
93102
ignore_files = _collect_top_level_ignore_files(path)
94103
assert len(ignore_files) == 0
@@ -110,19 +119,24 @@ def test_walk_ignore(fs: 'FakeFilesystem') -> None:
110119
path = normpath('/home/user/project')
111120
result = _collect_walk_ignore_files(path)
112121

113-
assert len(result) == 5
122+
assert len(result) == 7
114123
# ignored globally by default:
115124
assert normpath('/home/user/project/.git/HEAD') not in result
116125
assert normpath('/home/user/project/.cycode/config.yaml') not in result
117126
# ignored by .gitignore in project directory:
118127
assert normpath('/home/user/project/ignored.pyc') not in result
119128
assert normpath('/home/user/project/subproject/ignored.pyc') not in result
129+
# ignored by .cycodeignore in project directory:
130+
assert normpath('/home/user/project/ignored.cs') not in result
131+
assert normpath('/home/user/project/subproject/ignored.cs') not in result
120132
# ignored by .gitignore in subproject directory:
121133
assert normpath('/home/user/project/subproject/ignored.txt') not in result
122134
# ignored by .cycodeignore in project directory:
123135
assert normpath('/home/user/project/ignored2.log') not in result
124136
assert normpath('/home/user/project/ignored2.pyc') not in result
125137
assert normpath('/home/user/project/subproject/ignored.log') not in result
138+
# ignored by .cycodeignore in subproject directory:
139+
assert normpath('/home/user/project/ignored2.cs') not in result
126140
# presented after both .gitignore and .cycodeignore:
127141
assert normpath('/home/user/project/.gitignore') in result
128142
assert normpath('/home/user/project/subproject/.gitignore') in result
@@ -133,7 +147,7 @@ def test_walk_ignore(fs: 'FakeFilesystem') -> None:
133147
path = normpath('/home/user/project/subproject')
134148
result = _collect_walk_ignore_files(path)
135149

136-
assert len(result) == 2
150+
assert len(result) == 3
137151
# ignored:
138152
assert normpath('/home/user/project/subproject/ignored.txt') not in result
139153
assert normpath('/home/user/project/subproject/ignored.log') not in result

0 commit comments

Comments
 (0)