| | | 1 | | namespace AspxLint.Core.Rules; |
| | | 2 | | |
| | | 3 | | public sealed class Ws004FinalNewline : IRule |
| | | 4 | | { |
| | 212 | 5 | | public string Id => "WS-004"; |
| | 37 | 6 | | public string Name => "Pas de saut de ligne final"; |
| | 34 | 7 | | public Severity Severity => Severity.Info; |
| | | 8 | | public string Description => |
| | 25 | 9 | | "POSIX recommande qu'un fichier texte se termine par un saut de ligne. Sinon, certains outils Unix l'affichent m |
| | 46 | 10 | | public bool HasFix => true; |
| | | 11 | | |
| | | 12 | | public IEnumerable<Issue> Detect(string content, string[] lines, RuleContext ctx) |
| | | 13 | | { |
| | | 14 | | if (content.Length == 0) yield break; |
| | | 15 | | if (content.EndsWith('\n')) yield break; |
| | | 16 | | |
| | | 17 | | var lastLineLength = lines.Length == 0 ? 0 : lines[^1].Length; |
| | | 18 | | yield return new Issue(Id, Name, Severity, |
| | | 19 | | Math.Max(1, lines.Length), lastLineLength + 1, |
| | | 20 | | "— fin de fichier sans \\n", |
| | | 21 | | "Ajouter un saut de ligne a la fin du fichier."); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | public string? Fix(string content, RuleContext ctx) => |
| | 21 | 25 | | content.EndsWith('\n') ? content : content + "\n"; |
| | | 26 | | } |