Omit Default modifier style & code fix#23919
Conversation
|
@jinujoseph or @mavasani should this PR be targeting https://github.com/dotnet/roslyn-analyzers? |
|
@jasonmalinowski this is an |
c3290e9 to
c3168ac
Compare
|
@onovotny There's a simultaneous effort to move them, I think. |
|
@jasonmalinowski okay, gotcha. |
|
I'm not entirely sure how to get the default accessibility for a member here: I have to assume these rules are somewhere that I should be checking? -- class is internal, members in a type private, etc? |
|
I have something working, though not sure if the right way. I am seeing a whitepace issue on the test though: |
|
With some feedback, I can continue on the VB.NET side. Thanks! |
sharwell
left a comment
There was a problem hiding this comment.
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.
|
My preferred approach is having a tri-state option, like this: 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. 😄 |
|
@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 |
| { | ||
| public CSharpOmitDefaultAccessibilityModifiersDiagnosticAnalyzer() | ||
| { | ||
| } |
| { | ||
| // Default is internal | ||
| if (accessibility != Accessibility.Internal) | ||
| return; |
There was a problem hiding this comment.
curlies always required.
| return; | ||
| } | ||
|
|
||
| if(parentKind == SyntaxKind.ClassDeclaration || |
|
|
||
| // Check for default modifiers | ||
| var parentKind = member.Parent?.Kind(); | ||
| if(parentKind == null || parentKind == SyntaxKind.NamespaceDeclaration) |
There was a problem hiding this comment.
i don't see how you could ever have a null parent.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
A CompilationUnitSyntax. Test would be valuable :)
There was a problem hiding this comment.
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?
386248e to
d874e97
Compare
|
@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... |
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. |
|
@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? |
|
Just the option. However, we could always add the codepath that allows for the name to change as well. :) |
|
@onovotny Design meeting was today. We decided to use the current option (no rename), and to just add a third allowed value:
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. |
|
@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. :( |
|
@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? |
d874e97 to
8e260f8
Compare
|
@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? |
|
Ping? :) |
|
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) |
|
@onovotny Please let me know if you would like me to do the rebase or if you would like to do it yourself. :) |
|
@sharwell if you don't mind, I'd really appreciate it. Not sure what's diverged w.r.t. the changes in this batch. |
|
@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. 😄 |
|
@sharwell Thank you! |
|
This will be my first contribution to Roslyn 🎉 |
410bbaf to
12c5f27
Compare
|
windows_release_unit32_prtest failed on DiagnosticDataTests.DiagnosticData_GetText6 (details) FYI @dotnet/roslyn-infrastructure I'll re-run |
|
test windows_release_unit32_prtest please |

This a PR to implement #7066