Skip to content

Commit

Permalink
Merge branch 'main' into create-pull-request/maintenance-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Jan 8, 2025
2 parents a7f1d71 + bba21dc commit f13b564
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cfnlint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,11 @@ def _ignore_templates(self):
if isinstance(filenames, str):
filenames = [filenames]

return self._glob_filenames(filenames)
return self._glob_filenames(filenames, False)

def _glob_filenames(self, filenames: Sequence[str]) -> list[str]:
def _glob_filenames(
self, filenames: Sequence[str], raise_exception: bool = True
) -> list[str]:
# handle different shells and Config files
# some shells don't expand * and configparser won't expand wildcards
all_filenames = []
Expand All @@ -796,7 +798,8 @@ def _glob_filenames(self, filenames: Sequence[str]) -> list[str]:
add_filenames = glob.glob(filename, recursive=True)

if not add_filenames and not self.ignore_bad_template:
raise ValueError(f"{filename} could not be processed by glob.glob")
if raise_exception:
raise ValueError(f"{filename} could not be processed by glob.glob")

all_filenames.extend(add_filenames)

Expand Down
22 changes: 22 additions & 0 deletions test/unit/module/config/test_config_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ def test_config_expand_ignore_templates(self, yaml_mock):
)
self.assertEqual(len(config.templates), 3)

@patch("cfnlint.config.ConfigFileArgs._read_config", create=True)
def test_config_expand_and_ignore_templates_with_bad_path(self, yaml_mock):
"""Test ignore templates"""

yaml_mock.side_effect = [
{
"templates": ["test/fixtures/templates/bad/resources/iam/*.yaml"],
"ignore_templates": [
"dne/fixtures/templates/bad/resources/iam/resource_*.yaml"
],
},
{},
]
config = cfnlint.config.ConfigMixIn([])

# test defaults
self.assertIn(
str(Path("test/fixtures/templates/bad/resources/iam/resource_policy.yaml")),
config.templates,
)
self.assertEqual(len(config.templates), 4)

@patch("cfnlint.config.ConfigFileArgs._read_config", create=True)
def test_config_merge(self, yaml_mock):
"""Test merging lists"""
Expand Down

0 comments on commit f13b564

Please sign in to comment.