< Summary

Information
Class: AspxLint.Core.Rules.Asp001ControlMissingRunat
Assembly: AspxLint.Core
File(s): D:\a\claude-aspx-lint\claude-aspx-lint\src\AspxLint.Core\Rules\Asp001ControlMissingRunat.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 49
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_Name()100%11100%
get_Severity()100%11100%
get_Description()100%11100%
get_HasFix()100%11100%
.cctor()100%11100%
Fix(...)100%11100%

File(s)

D:\a\claude-aspx-lint\claude-aspx-lint\src\AspxLint.Core\Rules\Asp001ControlMissingRunat.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace AspxLint.Core.Rules;
 4
 5public sealed class Asp001ControlMissingRunat : IRule
 6{
 2077    public string Id => "ASP-001";
 288    public string Name => "Controle serveur sans runat=\"server\"";
 259    public Severity Severity => Severity.Error;
 10    public string Description =>
 2511        "Tout controle <asp:...> doit avoir l'attribut runat=\"server\", sinon il est traite comme du HTML litteral et n
 4612    public bool HasFix => true;
 13
 514    private static readonly Regex DetectRegex = new(
 515        @"<asp:([a-zA-Z]+)\b([^>]*?)/?>",
 516        RegexOptions.Compiled);
 17
 518    private static readonly Regex FixRegex = new(
 519        @"<asp:([a-zA-Z]+)\b([^>]*?)(\s*/?)>",
 520        RegexOptions.Compiled);
 21
 522    private static readonly Regex RunatPresent = new(
 523        @"\brunat\s*=\s*[""']?server[""']?",
 524        RegexOptions.IgnoreCase | RegexOptions.Compiled);
 25
 26    public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx)
 27    {
 28        for (int i = 0; i < lines.Length; i++)
 29        {
 30            foreach (Match m in DetectRegex.Matches(lines[i]))
 31            {
 32                if (RunatPresent.IsMatch(m.Groups[2].Value)) continue;
 33                yield return new Issue(Id, Name, Severity,
 34                    i + 1, m.Index + 1, m.Value,
 35                    $"Ajouter runat=\"server\" au controle <asp:{m.Groups[1].Value}>");
 36            }
 37        }
 38    }
 39
 40    public string? Fix(string content, RuleContext ctx) =>
 2741        FixRegex.Replace(content, m =>
 2742        {
 2743            var attrs = m.Groups[2].Value;
 2744            if (RunatPresent.IsMatch(attrs)) return m.Value;
 2745            var cleanAttrs = attrs.TrimEnd();
 2746            var tail = m.Groups[3].Value.Contains('/') ? " />" : ">";
 2747            return $"<asp:{m.Groups[1].Value}{cleanAttrs} runat=\"server\"{tail}";
 2748        });
 49}