public static bool IsValidTemplate()

in src/Analyzer.Utilities/TemplateDiscovery.cs [109:155]


        public static bool IsValidTemplate(FileInfo file)
        {
            try
            {
                // Assume bicep files are valid, they are compiled/verified later
                if (file.Extension.Equals(".bicep", StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }

                using var fileStream = new StreamReader(file.OpenRead());
                var reader = new JsonTextReader(fileStream);

                reader.Read();
                if (reader.TokenType != JsonToken.StartObject)
                {
                    return false;
                }

                while (reader.Read())
                {
                    if (reader.Depth == 1 && reader.TokenType == JsonToken.PropertyName)
                    {
                        if (string.Equals((string)reader.Value, "$schema", StringComparison.OrdinalIgnoreCase))
                        {
                            reader.Read();
                            if (reader.TokenType != JsonToken.String)
                            {
                                return false;
                            }

                            return validSchemaRegex.IsMatch((string)reader.Value);
                        }
                        else if (!validTemplateProperties.Any(property => string.Equals((string)reader.Value, property, StringComparison.OrdinalIgnoreCase)))
                        {
                            return false;
                        }
                    }
                }

                return false;
            }
            catch {
                // If template fails to parse in any way then also consider invalid template
                return false;
            }
        }