Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using USFMToolsSharp.Linter.LinterModules;
using USFMToolsSharp.Linter.Models;
using USFMToolsSharp.Models.Markers;

namespace USFMToolsSharp.Linter.LinterModules
{
public class UnorderedChapters : ILinterModule
{
public List<LinterResult> Lint(USFMDocument input)
{
List<int> chapterIndecies = new List<int>();
List<LinterResult> results = new List<LinterResult>();
foreach (Marker marker in input.Contents)
{
if (marker is CMarker)
{
int chapIndex = ((CMarker)marker).Number;
if (chapterIndecies.Count != 0)
{
if (chapIndex != chapterIndecies[chapterIndecies.Count - 1] + 1)
{
results.Add(new LinterResult
{
Position = marker.Position,
Level = LinterLevel.Error,
Message = $"Chapter {chapIndex} is not in the correct order."
});
}
}

chapterIndecies.Add(((CMarker)marker).Number);
}
if (marker is IDMarker)
{
chapterIndecies.Clear();
}
}
return results;
}
}
}
3 changes: 2 additions & 1 deletion USFMToolsSharp.Linter/USFMLinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class USFMLinter
new VerseMarkerValidation(),
new MissingEndMarkers(),
new UnpairedEndMarkers(),
new MissingTableRows()
new MissingTableRows(),
new UnorderedChapters()
};
public List<LinterResult> Lint(USFMDocument input)
{
Expand Down