< Summary

Information
Class: AspxLint.Core.Rules.Com001NestedDashes
Assembly: AspxLint.Core
File(s): D:\a\claude-aspx-lint\claude-aspx-lint\src\AspxLint.Core\Rules\Com001NestedDashes.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 51
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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%
LineFromOffset(...)75%44100%

File(s)

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

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace AspxLint.Core.Rules;
 4
 5public sealed class Com001NestedDashes : IRule
 6{
 2017    public string Id => "COM-001";
 288    public string Name => "Commentaire HTML imbrique (-- dans <!-- -->)";
 259    public Severity Severity => Severity.Warning;
 10    public string Description =>
 2511        "La sequence -- ne doit pas apparaitre a l'interieur d'un commentaire HTML <!-- -->. Cela invalide le commentair
 4612    public bool HasFix => false;
 13
 514    private static readonly Regex HtmlComment =
 515        new(@"<!--([\s\S]*?)-->", RegexOptions.Compiled);
 16
 17    public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx)
 18    {
 19        // Pre-calcul des offsets de debut de ligne.
 20        var lineStarts = new int[lines.Length];
 21        int pos = 0;
 22        for (int i = 0; i < lines.Length; i++)
 23        {
 24            lineStarts[i] = pos;
 25            pos += lines[i].Length + 1;
 26        }
 27
 28        foreach (Match m in HtmlComment.Matches(content))
 29        {
 30            if (!m.Groups[1].Value.Contains("--")) continue;
 31            var snippet = m.Value.Length > 60 ? m.Value[..60] + "…" : m.Value;
 32            yield return new Issue(Id, Name, Severity,
 33                LineFromOffset(m.Index, lineStarts), 1, snippet,
 34                "Le commentaire contient \"--\", ce qui est invalide en XHTML strict.");
 35        }
 36    }
 37
 438    public string? Fix(string content, RuleContext ctx) => null;
 39
 40    private static int LineFromOffset(int offset, int[] lineStarts)
 41    {
 442        int lo = 0, hi = lineStarts.Length - 1;
 443        while (lo < hi)
 44        {
 245            int mid = (lo + hi + 1) / 2;
 246            if (lineStarts[mid] <= offset) lo = mid;
 247            else hi = mid - 1;
 48        }
 249        return lo + 1;
 50    }
 51}