Skip to content

SpaceBeforeSquareBrackets doesn't ignore C# 'is' keyword #61965

@StrangeRanger

Description

@StrangeRanger

It doesn't look like the option SpaceBeforeSquareBrackets for clang-format takes into consideration the C# is the keyword. It seems like it's identified as a possible variable, despite it being a keyword. So it removes any space between is and the braces.

Here is an example:

Screenshot 2023-04-05 at 2 50 07 PM

Here is the all the code from the files, for context:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Logger.Tests;

[TestClass]
public class FileLoggerTests : FileLoggerTestsBase
{
    [TestMethod]
    public void Create_GivenClassAndValidFileName_Success()
    {
        Assert.AreEqual(nameof(FileLoggerTests), Logger.LogSource);
        Assert.AreEqual(FilePath, Logger.FilePath);
    }

    [TestMethod]
    public async Task Log_Message_FileAppended()
    {
        Logger.Log(LogLevel.Error, "Message1");
        Logger.Log(LogLevel.Error, "Message2");

        string[] lines = await File.ReadAllLinesAsync(FilePath);
        Assert.IsTrue(lines is[..] and { Length : 2 });
        foreach (string[] line in lines.Select(line => line.Split(',', 4)))
        {
            if (line is[string dateTime, string source, string levelText, string message])
            {
                Assert.IsTrue(DateTime.TryParse(dateTime, out _));
                Assert.AreEqual(nameof(FileLoggerTests), source);
                Assert.IsTrue(Enum.TryParse(typeof(LogLevel), levelText, out object? level) ?
                    level is LogLevel.Error : false,"Level was not parsed successfully.");
            }
        }
    }
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions