diff --git a/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs b/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs new file mode 100644 index 0000000..160a7d3 --- /dev/null +++ b/USFMToolsSharp.Linter/LinterModules/UnorderedChapters.cs @@ -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 Lint(USFMDocument input) + { + List chapterIndecies = new List(); + List results = new List(); + 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; + } + } +} \ No newline at end of file diff --git a/USFMToolsSharp.Linter/USFMLinter.cs b/USFMToolsSharp.Linter/USFMLinter.cs index 0a2e3b6..a7326e7 100644 --- a/USFMToolsSharp.Linter/USFMLinter.cs +++ b/USFMToolsSharp.Linter/USFMLinter.cs @@ -14,7 +14,8 @@ public class USFMLinter new VerseMarkerValidation(), new MissingEndMarkers(), new UnpairedEndMarkers(), - new MissingTableRows() + new MissingTableRows(), + new UnorderedChapters() }; public List Lint(USFMDocument input) {