| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace AspxLint.Core.Rules; |
| | | 4 | | |
| | | 5 | | public sealed class Asp005ServerTagSpaces : IRule |
| | | 6 | | { |
| | 207 | 7 | | public string Id => "ASP-005"; |
| | 28 | 8 | | public string Name => "Espace dans la directive ASP <% %>"; |
| | 25 | 9 | | public Severity Severity => Severity.Warning; |
| | | 10 | | public string Description => |
| | 25 | 11 | | "Pour la lisibilite, un espace est recommande apres <% et avant %> dans les blocs de code serveur (<%= valeur %> |
| | 46 | 12 | | public bool HasFix => true; |
| | | 13 | | |
| | 5 | 14 | | private static readonly Regex DetectRegex = |
| | 5 | 15 | | new(@"<%[=#:]?[^\s][^%]*?[^\s]%>", RegexOptions.Compiled); |
| | | 16 | | |
| | 5 | 17 | | private static readonly Regex FixRegex = |
| | 5 | 18 | | new(@"<%([=#:]?)([^\s%][^%]*?[^\s%])%>", RegexOptions.Compiled); |
| | | 19 | | |
| | | 20 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 21 | | { |
| | | 22 | | for (int i = 0; i < lines.Length; i++) |
| | | 23 | | { |
| | | 24 | | foreach (Match m in DetectRegex.Matches(lines[i])) |
| | | 25 | | { |
| | | 26 | | if (m.Value.Contains('@')) continue; // <%@ Page ... %> et autres directives |
| | | 27 | | yield return new Issue(Id, Name, Severity, |
| | | 28 | | i + 1, m.Index + 1, m.Value, |
| | | 29 | | "Espace recommande apres <% et avant %>."); |
| | | 30 | | } |
| | | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public string? Fix(string content, RuleContext ctx) => |
| | 21 | 35 | | FixRegex.Replace(content, m => |
| | 21 | 36 | | m.Value.Contains('@') |
| | 21 | 37 | | ? m.Value |
| | 21 | 38 | | : $"<%{m.Groups[1].Value} {m.Groups[2].Value} %>"); |
| | | 39 | | } |