2
2
import re
3
3
import textwrap
4
4
5
+ import cfnlint .config
5
6
import cfnlint .core
6
7
import cfnlint .helpers
8
+ import cfnlint .version
7
9
from cfnlint .config import ConfigMixIn as CfnLintConfig
8
10
from jsonschema .exceptions import ValidationError
9
11
from taskcat ._common_utils import neglect_submodule_templates
10
12
from taskcat ._config import Config
11
13
from taskcat ._dataclasses import Templates
12
14
15
+ # Ignoring linting errors here as pylint doesn't seem to handle the conditional nature
16
+ if cfnlint .version .__version__ .startswith ("0." ):
17
+ from cfnlint .core import ( # pylint:disable=no-name-in-module, ungrouped-imports
18
+ CfnLintExitException ,
19
+ )
20
+ else :
21
+ from cfnlint .runner import ( # pylint:disable=no-name-in-module, ungrouped-imports
22
+ CfnLintExitException ,
23
+ )
24
+
13
25
LOG = logging .getLogger (__name__ )
14
26
15
27
@@ -32,8 +44,24 @@ def __init__(self, config: Config, templates: Templates, strict: bool = False):
32
44
except ValidationError as e :
33
45
LOG .error ("Error parsing cfn-lint config file: %s" , str (e ))
34
46
raise
47
+
48
+ # There is a change in the way that the cfn lint config class functions between the 0.x and 1.x versions.
49
+ # In 1.x, the append_rules property getter includes the default rule set along with the loaded configuration
50
+ # https://github.com/aws-cloudformation/cfn-lint/blob/23ee527fadb43e4fd54238eeea5bc3a169175c91/src/cfnlint/config.py#L773
51
+ # In 0.x, it only returned the loaded configuration.
52
+ # https://github.com/aws-cloudformation/cfn-lint/blob/f006cb5d8c7056923f3f21b31c14edfeed3804b5/src/cfnlint/config.py#L730
53
+ #
54
+ # This causes issues for us as the get_rules method combines the supplied value with the default rule list,
55
+ # resulting in a duplicate rule error. get_rules has always behaved this way though, so not sure if we have just missed something
56
+ # in the intended approach to calling this.
57
+ if cfnlint .version .__version__ .startswith ("0." ):
58
+ append_rules = self ._cfnlint_config .append_rules
59
+ else :
60
+ append_rules = self ._cfnlint_config .append_rules
61
+ append_rules .remove (cfnlint .config ._DEFAULT_RULESDIR )
62
+
35
63
self ._rules = cfnlint .core .get_rules (
36
- self . _cfnlint_config . append_rules ,
64
+ append_rules ,
37
65
self ._cfnlint_config .ignore_checks ,
38
66
self ._cfnlint_config .include_checks ,
39
67
self ._cfnlint_config .configure_rules ,
@@ -91,17 +119,11 @@ def _run_checks(self, template, name, lint_errors, lints):
91
119
tpath = str (template .template_path )
92
120
results = []
93
121
try :
94
- ( _ , rules , template_matches ) = cfnlint .core .get_template_rules (
95
- tpath , self ._cfnlint_config
122
+ results = cfnlint .core .run_checks (
123
+ tpath , template . template , self ._rules , lints [ name ][ "regions" ]
96
124
)
97
- if template_matches :
98
- results = template_matches
99
- else :
100
- results = cfnlint .core .run_checks (
101
- tpath , template .template , rules , lints [name ]["regions" ]
102
- )
103
125
lints [name ]["results" ][tpath ] = results
104
- except cfnlint . core . CfnLintExitException as e :
126
+ except CfnLintExitException as e :
105
127
lint_errors .add (str (e ))
106
128
lints [name ]["results" ][tpath ] = results
107
129
0 commit comments