Skip to content
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

EditorConfig comments cannot follow a property value #51625

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Mar 3, 2021

Related to editorconfig/specification#23 and editorconfig/specification#31

Fixes #44596

⚠️ This is a breaking change for users who previously wrote comments at the end of lines in .editorconfig. I wasn't able to find a specific example but @Youssef1313 found this one:

dotnet_diagnostic.CA2007.severity = none # Disable warnings about ConfigureAwait, since this is a console app
dotnet_diagnostic.VSTHRD111.severity = none # Disable warnings about ConfigureAwait, since this is a console app

💭 I do notice that all cases we've found that seem to be affected involve a dotnet_diagnostic line. Since this is a compiler-controlled property interpretation, we do have the option of modifying the interpretation of that value to ignore text after a ; or #.

@sharwell sharwell requested a review from a team as a code owner March 3, 2021 15:10
Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break existing editorconfigs that used # as a comment after a value? Just noticed you already stated that.

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you update this as well?

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax highlighting of editorconfig in Visual Studio should reflect this.
Not sure if it belongs to this repository or it's an internal.

Also we might want VSCode to reflect this in syntax highlighting as well:

image

Should we file an issue to vscode repo?

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell
Copy link
Member Author

sharwell commented Mar 3, 2021

Needs a parallel change in roslyn-analyzers:

roslyn-analyzers already doesn't follow the spec, so I'd rather delete the custom support there than try to maintain it.

Copy link
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not merge this until we get confirmation that this is actually the correct behavior. There seems to be some belief that this is a spec defect

Base automatically changed from master to main March 3, 2021 23:53
@@ -177,15 +177,18 @@ public void SpacesInProperties()
properties);
}

[Fact]
public void EndOfLineComments()
[Theory]
Copy link
Member

@jcouv jcouv Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Documented for .NET 9

var trimmed = value.AsSpan();
var commentStartIndex = trimmed.IndexOfAny(commentStartCharacters);
if (commentStartIndex >= 0)
trimmed = trimmed[0..commentStartIndex].TrimEnd();
Copy link
Member

@jcouv jcouv Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, this change is to maintain the existing behavior and I assume we already have tests covering this. Is that right? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Yes, and tests have now been added.

@jcouv
Copy link
Member

jcouv commented Mar 23, 2021

Just saw Jon's comment above. I'll mark this PR as draft for now.
Did we start a conversation to confirm the desired behavior?

@Youssef1313
Copy link
Member

Youssef1313 commented Jan 1, 2023

Lets not merge this until we get confirmation that this is actually the correct behavior. There seems to be some belief that this is a spec defect

@jmarolf @jcouv @sharwell The spec is now updated editorconfig/specification#31 and it's clear what the correct behavior is.

Can this get reviewed and merged?

@@ -21,7 +21,7 @@ public sealed partial class AnalyzerConfig
// Matches EditorConfig section header such as "[*.{js,py}]", see https://editorconfig.org for details
private static readonly Regex s_sectionMatcher = new Regex(@"^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$", RegexOptions.Compiled);
// Matches EditorConfig property such as "indent_style = space", see https://editorconfig.org for details
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$", RegexOptions.Compiled);
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*$", RegexOptions.Compiled);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[=:]

Why are we considering both = and : to separate the key and the value? I don't think key : value should be allowed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ I have no idea, but that seems beyond the scope of this change.

@AnalogFeelings
Copy link

Any progress on this? This issue makes inserting the GPL license text impossible as it gets truncated.

@sharwell sharwell marked this pull request as ready for review January 5, 2024 21:00
@sharwell sharwell requested a review from a team as a code owner January 8, 2024 14:19
"refactoring" => ReportDiagnostic.Hidden,
"suggestion" => ReportDiagnostic.Info,
"warning" => ReportDiagnostic.Warn,
"error" => ReportDiagnostic.Error,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer these just be arguments to this test method, so the switch isn't needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer these just be arguments to this test method, so the switch isn't needed.

➡️ The current form is intentional. Arguments to the test method are input state and are used to define the unique ID of the test itself. Expected results should not be inputs, and changing an expected outcome should not be part of the test identity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree with Cyrus here -- we normally put the expected as an input too...

Copy link
Member Author

@sharwell sharwell Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we normally put the expected as an input too

➡️ I try to fix these when they occur in a method I'm working on. Test parameterization should only ever exist on the inputs, not the outputs. The entire test identity and reporting strategy (e.g. test historical pass rates, red/green developer iterations in TDD) is built around this premise.

@sharwell
Copy link
Member Author

sharwell commented Jan 8, 2024

Few popular repositories that are going to be affected:

