Skip to content

Commit

Permalink
Support AllowLongFourSlashCommentLines for #8.
Browse files Browse the repository at this point in the history
Support AllowLongUriLines in the XML schema (missed in 28e705a).
  • Loading branch information
menees committed Aug 6, 2022
1 parent 6fbf272 commit 594a754
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!-- Make the assembly, file, and NuGet package versions the same. -->
<!-- NOTE: Change the version in Vsix\source.extension.vsixmanifest to match this! -->
<Version>3.0.8</Version>
<Version>3.0.9</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
13 changes: 11 additions & 2 deletions src/Menees.Analyzers/Men002LineTooLong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ private void TryReport(
int thresholdIndex)
{
bool report = true;
if (this.Settings.AllowLongUriLines)

string? trimmed = null;
if (report && this.Settings.AllowLongUriLines)
{
// Ignore if the whole line minus comment delimiters passes Uri.TryCreate(absolute) (e.g., for http or UNC URLs).
string scrubbed = lineText.Trim();
trimmed ??= lineText.Trim();
string scrubbed = trimmed;
if (scrubbed.StartsWith("//"))
{
// Ignore multiple leading '/' in case the URL is inside a doc comment.
Expand All @@ -161,6 +164,12 @@ private void TryReport(
report = !Uri.TryCreate(scrubbed, UriKind.Absolute, out _);
}

if (report && this.Settings.AllowLongFourSlashCommentLines)
{
trimmed ??= lineText.Trim();
report = !trimmed.StartsWith("////");
}

if (report)
{
TextSpan excess = TextSpan.FromBounds(lineSpan.Start + thresholdIndex, lineSpan.End);
Expand Down
2 changes: 2 additions & 0 deletions src/Menees.Analyzers/Menees.Analyzers.Settings.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<xs:element name="MaxPropertyAccessorLines" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
<xs:element name="MaxFileLines" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
<xs:element name="MaxUnregionedLines" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
<xs:element name="AllowLongUriLines" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
<xs:element name="AllowLongFourSlashCommentLines" type="xs:boolean" minOccurs="0" maxOccurs="1"/>

<xs:element name="AnalyzeFileNameExclusions" minOccurs="0" maxOccurs="1">
<xs:complexType>
Expand Down
3 changes: 3 additions & 0 deletions src/Menees.Analyzers/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private Settings(XElement xml)
this.MaxFileLines = GetSetting(xml, nameof(this.MaxFileLines), this.MaxFileLines);
this.MaxUnregionedLines = GetSetting(xml, nameof(this.MaxUnregionedLines), this.MaxUnregionedLines);
this.AllowLongUriLines = GetSetting(xml, nameof(this.AllowLongUriLines), this.AllowLongUriLines);
this.AllowLongFourSlashCommentLines = GetSetting(xml, nameof(this.AllowLongFourSlashCommentLines), this.AllowLongFourSlashCommentLines);

this.analyzeFileNameExclusions = GetFileNameExclusions(xml, "AnalyzeFileNameExclusions", DefaultAnalyzeFileNameExclusions);
this.typeFileNameExclusions = GetFileNameExclusions(xml, "TypeFileNameExclusions", DefaultTypeFileNameExclusions);
Expand Down Expand Up @@ -190,6 +191,8 @@ private enum NumberBase

public bool AllowLongUriLines { get; } = true;

public bool AllowLongFourSlashCommentLines { get; }

#endregion

#region Public Methods
Expand Down
1 change: 1 addition & 0 deletions tests/Menees.Analyzers.Test/Men002UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Testing
public Testing()
{
// LongUriLines=true
//// This is a long line preceded by four slashes. Setting AllowLongFourSlashCommentLines=true makes it valid.
// https://www.amazon.com/Brain-Games%C2%AE-Large-Print-Searches/dp/1640304606/ref=sr_1_2?crid=3KP7CV3HBJADN&keywords=big+long+search+text&qid=1645375366&sprefix=big+long+search+text%2Caps%2C72&sr=8-2
/// https://www.amazon.com/Brain-Games%C2%AE-Large-Print-Searches/dp/1640304606/ref=sr_1_2?crid=3KP7CV3HBJADN&keywords=big+long+search+text&qid=1645375366&sprefix=big+long+search+text%2Caps%2C72&sr=8-2
//// https://www.amazon.com/Brain-Games%C2%AE-Large-Print-Searches/dp/1640304606/ref=sr_1_2?crid=3KP7CV3HBJADN&keywords=big+long+search+text&qid=1645375366&sprefix=big+long+search+text%2Caps%2C72&sr=8-2
Expand Down
1 change: 1 addition & 0 deletions tests/Menees.Analyzers.Test/Menees.Analyzers.Settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<MaxPropertyAccessorLines>5</MaxPropertyAccessorLines>
<MaxFileLines>20</MaxFileLines>
<MaxUnregionedLines>20</MaxUnregionedLines>
<AllowLongFourSlashCommentLines>true</AllowLongFourSlashCommentLines>

<AnalyzeFileNameExclusions>
<FileName>Test21.cs</FileName>
Expand Down

0 comments on commit 594a754

Please sign in to comment.