-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
feat: enable jumping to "not formatted" files from VisualStudio error list #1517
base: main
Are you sure you want to change the base?
Changes from 3 commits
dbced62
76a7c4b
7091394
3fc1a8a
ec1dac0
d129892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,14 @@ | |
|
||
namespace CSharpier.Cli; | ||
|
||
internal class FileIssueLogger(string filePath, ILogger logger) | ||
internal class FileIssueLogger(string filePath, ILogger logger, bool isMsBuildFormat) | ||
{ | ||
public void WriteError(string value, Exception? exception = null) | ||
{ | ||
logger.LogError(exception, $"{this.GetPath()} - {value}"); | ||
if (isMsBuildFormat) | ||
logger.LogError("{Path}: error: {Message}", this.GetPath(), value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also made WriteWarning() obey the --log-format parameter. |
||
else | ||
logger.LogError(exception, $"{this.GetPath()} - {value}"); | ||
} | ||
|
||
public void WriteWarning(string value) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
using System.IO.Abstractions.TestingHelpers; | ||
using System.Text; | ||
using CSharpier.Cli; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Logging; | ||
using NUnit.Framework; | ||
using System.IO.Abstractions.TestingHelpers; | ||
using System.Text; | ||
|
||
namespace CSharpier.Tests; | ||
|
||
[TestFixture] | ||
[Parallelizable(ParallelScope.All)] | ||
public class CommandLineFormatterTests | ||
{ | ||
private const bool IsMsBuildFormat = true; | ||
private const bool IsNotMsBuildFormat = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These don't appear to be used and should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed leftovers :) |
||
|
||
private const string UnformattedClassContent = "public class ClassName { public int Field; }"; | ||
private const string FormattedClassContent = | ||
"public class ClassName\n{\n public int Field;\n}\n"; | ||
|
@@ -362,6 +365,23 @@ public void Format_Checks_Unformatted_File() | |
.StartWith("Error ./Unformatted.cs - Was not formatted."); | ||
} | ||
|
||
[Test] | ||
public void Format_Checks_Unformatted_File_With_MsBuildFormat_Message() | ||
{ | ||
var context = new TestContext(); | ||
const string unformattedFilePath = "Unformatted.cs"; | ||
context.WhenAFileExists(unformattedFilePath, UnformattedClassContent); | ||
|
||
var result = Format(context, check: true, msBuildFormat: true); | ||
|
||
result.ExitCode.Should().Be(1); | ||
context.GetFileContent(unformattedFilePath).Should().Be(UnformattedClassContent); | ||
result | ||
.ErrorOutputLines.First() | ||
.Should() | ||
.StartWith("./Unformatted.cs: error: Was not formatted."); | ||
} | ||
|
||
[TestCase("Src/node_modules/File.cs")] | ||
[TestCase("node_modules/File.cs")] | ||
[TestCase("node_modules/Folder/File.cs")] | ||
|
@@ -750,6 +770,7 @@ private static FormatResult Format( | |
TestContext context, | ||
bool skipWrite = false, | ||
bool check = false, | ||
bool msBuildFormat = false, | ||
bool writeStdout = false, | ||
bool includeGenerated = false, | ||
bool compilationErrorsAsWarnings = false, | ||
|
@@ -772,7 +793,7 @@ params string[] directoryOrFilePaths | |
} | ||
|
||
var fakeConsole = new TestConsole(); | ||
var testLogger = new ConsoleLogger(fakeConsole, LogLevel.Information); | ||
var testLogger = new ConsoleLogger(fakeConsole, LogLevel.Information, msBuildFormat); | ||
var exitCode = CommandLineFormatter | ||
.Format( | ||
new CommandLineOptions | ||
|
@@ -782,6 +803,7 @@ params string[] directoryOrFilePaths | |
OriginalDirectoryOrFilePaths = originalDirectoryOrFilePaths, | ||
SkipWrite = skipWrite, | ||
Check = check, | ||
MsBuildFormat = msBuildFormat, | ||
WriteStdout = writeStdout || standardInFileContents != null, | ||
StandardInFileContents = standardInFileContents, | ||
IncludeGenerated = includeGenerated, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There have been requests for other log formats. I'm thinking this should be
--log-format
and accept a string/enum. Justmsbuild
anddefault
(or maybe call itconsole
?) for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed Startparameter and used enum as suggested.