Skip to content

Omit Default modifier style & code fix#23919

Merged
sharwell merged 10 commits intodotnet:dev15.7.xfrom
clairernovotny:default-modifier-style
Feb 1, 2018
Merged

Omit Default modifier style & code fix#23919
sharwell merged 10 commits intodotnet:dev15.7.xfrom
clairernovotny:default-modifier-style

Conversation

@clairernovotny
Copy link

This a PR to implement #7066

@clairernovotny clairernovotny requested a review from a team as a code owner December 22, 2017 20:51
@jasonmalinowski
Copy link
Member

@jinujoseph or @mavasani should this PR be targeting https://github.com/dotnet/roslyn-analyzers?

@clairernovotny
Copy link
Author

clairernovotny commented Dec 23, 2017

@jasonmalinowski this is an .editorconfig code style setting. From the discussion in the linked issue, it sounded like I should just mirror what @CyrusNajmabadi did in another PR. It would need to be here to be available as a default .editorconfig setting for all, right?

@clairernovotny clairernovotny force-pushed the default-modifier-style branch 4 times, most recently from c3290e9 to c3168ac Compare December 23, 2017 01:40
@jasonmalinowski
Copy link
Member

@onovotny There's a simultaneous effort to move them, I think.

@clairernovotny
Copy link
Author

@jasonmalinowski okay, gotcha.

@clairernovotny
Copy link
Author

I'm not entirely sure how to get the default accessibility for a member here:

https://github.com/onovotny/roslyn/blob/3028358c96e7f0b75aefd6416ba679d97e5970de/src/Features/CSharp/Portable/OmitDefaultAccessibilityModifiers/CSharpOmitDefaultAccessibilityModifiersDiagnosticAnalyzer.cs#L86

I have to assume these rules are somewhere that I should be checking? -- class is internal, members in a type private, etc?

@clairernovotny
Copy link
Author

Also frequently getting this trying to attach to the GUI worker process:
image

I have to restart VS and then I can do it once....

@clairernovotny
Copy link
Author

I have something working, though not sure if the right way. I am seeing a whitepace issue on the test though:

Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.OmitDefaultAccessibilityModifiers.OmitDefaultAccessibilityModifiersTests.TestAllConstructs FAILED:
	Exception type: 'Xunit.Sdk.EqualException', number: '0', parent: '-1'
	Exception message:
Assert.Equal() Failure
                                   ↓ (pos 506)
Expected: ···    static C() { }\r\n            C() { }\r\n            public C···
Actual:   ···    static C() { }\r\n\r\n            C() { }\r\n            public···
                                   ↑ (pos 506)
	Exception stacktrace

@clairernovotny
Copy link
Author

With some feedback, I can continue on the VB.NET side.

Thanks!

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

I don't like having a separate option or a separate diagnostic ID for this. We should take it to a design meeting to resolve when people come back from vacation.

@sharwell
Copy link
Contributor

sharwell commented Dec 24, 2017

My preferred approach is having a tri-state option, like this:

dotnet_default_accessibility_modifiers = allow|require|omit:severity

Since there appears to be a difference of opinions, we should wait for everyone to be back focused on work instead of various family outings, and resolve this in a design meeting in the new year. 😄

@clairernovotny
Copy link
Author

clairernovotny commented Dec 24, 2017

@sharwell I agree with you. I thought it should be part of the same option. You can see that there's debate on this #7066 (comment).

I agree this should go to a design meeting and I'm happy to update this as per the decision.

Question to think about: the current option, which is shipping, is dotnet_style_require_accessibility_modifiers. Is there a way to rename that to dotnet_style_default_accessibility_modifiers without breaking people who already are using the current option? I'm not sure if there's a mapping mechanism if you want to rename the setting name.

