Repository: aws-cloudformation/cfn-lint

Issue:
Junit format output is blank if E0000 is found
*cfn-lint version: 0.52.0*

If there is an E0000 error, the junit output format does not output anything.

Here is a minimal template that can be used to recreate the issue:
```
AWSTemplateFormatVersion:'2010-09-09'
Resources:
  TempNullResource:
    Type: 'Custom::NullResource'
```

The error is the missing space between `:` and `'` on the first line. If you run with `--format junit` you will get a blank output. If you add the space back (removing the error) you will see that the junit output has everything present. The junit output works fine with other errors, but if there is an E0000 then the output is blank. This has been tried with python 3.8.6.



Discussion:
Exit code is done right but nothing is printed because rules are empty.  Need to return rules even when we get a E0000 error

Resolving patch:
diff --git a/src/cfnlint/core.py b/src/cfnlint/core.py
--- a/src/cfnlint/core.py
+++ b/src/cfnlint/core.py
@@ -256,11 +256,32 @@ def _reset_rule_cache() -> None:
     __CACHED_RULES = None
 
 
+def _build_rule_cache(args: cfnlint.config.ConfigMixIn) -> None:
+    global __CACHED_RULES  # pylint: disable=global-statement
+    if __CACHED_RULES:
+        __CACHED_RULES.configure(
+            ignore_rules=args.ignore_checks,
+            include_rules=args.include_checks,
+            configure_rules=args.configure_rules,
+            include_experimental=args.include_experimental,
+            mandatory_rules=args.mandatory_checks,
+        )
+    else:
+        __CACHED_RULES = cfnlint.core.get_rules(
+            args.append_rules,
+            args.ignore_checks,
+            args.include_checks,
+            args.configure_rules,
+            args.include_experimental,
+            args.mandatory_checks,
+            args.custom_rules,
+        )
+
+
 def get_template_rules(
     filename: str, args: cfnlint.config.ConfigMixIn
 ) -> TemplateRules:
     """Get Template Configuration items and set them as default values"""
-    global __CACHED_RULES  # pylint: disable=global-statement
 
     ignore_bad_template: bool = False
     if args.ignore_bad_template:
@@ -279,30 +300,14 @@ def get_template_rules(
     (template, errors) = cfnlint.decode.decode(filename)
 
     if errors:
+        _build_rule_cache(args)
         if len(errors) == 1 and ignore_bad_template and errors[0].rule.id == 'E0000':
-            return (template, None, [])
-        return (template, None, errors)
+            return (template, __CACHED_RULES, [])
+        return (template, __CACHED_RULES, errors)
 
     args.template_args = template
 
-    if __CACHED_RULES:
-        __CACHED_RULES.configure(
-            ignore_rules=args.ignore_checks,
-            include_rules=args.include_checks,
-            configure_rules=args.configure_rules,
-            include_experimental=args.include_experimental,
-            mandatory_rules=args.mandatory_checks,
-        )
-    else:
-        __CACHED_RULES = cfnlint.core.get_rules(
-            args.append_rules,
-            args.ignore_checks,
-            args.include_checks,
-            args.configure_rules,
-            args.include_experimental,
-            args.mandatory_checks,
-            args.custom_rules,
-        )
+    _build_rule_cache(args)
 
     return (template, __CACHED_RULES, [])
 
diff --git a/src/cfnlint/formatters/__init__.py b/src/cfnlint/formatters/__init__.py
--- a/src/cfnlint/formatters/__init__.py
+++ b/src/cfnlint/formatters/__init__.py
@@ -92,6 +92,10 @@ def print_matches(self, matches, rules=None, filenames=None):
         if not rules:
             return None
 
+        if rules is not None:
+            # These "base" rules are not passed into formatters
+            rules.extend([ParseError(), TransformError(), RuleError()])
+
         test_cases = []
         for rule in rules.all_rules.values():
             if not rule.id in rules.used_rules:


Test patch: