< Summary

Information
Class: AspxLint.Core.Rules.Doc001MissingDoctype
Assembly: AspxLint.Core
File(s): D:\a\claude-aspx-lint\claude-aspx-lint\src\AspxLint.Core\Rules\Doc001MissingDoctype.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 41
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
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(...)87.5%88100%

File(s)

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

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace AspxLint.Core.Rules;
 4
 5public sealed class Doc001MissingDoctype : IRule
 6{
 2077    public string Id => "DOC-001";
 328    public string Name => "DOCTYPE manquant (ASPX seulement)";
 299    public Severity Severity => Severity.Warning;
 10    public string Description =>
 2511        "Un fichier ASPX standalone (non-Content) devrait declarer un DOCTYPE pour activer le mode standards des navigat
 4612    public bool HasFix => true;
 13
 514    private static readonly Regex MasterPageFile = new(
 515        @"MasterPageFile\s*=", RegexOptions.IgnoreCase | RegexOptions.Compiled);
 516    private static readonly Regex DoctypePresent = new(
 517        @"<!DOCTYPE", RegexOptions.IgnoreCase | RegexOptions.Compiled);
 518    private static readonly Regex HtmlOpen = new(
 519        @"<html\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
 20
 21    public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx)
 22    {
 23        if (ctx.Ext != "aspx") yield break;
 24        if (MasterPageFile.IsMatch(content)) yield break;       // content page : le master fournit le DOCTYPE
 25        if (DoctypePresent.IsMatch(content)) yield break;
 26        if (!HtmlOpen.IsMatch(content)) yield break;            // pas de <html> = sans doute un fragment
 27
 28        yield return new Issue(Id, Name, Severity, 1, 1,
 29            "(absence de <!DOCTYPE>)",
 30            "Ajouter \"<!DOCTYPE html>\" avant la balise <html>.");
 31    }
 32
 33    public string? Fix(string content, RuleContext ctx)
 34    {
 2135        if (ctx.Ext != "aspx") return content;
 2536        if (DoctypePresent.IsMatch(content) || MasterPageFile.IsMatch(content)) return content;
 1737        var match = HtmlOpen.Match(content);
 2638        if (!match.Success) return content;
 839        return content[..match.Index] + "<!DOCTYPE html>\n" + content[match.Index..];
 40    }
 41}