Skip to content

Commit 764a0b6

Browse files
committed
code quality
1 parent ce3284d commit 764a0b6

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

SDK/dotnet/src/ManagedCode.Tps/Internal/TpsContentCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ManagedCode.Tps.Internal;
55

66
internal sealed class TpsContentCompiler
77
{
8-
public ContentCompilationResult Compile(
8+
public static ContentCompilationResult Compile(
99
string rawText,
1010
int startOffset,
1111
InheritedFormattingState inherited,

SDK/dotnet/src/ManagedCode.Tps/Internal/TpsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ManagedCode.Tps.Internal;
77

88
internal sealed partial class TpsParser
99
{
10-
public DocumentAnalysis Parse(string source)
10+
public static DocumentAnalysis Parse(string source)
1111
{
1212
var normalized = TpsSupport.NormalizeLineEndings(source);
1313
var lineStarts = TpsSupport.CreateLineStarts(normalized);

SDK/dotnet/src/ManagedCode.Tps/ManagedCode.Tps.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
78
<AssemblyName>ManagedCode.Tps</AssemblyName>
89
<RootNamespace>ManagedCode.Tps</RootNamespace>
910
<PackageId>ManagedCode.Tps</PackageId>
11+
12+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
13+
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
14+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1015
</PropertyGroup>
1116

1217
</Project>

SDK/dotnet/src/ManagedCode.Tps/TpsPlayer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public PlayerState GetState(int elapsedMs)
3333
var clampedElapsed = Math.Clamp(elapsedMs, 0, Script.TotalDurationMs);
3434
var currentWord = FindCurrentWord(clampedElapsed);
3535
var currentSegment = currentWord is null
36-
? Script.Segments.FirstOrDefault()
36+
? Script.Segments.Count > 0 ? Script.Segments[0] : null
3737
: _segmentById.GetValueOrDefault(currentWord.SegmentId);
3838
var currentBlock = currentWord is null
39-
? currentSegment?.Blocks.FirstOrDefault()
39+
? currentSegment is not null && currentSegment.Blocks.Count > 0 ? currentSegment.Blocks[0] : null
4040
: _blockById.GetValueOrDefault(currentWord.BlockId);
4141
var currentPhrase = currentWord is null
42-
? currentBlock?.Phrases.FirstOrDefault()
42+
? currentBlock is not null && currentBlock.Phrases.Count > 0 ? currentBlock.Phrases[0] : null
4343
: _phraseById.GetValueOrDefault(currentWord.PhraseId);
4444
var currentWordIndex = currentWord?.Index ?? -1;
4545
var previousWord = currentWordIndex > 0 ? Script.Words[currentWordIndex - 1] : null;

SDK/dotnet/src/ManagedCode.Tps/TpsRuntime.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class TpsRuntime
77
{
88
public static TpsValidationResult Validate(string source)
99
{
10-
var analysis = new TpsParser().Parse(source);
10+
var analysis = TpsParser.Parse(source);
1111
CompileAnalysis(analysis);
1212
return new TpsValidationResult
1313
{
@@ -18,7 +18,7 @@ public static TpsValidationResult Validate(string source)
1818

1919
public static TpsParseResult Parse(string source)
2020
{
21-
var analysis = new TpsParser().Parse(source);
21+
var analysis = TpsParser.Parse(source);
2222
CompileAnalysis(analysis);
2323
return new TpsParseResult
2424
{
@@ -30,7 +30,7 @@ public static TpsParseResult Parse(string source)
3030

3131
public static TpsCompilationResult Compile(string source)
3232
{
33-
var analysis = new TpsParser().Parse(source);
33+
var analysis = TpsParser.Parse(source);
3434
var script = CompileAnalysis(analysis);
3535
return new TpsCompilationResult
3636
{
@@ -144,7 +144,7 @@ private static BlockCandidate CompileBlock(BlockDefinition definition, Inherited
144144
inherited.SpeedOffsets,
145145
blockArchetype);
146146

147-
var content = new TpsContentCompiler().Compile(
147+
var content = TpsContentCompiler.Compile(
148148
definition.Content?.Text ?? string.Empty,
149149
definition.Content?.StartOffset ?? 0,
150150
blockInherited,

0 commit comments

Comments
 (0)