-
Notifications
You must be signed in to change notification settings - Fork 509
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
First approach of rule SA1140 MaximumLineLength #2302
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2302 +/- ##
==========================================
+ Coverage 96.84% 96.84% +<.01%
==========================================
Files 598 600 +2
Lines 84061 84159 +98
Branches 3200 3210 +10
==========================================
+ Hits 81406 81504 +98
Misses 1790 1790
Partials 865 865
Continue to review full report at Codecov.
|
stylecop.settings is stylecop.json
Corrected some copy paste errors and added example for documentation |
Tabs are not handled with SA1140
Any news here? |
I'll have a look this week. Marked it 'do not merge' to signify that the discussion in #1808 has not come to a conclusion yet. |
|
||
this.SetLineLengthSettings(41); | ||
await this.VerifyCSharpDiagnosticAsync(testCode, new[] { diagnosticLine4 }, CancellationToken.None).ConfigureAwait(false); | ||
} |
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.
This is missing a test case where all lines are shorter than the maximum line length
/// than allowed in stylecop.json</para> | ||
/// </remarks> | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
internal class SA1140MaximumLineLength : DiagnosticAnalyzer |
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.
This should be marked with [NoCodeFix]
} | ||
|
||
public int LineLength => | ||
this.lineLength; | ||
} |
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.
LineLength should be named MaximumLineLength to provide more clarity to someone reading the stylecop.json
file.
documentation/ReadabilityRules.md
Outdated
@@ -39,3 +39,4 @@ Identifier | Name | Description | |||
[SA1134](SA1134.md) | AttributesMustNotShareLine | An attribute is placed on the same line of code as another attribute or element. | |||
[SA1136](SA1136.md) | EnumValuesShouldBeOnSeparateLines | Multiple enum values are placed on the same line of code. | |||
[SA1139](SA1139.md) | UseLiteralsSuffixNotationInsteadOfCasting | Use literal suffix notation instead of casting. | |||
[SA1140](SA1140.md) | SA1140MaximumLineLength | Code should be wrapped to a maximum line length. |
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.
SA1140MaximumLineLength
should be MaximumLineLength
, to be inline with the other entries
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.
Done
documentation/SA1140.md
Outdated
</table> | ||
|
||
:memo: This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic. | ||
|
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.
Please add a remark that this was added in 1.1.0
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.
Done
private static readonly string HelpLink = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1140.md"; | ||
|
||
private static readonly DiagnosticDescriptor Descriptor = | ||
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.ReadabilityRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink); |
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.
This should have AnalyzerConstants.DisabledByDefault
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.
Am i right that the AnalyzerConstants.DisabledByDefault
will set the Severity Level to None by default?
I would like this rule to check the line length as soon as a user defined a maximum in his config. Thats the way it works at the moment.
Renamed `SA1140MaximumLineLength` should be `MaximumLineLength`, to be inline with the other entries
Rule was added in 1.1.0
Ok, i think finally i implemented all of your requests exept the Please give feedback |
Hey guys, Did you already checkout my last changes? |
apologies for unsolicited commenting on this PR - I've nothing to do with project but was looking for this sort of functionality as a user @pkess - nice work. It would be great to see this merged into the project. While i like your approach w.r.t. to the outstanding issue on this PR, esp. for its convenience, it strikes me as a non-standard way to configure the rule. As a user, I would expect that the value specified in my ruleset ultimately governs whether or not the rule is on. One major benefit of this, is that there is only one obvious place I have to go in order to disable the rule, should I so desire. In order to break the impasse here, would you be willing to compromise here to get the majority of the benefit into the codebase? |
Hi, Thank you for your comment. Additionally I don't have a machine with Windows and visual studio running now (and will not have any in the next month's) so I am not able to fix it quite now. Feel free to fork my branch and implement it as you like. I would be excited! |
@pkess I'm won't hide that I'm not a fan of this rule (unrelated to your implementation of it), but after I get some of the other blocking issues (e.g. C# 7) taken care of I will take a serious look at this PR and see if we can get it included as a disabled-by-default rule. |
@sharwell - is there any timeline for including this functionality? It would be useful to know before we decide whether to reference another third-party analyzer or write our own equivalent. |
@LordBenjamin Not yet. Feel free to keep reminding me. |
@sharwell If this rule wasn't enabled by default (as per original PR), would you be happy to merge it? If so, I'd be happy to take a look at doing that tonight. |
@cristobalito I haven't had a chance to do the code review yet. If the only issues are the merge conflicts and changing it to disabled by default, then those are items we can quickly clean up when we get ready to merge. Thank you though. 😄 |
@sharwell is it possible to merge this? |
Any progress on this? Would love to see this rule implemented and it seems that we are on the home stretch. Anyone care to take us the last few yards? |
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.
I have a few minor comments on this. This is still pending @sharwell's take on this. All the comments I made could also be addressed in a later PR.
<value>Code should be wrapped to a maximum line length. See stylecop.json</value> | ||
</data> | ||
<data name="SA1140MessageFormat" xml:space="preserve"> | ||
<value>Maximum line length exceeded</value> |
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.
I think it would be good to change this to "Maximum line length of {0} exceeded" and make it include the set line length.
{ | ||
if ((line.End - line.Start) > readabilityRules.MaximumLineLength) | ||
{ | ||
var location = root.SyntaxTree.GetLocation(line.Span); |
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.
Maybe only report the diagnostic on the bit that is too long so the user knows how much the line is too long.
|
||
## Known issues | ||
|
||
Tabs in source file are not expanded to spaces for evaluation of the line length. Only use this rule if spaces are used for indention. |
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.
Should we do something about this? We could count the number of tabs in the line and use the configured tab width for that
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.
At the time this was first implemented, tab width might not have been included in stylecop.json. It's now available there so the feature could be implemented in this rule too.
using StyleCop.Analyzers.Helpers; | ||
|
||
/// <summary> | ||
/// Maximum line length |
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.
All(?) other rules contain the documentation as part of the xml documentation
Any news on this? My new fellow devs (company merged) prefer to operate a max line length style and I want something to pre-emptively warn me |
Would be very happy to see this as a feature. Any news on progress? |
Any update on this? |
I believe all updates will be seen in this thread or the proposal issue, if that's what you're asking. |
Is this change going to be checked in? Trying to get my team to standardize on a max line length is impossible without some kind of preventative check. Per documentation, it is recommended to have a max line length of 120 https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions. It would be really helpful to have this change to help enforce this rule. |
Hi,
i just created a rule to meet #1808.
The rule will not raise any warnings or errors unless a maximum line length is configured in stylecop.json
Please leave comments