示例#1
0
        private static void WriteRuleFileContent(RuleFileContent ruleFileContent, string outputPath)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RuleFileContent));

            using FileStream fs = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.None);
            serializer.WriteObject(fs, ruleFileContent);
        }
示例#2
0
        private static void GetRulesJson(string nugetInstalledPackagesPath, string version, string outputPath)
        {
            IEnumerable <string> dllPaths        = GetFxCopAnalyzerBinaries(nugetInstalledPackagesPath, version);
            RuleFileContent      ruleFileContent = new RuleFileContent();

            ruleFileContent.Rules = GetRules(dllPaths);
            WriteRuleFileContent(ruleFileContent, outputPath);
        }
示例#3
0
        private static void GetRulesJson(string nugetInstalledPackagesPath, string version, string outputPath)
        {
            IEnumerable <string> dllPaths        = GetNetAnalyzerBinaries(nugetInstalledPackagesPath, version);
            RuleFileContent      ruleFileContent = new RuleFileContent
            {
                Rules = GetRules(dllPaths)
            };

            ruleFileContent.Rules.Sort(CategoryThenIdComparer.Instance);
            WriteRuleFileContent(ruleFileContent, outputPath);
        }
示例#4
0
        private static void DiffRules(
            string oldRulesJsonPath,
            string newRulesJsonPath,
            string outputPath,
            string?latestRulesJsonPath = null)
        {
            RuleFileContent oldContent = ReadRuleFileContent(oldRulesJsonPath);
            RuleFileContent newContent = ReadRuleFileContent(newRulesJsonPath);

            // If we have the latest rules, we can backfill missing help link URLs.
            if (!string.IsNullOrWhiteSpace(latestRulesJsonPath))
            {
                RuleFileContent latestContent = ReadRuleFileContent(latestRulesJsonPath);
                Dictionary <string, RuleInfo> latestRulesById = latestContent.Rules.Where(r => r.Id != null).ToDictionary(r => r.Id !);
                foreach (RuleInfo rule in oldContent.Rules.Concat(newContent.Rules))
                {
                    if (string.IsNullOrWhiteSpace(rule.HelpLink) &&
                        rule.Id != null &&
                        latestRulesById.TryGetValue(rule.Id, out RuleInfo? latestRule))
                    {
                        rule.HelpLink = latestRule.HelpLink;
                    }
                }
            }

            Dictionary <string, RuleInfo> oldRulesById = oldContent.Rules.Where(r => r.Id != null).ToDictionary(r => r.Id !);
            Dictionary <string, RuleInfo> newRulesById = newContent.Rules.Where(r => r.Id != null).ToDictionary(r => r.Id !);
            IEnumerable <RuleInfo>        addedRules   =
                newContent.Rules
                .Where(r => r.Id != null && !oldRulesById.ContainsKey(r.Id));
            IEnumerable <RuleInfo> removedRules =
                oldContent.Rules
                .Where(r => r.Id != null && !newRulesById.ContainsKey(r.Id));
            IEnumerable <RuleInfo> changedRules =
                newContent.Rules
                .Where(r => r.Id != null &&
                       oldRulesById.TryGetValue(r.Id, out RuleInfo? oldRule) &&
                       r.IsEnabledByDefault != oldRule.IsEnabledByDefault);
            StringBuilder sb = new StringBuilder();

            GenerateAddRemovedRulesDiffMarkdown(sb, "### Added", addedRules);
            GenerateAddRemovedRulesDiffMarkdown(sb, "### Removed", removedRules);
            GenerateChangedRulesDiffMarkdown(sb, "### Changed", changedRules);
            File.WriteAllText(outputPath, sb.ToString());
        }