@@ -54,6 +54,7 @@ if (parentPort) {
5454 payload . content as string ,
5555 payload . uri as string ,
5656 payload . fileType as CloudFormationFileType ,
57+ payload . settings as Record < string , unknown > ,
5758 ) ;
5859 break ;
5960 }
@@ -62,6 +63,7 @@ if (parentPort) {
6263 payload . path as string ,
6364 payload . uri as string ,
6465 payload . fileType as CloudFormationFileType ,
66+ payload . settings as Record < string , unknown > ,
6567 ) ;
6668 break ;
6769 }
@@ -247,30 +249,71 @@ async function initializePyodide(): Promise<InitializeResult> {
247249
248250 return results
249251
250- def lint_str(template_str, uri, template_args=None):
252+ def parse_cfn_lint_settings(settings):
253+ """Parse cfn-lint settings into ManualArgs format"""
254+ config = {}
255+ if not settings:
256+ return config
257+
258+ if settings.get('ignoreChecks'):
259+ config['ignore_checks'] = settings['ignoreChecks']
260+ if settings.get('includeChecks'):
261+ config['include_checks'] = settings['includeChecks']
262+ if settings.get('mandatoryChecks'):
263+ config['mandatory_checks'] = settings['mandatoryChecks']
264+ if settings.get('includeExperimental'):
265+ config['include_experimental'] = settings['includeExperimental']
266+ if settings.get('configureRules'):
267+ # Parse configure rules from string format "RuleId:key=value"
268+ configure_rules = {}
269+ for rule_config in settings['configureRules']:
270+ if ':' in rule_config:
271+ rule_id, config_str = rule_config.split(':', 1)
272+ if '=' in config_str:
273+ key, value = config_str.split('=', 1)
274+ if rule_id not in configure_rules:
275+ configure_rules[rule_id] = {}
276+ # Convert string values to appropriate types
277+ if value.lower() == 'true':
278+ configure_rules[rule_id][key] = True
279+ elif value.lower() == 'false':
280+ configure_rules[rule_id][key] = False
281+ else:
282+ try:
283+ configure_rules[rule_id][key] = int(value)
284+ except ValueError:
285+ configure_rules[rule_id][key] = value
286+ if configure_rules:
287+ config['configure_rules'] = configure_rules
288+ if settings.get('regions'):
289+ config['regions'] = settings['regions']
290+ return config
291+
292+ def lint_str(template_str, uri, settings=None):
251293 """
252294 Lint a CloudFormation template string and return LSP diagnostics
253295
254296 Args:
255297 template_str (str): CloudFormation template as a string
256298 uri (str): Document URI
257- template_args (dict, optional): Additional template arguments
299+ settings (dict, optional): cfn-lint settings
258300
259301 Returns:
260302 dict: LSP PublishDiagnosticsParams
261303 """
304+ config = parse_cfn_lint_settings(settings)
305+ return match_to_diagnostics(lint(template_str, config=ManualArgs(**config) if config else None), uri)
262306
263- return match_to_diagnostics(lint(template_str), uri)
264-
265- def lint_uri(lint_path, uri, lint_type, template_args=None):
266- args = ManualArgs()
307+ def lint_uri(lint_path, uri, lint_type, settings=None):
308+ config = parse_cfn_lint_settings(settings)
267309 path = Path(lint_path)
310+
268311 if lint_type == "template":
269- args ["templates"] = [str(path)]
312+ config ["templates"] = [str(path)]
270313 elif lint_type == "gitsync-deployment":
271- args ["deployment_files"] = [str(path)]
314+ config ["deployment_files"] = [str(path)]
272315
273- return match_to_diagnostics(lint_by_config(args ), uri)
316+ return match_to_diagnostics(lint_by_config(ManualArgs(**config) ), uri)
274317 ` ) ;
275318
276319 // Create result object first
@@ -309,6 +352,7 @@ async function lintTemplate(
309352 content : string ,
310353 uri : string ,
311354 _fileType : CloudFormationFileType ,
355+ settings ?: Record < string , unknown > ,
312356) : Promise < PublishDiagnosticsParams [ ] > {
313357 if ( ! initialized || ! pyodide ) {
314358 throw new Error ( 'Pyodide not initialized' ) ;
@@ -319,9 +363,11 @@ async function lintTemplate(
319363 const pyUri = pyodide . toPy ( uri ) ;
320364 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
321365 const pyContent = pyodide . toPy ( content . replaceAll ( '"""' , '\\"\\"\\"' ) ) ;
366+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
367+ const pySettings = pyodide . toPy ( settings ?? { } ) ;
322368
323369 // Execute Python code and get result
324- const pythonCode = `lint_str(r"""${ pyContent } """, r"""${ pyUri } """)` ;
370+ const pythonCode = `lint_str(r"""${ pyContent } """, r"""${ pyUri } """, ${ pySettings } )` ;
325371 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
326372 const result = await pyodide . runPythonAsync ( pythonCode ) ;
327373
@@ -333,13 +379,17 @@ async function lintFile(
333379 path : string ,
334380 uri : string ,
335381 fileType : CloudFormationFileType ,
382+ settings ?: Record < string , unknown > ,
336383) : Promise < PublishDiagnosticsParams [ ] > {
337384 if ( ! initialized || ! pyodide ) {
338385 throw new Error ( 'Pyodide not initialized' ) ;
339386 }
340387
388+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
389+ const pySettings = pyodide . toPy ( settings ?? { } ) ;
390+
341391 // Execute Python code and get result
342- const pythonCode = `lint_uri(r"""${ path } """, r"""${ uri } """, r"""${ fileType } """)` ;
392+ const pythonCode = `lint_uri(r"""${ path } """, r"""${ uri } """, r"""${ fileType } """, ${ pySettings } )` ;
343393 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
344394 const result = await pyodide . runPythonAsync ( pythonCode ) ;
345395
0 commit comments