| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace AspxLint.Core.Rules; |
| | | 4 | | |
| | | 5 | | public sealed class Asp004ContentMissingPlaceHolderId : IRule |
| | | 6 | | { |
| | 203 | 7 | | public string Id => "ASP-004"; |
| | 26 | 8 | | public string Name => "Content sans ContentPlaceHolderID (page enfant)"; |
| | 23 | 9 | | public Severity Severity => Severity.Error; |
| | | 10 | | public string Description => |
| | 25 | 11 | | "Une balise <asp:Content> doit referencer un placeholder du master via ContentPlaceHolderID, sinon la page ne sa |
| | 46 | 12 | | public bool HasFix => false; |
| | | 13 | | |
| | 5 | 14 | | private static readonly Regex ContentRegex = new( |
| | 5 | 15 | | @"<asp:Content\b([^>]*?)>", |
| | 5 | 16 | | RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 17 | | |
| | 5 | 18 | | private static readonly Regex CphIdAttr = new( |
| | 5 | 19 | | @"ContentPlaceHolderID\s*=\s*[""'][^""']+[""']", |
| | 5 | 20 | | RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 21 | | |
| | | 22 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 23 | | { |
| | | 24 | | for (int i = 0; i < lines.Length; i++) |
| | | 25 | | { |
| | | 26 | | foreach (Match m in ContentRegex.Matches(lines[i])) |
| | | 27 | | { |
| | | 28 | | if (CphIdAttr.IsMatch(m.Groups[1].Value)) continue; |
| | | 29 | | yield return new Issue(Id, Name, Severity, |
| | | 30 | | i + 1, m.Index + 1, m.Value, |
| | | 31 | | "Ajouter ContentPlaceHolderID=\"...\" pointant vers un placeholder du master."); |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | } |
| | | 35 | | |
| | 4 | 36 | | public string? Fix(string content, RuleContext ctx) => null; |
| | | 37 | | } |