-
Notifications
You must be signed in to change notification settings - Fork 49
Implement compiler warnings #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec71290
Implement throwing and processing warnings in the codegen pipeline. A…
evgTSV e8f5416
Amend JsonObjectFileTests.cs to work with the new CompilationOptions'…
evgTSV d135487
Add tests for StringFormatExtensions
evgTSV 53fdccf
Remove BOM bytes
evgTSV afe219d
(#978) Core: minor fixes
ForNeVeR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // SPDX-FileCopyrightText: 2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| using Cesium.Core; | ||
| using Cesium.Core.Warnings; | ||
|
|
||
| namespace Cesium.CodeGen; | ||
|
|
||
| public class CompilerWarningProcessor(WarningsSet set) : IWarningProcessor<CompilerWarning> | ||
| { | ||
| public void EmitWarning(CompilerWarning warning) | ||
| { | ||
| if (set.HasFlag(warning.Set)) | ||
| Console.Error.WriteLine($"Warning: {warning.Message} [-W{warning.Set.ToString().FromCamelToKebab()}]"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: 2025-2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
|
|
||
| SPDX-License-Identifier: MIT | ||
| --> | ||
|
|
||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| <PackageReference Include="xunit" /> | ||
| <PackageReference Include="xunit.runner.visualstudio"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Cesium.Core\Cesium.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-FileCopyrightText: 2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| namespace Cesium.Core.Tests; | ||
|
|
||
| public class StringFormatExtensionsTest | ||
| { | ||
| [Theory] | ||
| [InlineData("", "")] | ||
| [InlineData("hello", "Hello")] | ||
| [InlineData("hello-world", "HelloWorld")] | ||
| [InlineData("-hello", "Hello")] | ||
| [InlineData("hello-", "Hello")] | ||
| [InlineData("hello--world", "HelloWorld")] | ||
| [InlineData("---", "")] | ||
| [InlineData("hello-123", "Hello123")] | ||
| [InlineData("a-b-123", "AB123")] | ||
| [InlineData("HELLO-WORLD", "HELLOWORLD")] | ||
| [InlineData("a", "A")] | ||
| [InlineData("a-b", "AB")] | ||
| public void StringFromKebabToCamelTest(string input, string expected) | ||
| => Assert.Equal(expected, input.FromKebabToCamel()); | ||
|
|
||
| [Theory] | ||
| [InlineData("", "")] | ||
| [InlineData("Hello", "hello")] | ||
| [InlineData("HelloWorld", "hello-world")] | ||
| [InlineData("hello", "hello")] | ||
| [InlineData("HELLO", "hello")] | ||
| [InlineData("XMLHttpRequest", "xml-http-request")] | ||
| [InlineData("Hello123", "hello-123")] | ||
| [InlineData("Hello123World", "hello-123-world")] | ||
| [InlineData("A", "a")] | ||
| [InlineData("a", "a")] | ||
| [InlineData("123", "123")] | ||
| [InlineData("A1B2", "a-1-b-2")] | ||
| [InlineData("AbcDef", "abc-def")] | ||
| public void StringFromCamelToKebabTest(string input, string expected) | ||
| => Assert.Equal(expected, input.FromCamelToKebab()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // SPDX-FileCopyrightText: 2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| using System.Text; | ||
|
|
||
| namespace Cesium.Core; | ||
|
|
||
| public static class StringFormatExtensions | ||
| { | ||
| extension(ReadOnlySpan<char> str) | ||
| { | ||
| public string FromKebabToCamel() | ||
| { | ||
| if (str.IsEmpty) return string.Empty; | ||
|
|
||
| var sb = new StringBuilder(); | ||
|
|
||
| foreach (var part in str.Split('-')) | ||
| { | ||
| if (part.Start.Value == part.End.Value) | ||
| continue; | ||
|
|
||
| sb.Append(char.ToUpper(str[part.Start])); | ||
|
|
||
| if (part.Start.Value != part.End.Value) | ||
| sb.Append(str[(part.Start.Value + 1)..part.End]); | ||
| } | ||
|
|
||
| return sb.ToString(); | ||
| } | ||
|
|
||
| public string FromCamelToKebab() | ||
| { | ||
| if (str.IsEmpty) return string.Empty; | ||
|
|
||
| var sb = new StringBuilder(); | ||
|
|
||
| for (int i = 0; i < str.Length; i++) | ||
| { | ||
| if (char.IsLower(str[i])) | ||
| sb.Append(str[i]); | ||
| else if (i == 0) | ||
| sb.Append(char.ToLower(str[i])); | ||
| else if (char.IsDigit(str[i]) && !char.IsDigit(str[i - 1])) | ||
| sb.Append('-').Append(str[i]); | ||
| else if (char.IsDigit(str[i])) | ||
| sb.Append(str[i]); | ||
| else if (char.IsLower(str[i - 1])) | ||
| sb.Append('-').Append(char.ToLower(str[i])); | ||
| else if (i + 1 == str.Length || char.IsUpper(str[i + 1])) | ||
| sb.Append(char.ToLower(str[i])); | ||
| else | ||
| sb.Append('-').Append(char.ToLower(str[i])); | ||
| } | ||
|
|
||
| return sb.ToString(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-FileCopyrightText: 2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| namespace Cesium.Core.Warnings; | ||
|
|
||
| public record CompilerWarning(string Message, WarningsSet Set) | ||
| : DiagnosticWarning(new SourceLocationInfo(string.Empty, 0, 0), Message); | ||
|
ForNeVeR marked this conversation as resolved.
|
||
| // TODO: In future we have to determine a location where a warning is triggered | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-FileCopyrightText: 2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| namespace Cesium.Core.Warnings; | ||
|
|
||
| public record DiagnosticWarning(SourceLocationInfo Location, string Message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| // SPDX-FileCopyrightText: 2025 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // SPDX-FileCopyrightText: 2025-2026 Cesium contributors <https://github.com/ForNeVeR/Cesium> | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| namespace Cesium.Core.Warnings; | ||
|
|
||
| public interface IWarningProcessor | ||
| public interface IWarningProcessor<in T> where T : DiagnosticWarning | ||
| { | ||
| public void EmitWarning(PreprocessorWarning warning); | ||
| public void EmitWarning(T warning); | ||
| } | ||
|
ForNeVeR marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.