Note that none of these will be affected now that dotnet_diagnostic.*.severity parsing has been updated to ignore text that was previously a comment.

Comment on lines 7 to 9
The compiler is updated based on the EditorConfig specification clarification in
[editorconfig/specification#31](https://github.com/editorconfig/specification/pull/31). This changes the way values are
passed to analyzers for lines with the following form:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples are great, but this might be clear too if we just say "comments now must be on their own line; comments after a value are treated as a part of the value."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Updated the text


## .editorconfig values no longer support trailing comments

***Introduced in Visual Studio 2022 version [TBD]***
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a reminder to fix this prior to merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Do we know what the value here is going to be?

"refactoring" => ReportDiagnostic.Hidden,
"suggestion" => ReportDiagnostic.Info,
"warning" => ReportDiagnostic.Warn,
"error" => ReportDiagnostic.Error,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree with Cyrus here -- we normally put the expected as an input too...

Comment on lines +997 to +998
[InlineData("#")]
[InlineData(";")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider tweaking the inline data to add another case like:

Suggested change
[InlineData("#")]
[InlineData(";")]
[InlineData("error # ignored text")]
[InlineData("error ; ignored text")]
[InlineData("warning ; ignored text")]

As otherwise this test could incorrectly pass if all parse errors were simply converted to ReportDiagnostic.Error.

Copy link
Member Author

@sharwell sharwell Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Added a second line inside the test itself.

/// files. For code style options maintained by Roslyn, we continue to detect and remove these "comments" for
/// backwards compatibility.
/// </summary>
private static readonly char[] s_commentDelimiters = ['#', ';'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to share this code/list with the compiler code doing the same thing? The file path here makes me think we've already got shared files between both layers to use here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ The sharing here is between the workspaces and code style layers. The compiler maintains its own back-compat separately.

@jasonmalinowski
Copy link
Member

Overall though I love the approach to maintain compat -- simply treating this as a break would have been far too icky for these scenarios.

@@ -21,7 +21,7 @@ public sealed partial class AnalyzerConfig
// Matches EditorConfig section header such as "[*.{js,py}]", see https://editorconfig.org for details
private static readonly Regex s_sectionMatcher = new Regex(@"^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$", RegexOptions.Compiled);
// Matches EditorConfig property such as "indent_style = space", see https://editorconfig.org for details
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$", RegexOptions.Compiled);
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*$", RegexOptions.Compiled);
Copy link
Contributor

@ToddGrun ToddGrun Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably outside the scope of this PR, but should we be allowing whitespace within the key?

eg:
test value = allowed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that we do not currently support whitespace inside the key, but according to the specification it should be allowed:

Key: The part before the first = (trimmed of whitespace, but including any whitespace in the middle).

Can you file a new issue for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Delsin-Yu
Copy link

Any movement on this?

@raulsntos
Copy link
Contributor

What's the status of this PR? Since the PR documents the breaking change in .NET 9, is it safe to assume it will be merged for that release?

@@ -330,33 +330,40 @@ static void freeKey(List<Section> sectionKey, ObjectPool<List<Section>> pool)

internal static bool TryParseSeverity(string value, out ReportDiagnostic severity)
{
ReadOnlySpan<char> commentStartCharacters = stackalloc char[] { ';', '#' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider leaving a comment ("for backcompat, ...")

var comparer = StringComparer.OrdinalIgnoreCase;
if (comparer.Equals(value, "default"))
if (trimmed.Equals("default".AsSpan(), StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparer local on line above (339) no longer seems to be used


## .editorconfig values no longer support trailing comments

***Introduced in Visual Studio 2022 version 17.[TBD]***
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagging @jaredpar to advise on which release to pull this change into, since it involves a compat break. Feels like we should hold this off rather than squeeze it late in the release cycle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either update this before merging, or open an issue to track updating it once we know which release it landed in.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler changes LGTM Thanks (iteration 6)

@jcouv jcouv self-assigned this Sep 30, 2024
@jcouv
Copy link
Member

jcouv commented Oct 16, 2024

@dotnet/roslyn-compiler for a second review. Thanks

1 similar comment
@jcouv
Copy link
Member

jcouv commented Oct 30, 2024

@dotnet/roslyn-compiler for a second review. Thanks


## .editorconfig values no longer support trailing comments

***Introduced in Visual Studio 2022 version 17.[TBD]***
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either update this before merging, or open an issue to track updating it once we know which release it landed in.

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting a hold on this given it's a breaking change in editorconfig and we're trying ot discuss what paths for that look like.

@jcouv jcouv marked this pull request as draft November 21, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.editorconfig file_header_template: can't use # (or ;) symbol