Skip to content

Strip common prefixes before applying naming suggestions#26589

Merged
sharwell merged 6 commits intodotnet:masterfrom
sharwell:strip-prefixes
Jun 7, 2018
Merged

Strip common prefixes before applying naming suggestions#26589
sharwell merged 6 commits intodotnet:masterfrom
sharwell:strip-prefixes

Conversation

@sharwell
Copy link
Copy Markdown
Contributor

@sharwell sharwell commented May 3, 2018

Fixes #26566

Ask Mode template not completed

Customer scenario

What does the customer do to get into this situation, and why do we think this
is common enough to address for this release. (Granted, sometimes this will be
obvious "Open project, VS crashes" but in general, I need to understand how
common a scenario is)

Bugs this fixes

(either VSO or GitHub links)

Workarounds, if any

Also, why we think they are insufficient for RC vs. RC2, RC3, or RTW

Risk

This is generally a measure our how central the affected code is to adjacent
scenarios and thus how likely your fix is to destabilize a broader area of code

Performance impact

(with a brief justification for that assessment (e.g. "Low perf impact because no extra allocations/no complexity changes" vs. "Low")

Is this a regression from a previous update?

Root cause analysis

How did we miss it? What tests are we adding to guard against it in the future?

How was the bug found?

(E.g. customer reported it vs. ad hoc testing)

Test documentation updated?

If this is a new non-compiler feature or a significant improvement to an existing feature, update https://github.com/dotnet/roslyn/wiki/Manual-Testing once you know which release it is targeting.

@sharwell sharwell requested a review from a team as a code owner May 3, 2018 15:56
@jcouv jcouv added the Area-IDE label May 3, 2018
@Neme12
Copy link
Copy Markdown
Contributor

Neme12 commented May 3, 2018

I think I saw some separate tests specifically for generating and updating names somewhere, and I think they were in VB. So that might be a better place to put all these cases in.

@sharwell
Copy link
Copy Markdown
Contributor Author

sharwell commented May 3, 2018

@Neme12 I wasn't able to find any naming styles tests for VB. Do you know where they are?

@Neme12
Copy link
Copy Markdown
Contributor

Neme12 commented May 3, 2018

Sorry, I wasn't clear enough. The tests don't test VB code, they're just written in VB. I found them:
http://source.roslyn.io/#Roslyn.Services.Editor2.UnitTests/Diagnostics/NamingStyles/NamingStyleTests.IdentifierCreation.Casing.vb

But given that they only test the internal helpers, not the code fix itself to make sure everything is wired up properly, your addition is still useful as is.

[InlineData("M__", "_")]
[InlineData("S_", "_s_")]
[InlineData("T_", "_t_")]
[InlineData("M_S__T_", "_t_")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

expected tests with just _'s or also, _m also tests of something like _moop

@sharwell sharwell added this to the 15.8 milestone May 25, 2018
Copy link
Copy Markdown
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Looks good!

prefix: "",
suffix: "",
wordSeparator: "");
var namingRule = new SerializableNamingRule()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: either add blank lines between all of the statements (preferred) or remove the one above.

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell Jun 6, 2018

Choose a reason for hiding this comment

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

➡️ Fixed in a93570e

prefix: "_",
suffix: "",
wordSeparator: "");
var namingRule = new SerializableNamingRule()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: either add blank lines between all of the statements (preferred) or remove the one above.

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell Jun 6, 2018

Choose a reason for hiding this comment

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

➡️ Fixed in a93570e

var index = 0;
while (name.Length > index + 1)
{
switch (char.ToLowerInvariant(name[index]))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I don't think the case indentation below matches the repo style.

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell Jun 6, 2018

Choose a reason for hiding this comment

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

➡️ It doesn't. I tried to fix this in #22143 but the change never moved forward. Until then the repo style is "user selection". The specific line for this scenario is:

csharp_indent_switch_labels = true

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell Jun 6, 2018

Choose a reason for hiding this comment

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

➡️ Fixed in 793ed33

private static string StripCommonPrefixes(string name)
{
var index = 0;
while (name.Length > index + 1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I kind of expected to see this expression inverted as I think it reads better. Totally not a big deal though. That's kind of in the eye of the beholder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I assumed from the form that name was getting written in the loop. Since it's not written, I definitely expected to see this the other way around.

Copy link
Copy Markdown
Contributor Author

@sharwell sharwell Jun 6, 2018

Choose a reason for hiding this comment

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

➡️ Fixed in a93570e

{
case 'm':
case 's':
case 't':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about 'g'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For now I just used the prefixes deemed "common" by the old StyleCop implementation. We can add others if we want to, but probably as a separate issue. Want me to file a bug for this?

[InlineData("M__", "_")]
[InlineData("S_", "s_")]
[InlineData("T_", "t_")]
[InlineData("M_S__T_", "t_")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What tests that start with underscores but have a prefix, like __s_bar? The algorithm covers those too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The algorithm covers these, but none of the tests will work currently due to #26588. I expect to see the remaining test cases added as part of that work, but I can also add placeholders (skipped) here if you want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

➡️ Added in add68b0

@sharwell sharwell changed the base branch from master to dev15.8-preview3 June 6, 2018 20:26
@sharwell sharwell changed the base branch from dev15.8-preview3 to master June 7, 2018 19:48
@jinujoseph
Copy link
Copy Markdown
Contributor

Approved to merge for 15.8.Preview4

@sharwell sharwell merged commit c4bc724 into dotnet:master Jun 7, 2018
@sharwell sharwell deleted the strip-prefixes branch June 7, 2018 20:43
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.

Naming violation code fix should strip known common prefixes

7 participants