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

ricardoboss / STEP / 18225760412

03 Oct 2025 02:54PM UTC coverage: 71.129% (+0.07%) from 71.061%
18225760412

Pull #168

github

web-flow
Merge d72f96053 into 1a6c9c7c7
Pull Request #168: More testable analyzers

470 of 610 branches covered (77.05%)

Branch coverage included in aggregate %.

23 of 104 new or added lines in 19 files covered. (22.12%)

4 existing lines in 2 files now uncovered.

3127 of 4447 relevant lines covered (70.32%)

1922.9 hits per line

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

0.0
/StepLang.Tooling.Formatting/Analyzers/FileEncodingAnalyzer.cs
1
using StepLang.Tooling.Formatting.Analyzers.Results;
2
using System.Text;
3

4
namespace StepLang.Tooling.Formatting.Analyzers;
5

6
public class FileEncodingAnalyzer : IFileAnalyzer
7
{
8
        private static readonly Encoding DefaultEncoding = Encoding.UTF8;
×
9

10
        public async Task<FileAnalysisResult> AnalyzeAsync(FileInfo original, CancellationToken cancellationToken = default)
11
        {
12
                await using var stream = new FileStream(original.FullName, FileMode.Open, FileAccess.Read);
×
13

14
                var usedEncoding = GetEncoding(stream, DefaultEncoding);
×
NEW
15
                if (usedEncoding.Equals(DefaultEncoding))
×
NEW
16
                        return FileAnalysisResult.RetainOriginal();
×
17

18
                var tempFile = Path.GetTempFileName();
×
19

20
                await using var tempWriter = new StreamWriter(tempFile, false, DefaultEncoding);
×
21
                using var fileReader = new StreamReader(stream, usedEncoding);
×
22
                await tempWriter.WriteAsync(await fileReader.ReadToEndAsync(cancellationToken));
×
23
                await tempWriter.FlushAsync(cancellationToken);
×
24

NEW
25
                return FileAnalysisResult.FixedAt(AnalysisSeverity.Warning, new FileInfo(tempFile));
×
26
        }
×
27

28
        private static Encoding GetEncoding(Stream stream, Encoding fallback)
29
        {
30
                using var reader = new StreamReader(stream, fallback, true);
×
31

32
                // Detect byte order mark if any - otherwise assume default
33
                _ = reader.Peek();
×
34

35
                return reader.CurrentEncoding;
×
36
        }
×
37
}
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