| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace AspxLint.Core.Rules; |
| | | 4 | | |
| | | 5 | | public sealed class Asp003ContentPlaceHolderMissingId : IRule |
| | | 6 | | { |
| | 205 | 7 | | public string Id => "ASP-003"; |
| | 28 | 8 | | public string Name => "ContentPlaceHolder sans ID (MASTER)"; |
| | 25 | 9 | | public Severity Severity => Severity.Error; |
| | | 10 | | public string Description => |
| | 25 | 11 | | "Dans un fichier MASTER, chaque <asp:ContentPlaceHolder> doit avoir un attribut ID unique pour que les pages enf |
| | 46 | 12 | | public bool HasFix => false; |
| | | 13 | | |
| | 4 | 14 | | private static readonly Regex CphRegex = new( |
| | 4 | 15 | | @"<asp:ContentPlaceHolder\b([^>]*?)\/?>", |
| | 4 | 16 | | RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 17 | | |
| | 4 | 18 | | private static readonly Regex IdAttrRegex = new( |
| | 4 | 19 | | @"\bID\s*=\s*[""'][^""']+[""']", |
| | 4 | 20 | | RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 21 | | |
| | | 22 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 23 | | { |
| | | 24 | | if (ctx.Ext != "master") yield break; |
| | | 25 | | |
| | | 26 | | for (int i = 0; i < lines.Length; i++) |
| | | 27 | | { |
| | | 28 | | foreach (Match m in CphRegex.Matches(lines[i])) |
| | | 29 | | { |
| | | 30 | | if (IdAttrRegex.IsMatch(m.Groups[1].Value)) continue; |
| | | 31 | | yield return new Issue(Id, Name, Severity, |
| | | 32 | | i + 1, m.Index + 1, m.Value, |
| | | 33 | | "Ajouter un attribut ID unique a ce ContentPlaceHolder."); |
| | | 34 | | } |
| | | 35 | | } |
| | | 36 | | } |
| | | 37 | | |
| | 4 | 38 | | public string? Fix(string content, RuleContext ctx) => null; |
| | | 39 | | } |