private static DependencyTargetCollection ToRuleBlockV1()

in src/PSRule/Host/HostHelper.cs [441:515]


        private static DependencyTargetCollection<RuleBlock> ToRuleBlockV1(ILanguageBlock[] blocks, RunspaceContext context)
        {
            // Index rules by RuleId
            var results = new DependencyTargetCollection<RuleBlock>();

            // Keep track of rule names and ids that have been added
            var seenRuleNames = new HashSet<string>();
            var seenRuleIds = new HashSet<ResourceId>();

            try
            {
                foreach (var block in blocks.OfType<RuleBlock>())
                {
                    var ruleName = block.Name;
                    var ruleId = block.Id;

                    if (seenRuleIds.Contains(ruleId))
                        throw ThrowDuplicateRuleId(block);

                    else if (seenRuleNames.Contains(ruleName))
                        context.WarnDuplicateRuleName(ruleName);

                    else
                    {
                        results.TryAdd(block);
                        seenRuleNames.Add(ruleName);
                        seenRuleIds.Add(ruleId);
                    }
                }

                foreach (var yaml in blocks.OfType<RuleV1>())
                {
                    var ruleName = yaml.Name;
                    var ruleId = yaml.Id;

                    if (seenRuleIds.Contains(ruleId))
                        throw ThrowDuplicateRuleId(yaml);

                    else if (seenRuleNames.Contains(ruleName))
                        context.WarnDuplicateRuleName(ruleName);

                    else
                    {
                        context.EnterSourceScope(yaml.Source);
                        var info = GetHelpInfo(context, ruleName, yaml.Synopsis) ?? new RuleHelpInfo(ruleName, ruleName, yaml.Source.ModuleName)
                        {
                            Synopsis = yaml.Synopsis
                        };
                        var block = new RuleBlock
                        (
                            source: yaml.Source,
                            id: yaml.Id,
                            @ref: yaml.Ref,
                            level: yaml.Level,
                            info: info,
                            condition: new RuleVisitor(yaml.Source.ModuleName, yaml.Id.Value, yaml.Spec),
                            alias: yaml.Alias,
                            tag: yaml.Metadata.Tags,
                            dependsOn: null,  // TODO: No support for DependsOn yet
                            configuration: null, // TODO: No support for rule configuration use module or workspace config
                            extent: null,
                            flags: yaml.Flags
                        );
                        results.TryAdd(block);
                        seenRuleNames.Add(ruleName);
                        seenRuleIds.Add(ruleId);
                    }
                }
            }
            finally
            {
                context.ExitSourceScope();
            }
            return results;
        }