-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support module paths in append_rules (#1216)
* Add RulesCollection.create_from_module * Support appending rules from a module * Update README w/ new append_rules module support
- Loading branch information
Showing
10 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
from cfnlint.rules import CloudFormationLintRule # pylint: disable=E0401 | ||
|
||
class CustomRule1(CloudFormationLintRule): | ||
""" Def Rule """ | ||
id = 'E9001' | ||
shortdesc = 'Custom Rule 1' | ||
description = 'Test Rule Description' | ||
source_url = 'https://github.com/aws-cloudformation/cfn-python-lint/' | ||
tags = ['resources'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
import os | ||
|
||
from test.testlib.testcase import BaseTestCase | ||
from cfnlint.helpers import create_rules | ||
from cfnlint.rules import CloudFormationLintRule | ||
|
||
|
||
class TestCreateRules(BaseTestCase): | ||
"""Test creating rules from a module.""" | ||
|
||
def testBase(self): | ||
from cfnlint.rules.templates import Base | ||
rules = create_rules(Base) | ||
self.assertTrue(all(isinstance(r, CloudFormationLintRule) for r in rules)) | ||
self.assertTrue('E1001' in (r.id for r in rules)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
import os | ||
|
||
from test.testlib.testcase import BaseTestCase | ||
from cfnlint.helpers import load_plugins | ||
from cfnlint.rules import CloudFormationLintRule | ||
from cfnlint.core import DEFAULT_RULESDIR # pylint: disable=E0401 | ||
|
||
|
||
class TestLoadPlugins(BaseTestCase): | ||
"""Test loading rules.""" | ||
|
||
def testFromDefaultDirectory(self): | ||
rules = load_plugins(DEFAULT_RULESDIR) | ||
|
||
self.assertTrue(all(isinstance(r, CloudFormationLintRule) for r in rules)) | ||
# From templates/Base.py | ||
self.assertTrue('E1001' in (r.id for r in rules)) | ||
# From resources/Name.py | ||
self.assertTrue('E3006' in (r.id for r in rules)) | ||
|
||
def testFromSubDirectory(self): | ||
path = os.path.join(DEFAULT_RULESDIR, "templates") | ||
rules = load_plugins(path) | ||
|
||
self.assertTrue(all(isinstance(r, CloudFormationLintRule) for r in rules)) | ||
self.assertTrue('E1001' in (r.id for r in rules)) | ||
self.assertFalse('E3006' in (r.id for r in rules)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters