Skip to content

Commit 53fe420

Browse files
committed
🚨 apply linter suggestions
Signed-off-by: Yves Bastide <[email protected]>
1 parent 25c01e3 commit 53fe420

File tree

6 files changed

+29
-56
lines changed

6 files changed

+29
-56
lines changed

‎RobotsTxt/Extensions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
31
namespace RobotsTxt
42
{
53
public static class MyExtensions
@@ -28,7 +26,7 @@ public static bool EqualsIgnoreCase(this ReadOnlySpan<byte> self, ReadOnlySpan<b
2826
return true;
2927
}
3028

31-
public static bool StartsWithIgnoreCase(this ReadOnlySpan<byte> span, string value)
29+
public static bool StartsWithIgnoreCase(this ReadOnlySpan<byte> span, ReadOnlySpan<byte> value)
3230
{
3331
if (span.Length < value.Length)
3432
{
@@ -42,8 +40,8 @@ public static bool StartsWithIgnoreCase(this ReadOnlySpan<byte> span, string val
4240
if ('A' <= c1 && c1 <= 'Z')
4341
c1 += 32;
4442
if ('A' <= c2 && c2 <= 'Z')
45-
c2 += ' ';
46-
if (c1 != (byte)c2)
43+
c2 += (byte)' ';
44+
if (c1 != c2)
4745
{
4846
return false;
4947
}

‎RobotsTxt/IRobotsParseHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
31
namespace RobotsTxt
42
{
53
public interface IRobotsParseHandler

‎RobotsTxt/LongestMatchRobotsMatchStrategy.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace RobotsTxt
1+
namespace RobotsTxt
42
{
53

64
/// <summary>

‎RobotsTxt/ParsedRobotsKey.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Diagnostics;
32

43
namespace RobotsTxt
@@ -51,31 +50,31 @@ public void Parse(ReadOnlySpan<byte> key)
5150

5251
private bool KeyIsSitemap(ReadOnlySpan<byte> key)
5352
{
54-
return key.StartsWithIgnoreCase("sitemap") ||
55-
key.StartsWithIgnoreCase("site-map");
53+
return key.StartsWithIgnoreCase("sitemap"u8) ||
54+
key.StartsWithIgnoreCase("site-map"u8);
5655
}
5756

5857
private bool KeyIsDisallow(ReadOnlySpan<byte> key)
5958
{
6059
return (
61-
key.StartsWithIgnoreCase("disallow") ||
62-
(AllowFrequentTypos && (key.StartsWithIgnoreCase("dissallow") ||
63-
key.StartsWithIgnoreCase("dissalow") ||
64-
key.StartsWithIgnoreCase("disalow") ||
65-
key.StartsWithIgnoreCase("diasllow") ||
66-
key.StartsWithIgnoreCase("disallaw"))));
60+
key.StartsWithIgnoreCase("disallow"u8) ||
61+
(AllowFrequentTypos && (key.StartsWithIgnoreCase("dissallow"u8) ||
62+
key.StartsWithIgnoreCase("dissalow"u8) ||
63+
key.StartsWithIgnoreCase("disalow"u8) ||
64+
key.StartsWithIgnoreCase("diasllow"u8) ||
65+
key.StartsWithIgnoreCase("disallaw"u8))));
6766
}
6867

6968
private bool KeyIsAllow(ReadOnlySpan<byte> key)
7069
{
71-
return key.StartsWithIgnoreCase("allow");
70+
return key.StartsWithIgnoreCase("allow"u8);
7271
}
7372

7473
private bool KeyIsUserAgent(ReadOnlySpan<byte> key)
7574
{
76-
return key.StartsWithIgnoreCase("user-agent") ||
77-
(AllowFrequentTypos && (key.StartsWithIgnoreCase("useragent") ||
78-
key.StartsWithIgnoreCase("user agent")));
75+
return key.StartsWithIgnoreCase("user-agent"u8) ||
76+
(AllowFrequentTypos && (key.StartsWithIgnoreCase("useragent"u8) ||
77+
key.StartsWithIgnoreCase("user agent"u8)));
7978
}
8079

8180

‎RobotsTxt/RobotsMatcher.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Diagnostics;
42
using System.Text;
53

@@ -224,7 +222,7 @@ internal static string GetPathParamsQuery(string url)
224222
{
225223
var searchStart = 0;
226224
if (url is ['/', '/', ..]) searchStart = 2;
227-
var earlyPath = url.IndexOfAny(new[] { '/', '?', ';' }, searchStart);
225+
var earlyPath = url.IndexOfAny(['/', '?', ';',], searchStart);
228226
var protocolEnd = url.IndexOf("://", searchStart, StringComparison.Ordinal);
229227
if (earlyPath < protocolEnd)
230228
{
@@ -240,7 +238,7 @@ internal static string GetPathParamsQuery(string url)
240238
protocolEnd += 3;
241239
}
242240

243-
var pathStart = url.IndexOfAny(new[] { '/', '?', ';' }, protocolEnd);
241+
var pathStart = url.IndexOfAny(['/', '?', ';',], protocolEnd);
244242
if (pathStart != -1)
245243
{
246244
var hashPos = url.IndexOf('#', searchStart);
@@ -258,16 +256,10 @@ internal static string GetPathParamsQuery(string url)
258256
return "/";
259257
}
260258

261-
class Match
259+
class Match(int priority = Match.NoMatchPriority, int line = 0)
262260
{
263261
private const int NoMatchPriority = -1;
264262

265-
public Match(int priority = NoMatchPriority, int line = 0)
266-
{
267-
Priority = priority;
268-
Line = line;
269-
}
270-
271263
public void Set(int priority, int line)
272264
{
273265
Priority = priority;
@@ -279,8 +271,8 @@ public void Clear()
279271
Set(NoMatchPriority, 0);
280272
}
281273

282-
public int Priority { get; private set; }
283-
public int Line { get; private set; }
274+
public int Priority { get; private set; } = priority;
275+
public int Line { get; private set; } = line;
284276
}
285277

286278
// For each of the directives within user-agents, we keep global and specific

‎RobotsTxt/RobotsTxtParser.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
2-
31
namespace RobotsTxt
42
{
5-
public class RobotsTxtParser
3+
public class RobotsTxtParser(byte[] robotsBody, IRobotsParseHandler handler)
64
{
7-
static readonly byte[] UtfBom = { 0xEF, 0xBB, 0xBF };
5+
static readonly byte[] UtfBom = [0xEF, 0xBB, 0xBF];
86
static readonly byte[] HexDigits = "0123456789ABCDEF"u8.ToArray();
97

108
public void Parse()
@@ -21,9 +19,9 @@ public void Parse()
2119
var lineNum = 0;
2220
var bomPos = 0;
2321
bool lastWasCarriageReturn = false;
24-
_handler.HandleRobotsStart();
22+
handler.HandleRobotsStart();
2523

26-
foreach (var ch in _robotsBody)
24+
foreach (var ch in robotsBody)
2725
{
2826
// Google-specific optimization: UTF-8 byte order marks should never
2927
// appear in a robots.txt file, but they do nevertheless. Skipping
@@ -62,16 +60,7 @@ public void Parse()
6260

6361
var spanLeft = lineBuffer.AsSpan(0, linePos);
6462
ParseAndEmitLine(++lineNum, spanLeft);
65-
_handler.HandleRobotsEnd();
66-
}
67-
68-
private readonly byte[] _robotsBody;
69-
private readonly IRobotsParseHandler _handler;
70-
71-
public RobotsTxtParser(byte[] robotsBody, IRobotsParseHandler handler)
72-
{
73-
_robotsBody = robotsBody;
74-
_handler = handler;
63+
handler.HandleRobotsEnd();
7564
}
7665

7766
void ParseAndEmitLine(int currentLine, ReadOnlySpan<byte> line)
@@ -86,16 +75,15 @@ void ParseAndEmitLine(int currentLine, ReadOnlySpan<byte> line)
8675
if (NeedEscapeValueForKey(key))
8776
{
8877
var escapedValue = MaybeEscapePattern(value);
89-
EmitKeyValueToHandler(currentLine, key, escapedValue, _handler);
78+
EmitKeyValueToHandler(currentLine, key, escapedValue);
9079
}
9180
else
9281
{
93-
EmitKeyValueToHandler(currentLine, key, value, _handler);
82+
EmitKeyValueToHandler(currentLine, key, value);
9483
}
9584
}
9685

97-
private void EmitKeyValueToHandler(int currentLine, ParsedRobotsKey key, ReadOnlySpan<byte> value,
98-
IRobotsParseHandler handler)
86+
private void EmitKeyValueToHandler(int currentLine, ParsedRobotsKey key, ReadOnlySpan<byte> value)
9987
{
10088
switch (key.Type)
10189
{

0 commit comments

Comments
 (0)