{
public CSharpOmitDefaultAccessibilityModifiersDiagnosticAnalyzer()
{
}
Copy link
Contributor

Choose a reason for hiding this comment

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

seems unnecessary.

{
// Default is internal
if (accessibility != Accessibility.Internal)
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

curlies always required.

return;
}

if(parentKind == SyntaxKind.ClassDeclaration ||
Copy link
Contributor

Choose a reason for hiding this comment

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

space after 'if'.


// Check for default modifiers
var parentKind = member.Parent?.Kind();
if(parentKind == null || parentKind == SyntaxKind.NamespaceDeclaration)
Copy link
Contributor

Choose a reason for hiding this comment

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

space after if.

Copy link
Contributor

Choose a reason for hiding this comment

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

i don't see how you could ever have a null parent.

Copy link
Author

Choose a reason for hiding this comment

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

What is the parent of a type that's not in a namespace? I can add a test for that if that'd be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

A CompilationUnitSyntax. Test would be valuable :)

Copy link
Author

Choose a reason for hiding this comment

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

Done. Changed the analyzer and added a test to cover that and it passes. Still stuck on the extra CR being added on the main test. Nothing I've added should be adding a space, so is there an interfering default somewhere?

@kuhlenh
Copy link

kuhlenh commented Jan 4, 2018

@onovotny thanks for your patience! We are meeting next week and will have an answer for you by the end of next week on design here...

@clairernovotny
Copy link
Author

@kuhlenh Thanks! IMO, I think @sharwell is right and it should be a single rule called dotnet_style_default_accessibility_modifiers. I don't know what kind of remapping mechanisms might exist for backwards compat though, if that's an issue.

@CyrusNajmabadi
Copy link
Contributor

I don't know what kind of remapping mechanisms might exist for backwards compat though, if that's an issue.

You can provide arbitrary code to handle this sort of thing. At least a couple of our binary options have become tri-state and then handle the processing accordingly. For example the expression-body option gained 'when on single line' in a backward compatible manner.

@clairernovotny
Copy link
Author

@CyrusNajmabadi In that case, or in any other, has the name of the option itself changed or just the available values that can be set for it?

@CyrusNajmabadi
Copy link
Contributor

Just the option. However, we could always add the codepath that allows for the name to change as well. :)

@sharwell
Copy link
Contributor

@onovotny Design meeting was today. We decided to use the current option (no rename), and to just add a third allowed value:

  • true: Currently supported, and meaning does not change
  • false: Currently supported, and meaning does not change
  • omit_if_default: New value, supported after this is merged. Old versions of Visual Studio will see this as an invalid value, and fall back to the default value false.

This is desirable since it means for all users, the behavior in old versions is unchanged regardless of whether the project adopts the new syntax.

@CyrusNajmabadi
Copy link
Contributor

@onovotny It would be painful, and it's totally my fault for leading you down the wrong path, but i think this should all go into a single analyzer/fixer. Basically its the same analyzer fixer that checks your code against the option, and then fixes it accordingly. Right now, having it be two separate ones means basically near 100% duplication, whne all that really had to change is the simple check, and what the fix does.

:(

@clairernovotny
Copy link
Author

clairernovotny commented Jan 10, 2018

@CyrusNajmabadi No problem. I'll update my code accordingly. Is there any chance of this hitting 15.6, and if so, what would the deadlines be before it's too late?

@sharwell sharwell changed the base branch from master to dev15.7.x January 25, 2018 17:30
@sharwell sharwell changed the base branch from dev15.7.x to master January 25, 2018 17:31
@sharwell
Copy link
Contributor

@Pilchie I'd like to merge this in 15.7. Can I get an ask mode bar check before doing the rebase it would need?

@clairernovotny
Copy link
Author

clairernovotny commented Jan 31, 2018

Ping? :)

@Pilchie Pilchie added this to the 15.7 milestone Jan 31, 2018
@Pilchie
Copy link
Member

Pilchie commented Jan 31, 2018

Approved for 15.7 - sorry for the delay. Note that it will need to be rebased though (master will be next foundational update, not 15.7)

@sharwell
Copy link
Contributor

@onovotny Please let me know if you would like me to do the rebase or if you would like to do it yourself. :)

@clairernovotny
Copy link
Author

@sharwell if you don't mind, I'd really appreciate it. Not sure what's diverged w.r.t. the changes in this batch.

@sharwell
Copy link
Contributor

@onovotny Nothing diverged, we just want to ship the change earlier than the master branch will ship next. I'll get the rebase done and then we can merge it after the build passes. 😄

@clairernovotny
Copy link
Author

@sharwell Thank you!

@clairernovotny
Copy link
Author

This will be my first contribution to Roslyn 🎉

@sharwell sharwell force-pushed the default-modifier-style branch from 410bbaf to 12c5f27 Compare January 31, 2018 16:48
@clairernovotny clairernovotny requested review from a team as code owners January 31, 2018 16:48
@sharwell sharwell changed the base branch from master to dev15.7.x January 31, 2018 16:48
@jcouv
Copy link
Member

jcouv commented Jan 31, 2018

windows_release_unit32_prtest failed on DiagnosticDataTests.DiagnosticData_GetText6 (details)

FYI @dotnet/roslyn-infrastructure I'll re-run

@jcouv
Copy link
Member

jcouv commented Jan 31, 2018

test windows_release_unit32_prtest please

@sharwell sharwell merged commit 009c90b into dotnet:dev15.7.x Feb 1, 2018
@clairernovotny clairernovotny deleted the default-modifier-style branch February 1, 2018 19:46
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.

7 participants