| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace AspxLint.Core.Rules; |
| | | 4 | | |
| | | 5 | | public sealed class Sm001MultipleScriptManager : IRule |
| | | 6 | | { |
| | 203 | 7 | | public string Id => "SM-001"; |
| | 30 | 8 | | public string Name => "Plusieurs ScriptManager dans la page"; |
| | 27 | 9 | | public Severity Severity => Severity.Error; |
| | | 10 | | public string Description => |
| | 25 | 11 | | "Une page ASP.NET ne peut contenir qu'un seul <asp:ScriptManager>. Pour les content pages avec un master ayant d |
| | 46 | 12 | | public bool HasFix => false; |
| | | 13 | | |
| | 5 | 14 | | private static readonly Regex DetectRegex = |
| | 5 | 15 | | new(@"<asp:ScriptManager\b", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | | 16 | | |
| | | 17 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 18 | | { |
| | | 19 | | var matches = new List<(int line, int col, string snippet)>(); |
| | | 20 | | for (int i = 0; i < lines.Length; i++) |
| | | 21 | | { |
| | | 22 | | foreach (Match m in DetectRegex.Matches(lines[i])) |
| | | 23 | | { |
| | | 24 | | var rest = lines[i][m.Index..]; |
| | | 25 | | var endTag = rest.IndexOf('>'); |
| | | 26 | | var snippet = endTag >= 0 ? rest[..(endTag + 1)] : rest; |
| | | 27 | | matches.Add((i + 1, m.Index + 1, snippet)); |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | if (matches.Count <= 1) yield break; |
| | | 32 | | |
| | | 33 | | var firstLine = matches[0].line; |
| | | 34 | | for (int k = 1; k < matches.Count; k++) |
| | | 35 | | { |
| | | 36 | | var mm = matches[k]; |
| | | 37 | | yield return new Issue(Id, Name, Severity, |
| | | 38 | | mm.line, mm.col, mm.snippet, |
| | | 39 | | $"Un ScriptManager existe deja ligne {firstLine}. Utiliser ScriptManagerProxy ici."); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | 4 | 43 | | public string? Fix(string content, RuleContext ctx) => null; |
| | | 44 | | } |