protected override void Analyze(IAnalyzerContext context) { IDirectory dataDirectory = context.FileSystem.GetRootDirectory("data"); foreach (IFile dataFile in dataDirectory.GetFiles(System.IO.SearchOption.AllDirectories)) { if (!dataFile.Path.Extension.Equals(".yml")) { context.AddAnalyzerResult(null, $"File {dataDirectory.Parent.Path.GetRelativePath(dataFile.Path.FullPath)} should have a .yml extension"); } if (dataFile.Path.FileName.FullPath.ToLower() != dataFile.Path.FileName || dataFile.Path.FileNameWithoutExtension.FullPath.Any(c => !char.IsLetterOrDigit(c) && c != '-')) { context.AddAnalyzerResult(null, $"File {dataDirectory.Parent.Path.GetRelativePath(dataFile.Path.FullPath)} should only contain lowercase letters, digits, and dashes"); } } }
protected override void AnalyzeSpeakerData(IDocument document, IAnalyzerContext context) { foreach (KeyValuePair <string, SpeakerLinkAttribute> linkAttribute in SpeakerLinkAttribute.GetAll()) { if (document.ContainsKey(linkAttribute.Key)) { if (!Uri.TryCreate(document.GetString(linkAttribute.Key), UriKind.Absolute, out Uri uri)) { context.AddAnalyzerResult(document, $"{linkAttribute.Key} link {document.GetString(linkAttribute.Key)} is invalid"); } else if (linkAttribute.Value.EnforceHttps && uri.Scheme != Uri.UriSchemeHttps) { context.AddAnalyzerResult(document, $"{linkAttribute.Key} link should be HTTPS and was not"); } } } }
protected override void AnalyzeSpeakerData(IDocument document, IAnalyzerContext context) { string pronouns = document.GetString(SiteKeys.Pronouns); if (!pronouns.IsNullOrEmpty() && (pronouns.Count(x => x == '/') != 1 || pronouns.Any(x => x != '/' && (!char.IsLetter(x) || !char.IsLower(x))))) { context.AddAnalyzerResult(document, $"Preferred gender pronouns should be of the form [subject]/[object] in lowercase (I.e. \"they/them\")"); } }
protected override void AnalyzeSpeakerData(IDocument document, IAnalyzerContext context) { IReadOnlyList <string> topics = document.GetList <string>(SiteKeys.Topics); if (topics == null || topics.Count == 0) { // No topics, but that's okay (if we ever want to enforce at least one topic, add an analyzer result here) return; } string[] nonApprovedTopics = topics.Where(x => !Topics.Contains(x)).ToArray(); if (nonApprovedTopics.Length > 0) { context.AddAnalyzerResult(document, $"Document contains non-approved topic(s): {string.Join(", ", nonApprovedTopics)}"); } }
protected override void AnalyzeSpeakerData(IDocument document, IAnalyzerContext context) { IReadOnlyList <string> languages = document.GetList <string>(SiteKeys.Language); if (languages?.Count > 0) { foreach (string language in languages) { if (!char.IsUpper(language[0])) { context.AddAnalyzerResult(document, $"Please capitalize speaker language: {language}"); } } } }