17
17
PLAYBOOK_ROLE_KEYWORDS ,
18
18
RC ,
19
19
)
20
- from ansiblelint .errors import MatchError
21
20
from ansiblelint .file_utils import Lintable
22
21
from ansiblelint .rules import AnsibleLintRule , RulesCollection
23
22
from ansiblelint .runner import Runner
26
25
from ansiblelint .utils import parse_yaml_from_file
27
26
28
27
if TYPE_CHECKING :
28
+ from ansiblelint .errors import MatchError
29
29
from ansiblelint .utils import Task
30
30
31
31
@@ -121,11 +121,10 @@ def get_var_naming_matcherror(
121
121
) -> MatchError | None :
122
122
"""Return a MatchError if the variable name is not valid, otherwise None."""
123
123
if not isinstance (ident , str ): # pragma: no cover
124
- return MatchError (
124
+ return self . create_matcherror (
125
125
tag = "var-naming[non-string]" ,
126
126
message = "Variables names must be strings." ,
127
- rule = self ,
128
- lintable = file ,
127
+ filename = file ,
129
128
)
130
129
131
130
if ident in ANNOTATION_KEYS or ident in self .allowed_special_names :
@@ -134,35 +133,31 @@ def get_var_naming_matcherror(
134
133
try :
135
134
ident .encode ("ascii" )
136
135
except UnicodeEncodeError :
137
- return MatchError (
136
+ return self . create_matcherror (
138
137
tag = "var-naming[non-ascii]" ,
139
138
message = f"Variables names must be ASCII. ({ ident } )" ,
140
- rule = self ,
141
- lintable = file ,
139
+ filename = file ,
142
140
)
143
141
144
142
if keyword .iskeyword (ident ):
145
- return MatchError (
143
+ return self . create_matcherror (
146
144
tag = "var-naming[no-keyword]" ,
147
145
message = f"Variables names must not be Python keywords. ({ ident } )" ,
148
- rule = self ,
149
- lintable = file ,
146
+ filename = file ,
150
147
)
151
148
152
149
if ident in self .reserved_names :
153
- return MatchError (
150
+ return self . create_matcherror (
154
151
tag = "var-naming[no-reserved]" ,
155
152
message = f"Variables names must not be Ansible reserved names. ({ ident } )" ,
156
- rule = self ,
157
- lintable = file ,
153
+ filename = file ,
158
154
)
159
155
160
156
if ident in self .read_only_names :
161
- return MatchError (
157
+ return self . create_matcherror (
162
158
tag = "var-naming[read-only]" ,
163
159
message = f"This special variable is read-only. ({ ident } )" ,
164
- rule = self ,
165
- lintable = file ,
160
+ filename = file ,
166
161
)
167
162
168
163
# We want to allow use of jinja2 templating for variable names
@@ -172,11 +167,10 @@ def get_var_naming_matcherror(
172
167
if not bool (self .re_pattern .match (ident )) and (
173
168
not prefix or not prefix .from_fqcn
174
169
):
175
- return MatchError (
170
+ return self . create_matcherror (
176
171
tag = "var-naming[pattern]" ,
177
172
message = f"Variables names should match { self .re_pattern_str } regex. ({ ident } )" ,
178
- rule = self ,
179
- lintable = file ,
173
+ filename = file ,
180
174
)
181
175
182
176
if (
@@ -185,11 +179,10 @@ def get_var_naming_matcherror(
185
179
and not has_jinja (prefix .value )
186
180
and is_fqcn_or_name (prefix .value )
187
181
):
188
- return MatchError (
182
+ return self . create_matcherror (
189
183
tag = "var-naming[no-role-prefix]" ,
190
184
message = f"Variables names from within roles should use { prefix .value } _ as a prefix." ,
191
- rule = self ,
192
- lintable = file ,
185
+ filename = file ,
193
186
)
194
187
return None
195
188
0 commit comments