• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kysect / Configuin / 9125745422

17 May 2024 09:05AM UTC coverage: 81.509% (+0.02%) from 81.494%
9125745422

push

github

FrediKats
Documentation for format command

239 of 358 branches covered (66.76%)

Branch coverage included in aggregate %.

1771 of 2108 relevant lines covered (84.01%)

531.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/Sources/Kysect.Configuin.EditorConfig/DocumentModel/EditorConfigDocumentParser.cs
1
using Kysect.CommonLib.BaseTypes.Extensions;
2
using Kysect.Configuin.EditorConfig.DocumentModel.Nodes;
3

4
namespace Kysect.Configuin.EditorConfig.DocumentModel;
5

6
public class EditorConfigDocumentParser
7
{
8
    public EditorConfigDocument Parse(string content)
9
    {
10
        content.ThrowIfNull();
19✔
11

12
        // KB: sometimes Environment.NewLine is not the same as in the file
13
        string[] lines = content.Split(Environment.NewLine);
19✔
14
        return Parse(lines);
19✔
15
    }
16

17
    public EditorConfigDocument Parse(string[] lines)
18
    {
19
        lines.ThrowIfNull();
19✔
20

21
        var context = new EditorConfigDocumentParsingContext();
19✔
22

23
        foreach (string line in lines)
3,456✔
24
        {
25
            var trimmedLine = line.Trim();
1,709✔
26
            bool isCategory = trimmedLine.StartsWith("[");
1,709✔
27
            if (isCategory)
1,709✔
28
            {
29
                var categoryName = line.Substring(1, line.Length - 2);
11✔
30
                context.AddCategory(categoryName);
11✔
31
                continue;
11✔
32
            }
33

34
            bool isSection = trimmedLine.StartsWith(EditorConfigDocumentSectionNode.NodeIndicator);
1,698✔
35
            if (isSection)
1,698✔
36
            {
37
                context.AddSection(trimmedLine);
3✔
38
                continue;
3✔
39
            }
40

41
            // TODO: add test for commented properties
42
            bool isTrivia = trimmedLine.StartsWith("#") || string.IsNullOrWhiteSpace(line);
1,695✔
43
            if (isTrivia)
1,695✔
44
            {
45
                context.AddTrivia(line);
494✔
46
                continue;
494✔
47
            }
48

49
            bool isProperty = trimmedLine.Contains('=');
1,201✔
50
            if (isProperty)
1,201!
51
            {
52
                string[] parts = line.Split('=');
1,201✔
53
                if (parts.Length != 2)
1,201!
54
                    throw new ArgumentException($"Line {line} contains unexpected count of '='");
×
55

56
                var propertyNode = new EditorConfigPropertyNode(EditorConfigStringNode.Create(parts[0]), EditorConfigStringNode.Create(parts[1]));
1,201✔
57
                context.AddProperty(propertyNode);
1,201✔
58
                continue;
1,201✔
59
            }
60

61
            throw new NotSupportedException($"Not supported line: {line}");
×
62
        }
63

64
        return context.Build();
19✔
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc