Skip to content

Commit 866a802

Browse files
tbaslykkblok
andauthored
[BREAKING CHANGE] Enable various analyzer rules (#2006)
* Enable various analyzer rules * Update lib/PuppeteerSharp/BrowserFetcherOptions.cs * Update lib/PuppeteerSharp/LauncherBase.cs * Document tasks * Move DefaultArgs property Co-authored-by: Darío Kondratiuk <dariokondratiuk@gmail.com>
1 parent 09a040c commit 866a802

26 files changed

+138
-132
lines changed

lib/PuppeteerSharp.Tests/OOPIFTests/OOPIFTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,6 @@ public async Task ShouldSupportLazyOopframes()
350350
Assert.Single(Page.Frames.Where(frame => !frame.HasStartedLoading));
351351
}
352352

353-
private IEnumerable<Target> Oopifs => Context.Targets().Where(target => target.TargetInfo.Type == TargetType.iFrame);
353+
private IEnumerable<Target> Oopifs => Context.Targets().Where(target => target.TargetInfo.Type == TargetType.IFrame);
354354
}
355355
}

lib/PuppeteerSharp.ruleset

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
<Rule Id="SA1210" Action="Error" /> <!-- Error SA1210: Using directives should be ordered alphabetically by the namespaces. (SA1210)-->
2020
<Rule Id="SA1208" Action="Error" /> <!-- Error SA1208: Order usings-->
2121
<Rule Id="SA1204" Action="None" /> <!-- Error SA1204: Static members should appear before non-static members (SA1204)-->
22-
<Rule Id="SA1004" Action="None" /> <!-- Error SA1004: Documentation line should begin with a space. (SA1004)-->
22+
<Rule Id="SA1004" Action="Error" /> <!-- Error SA1004: Documentation line should begin with a space. (SA1004)-->
2323
<Rule Id="SA1513" Action="None" /> <!-- Error SA1513: Closing brace should be followed by blank line (SA1513)-->
2424
<Rule Id="SA1124" Action="Error" /> <!-- Error SA1124: Don't use regions-->
2525
<Rule Id="SA1009" Action="Error" /> <!-- Error SA1009: Closing parenthesis should not be preceded by a space. (SA1009)-->
2626
<Rule Id="SA1413" Action="None" /> <!-- Error SA1413: Use trailing comma in multi-line initializers (SA1413)-->
2727
<Rule Id="SA1602" Action="None" /> <!-- Error SA1602: Enumeration items should be documented (SA1602)-->
2828
<Rule Id="SA1005" Action="Error" /> <!-- Error SA1005: Single line comment should begin with a space. (SA1005)-->
29-
<Rule Id="SA1203" Action="None" /> <!-- Error SA1203: Constant fields should appear before non-constant fields (SA1203)-->
30-
<Rule Id="SA1720" Action="None" /> <!-- Error SA1720: Name contains type-->
31-
<Rule Id="SA1300" Action="None" /> <!-- Error SA1300: Element 'iFrame' should begin with an uppercase letter (SA1300)-->
32-
<Rule Id="SA1500" Action="None" /> <!-- Error SA1500: Braces for multi-line statements should not share line (SA1500)-->
29+
<Rule Id="SA1203" Action="Error" /> <!-- Error SA1203: Constant fields should appear before non-constant fields (SA1203)-->
30+
<Rule Id="SA1720" Action="Error" /> <!-- Error SA1720: Name contains type-->
31+
<Rule Id="SA1300" Action="Error" /> <!-- Error SA1300: Element 'iFrame' should begin with an uppercase letter (SA1300)-->
32+
<Rule Id="SA1500" Action="Error" /> <!-- Error SA1500: Braces for multi-line statements should not share line (SA1500)-->
3333
<Rule Id="SA1214" Action="Error" /> <!-- Error SA1214: Readonly fields should appear before non-readonly fields (SA1214)-->
34-
<Rule Id="SA1642" Action="None" /> <!-- Error SA1642: Constructor summary documentation should begin with standard text (SA1642) (PuppeteerSharp)-->
34+
<Rule Id="SA1642" Action="Error" /> <!-- Error SA1642: Constructor summary documentation should begin with standard text (SA1642) (PuppeteerSharp)-->
3535
<Rule Id="SA1013" Action="Error" /> <!-- Error SA1013: Closing brace should be preceded by a space. (SA1013) -->
3636
<Rule Id="SA1515" Action="Error" /> <!-- Error SA1515: Single-line comment should be preceded by blank line (SA1515) -->
3737
<Rule Id="SA1518" Action="None" /> <!-- Error SA1518: File is required to end with a single newline character (SA1518)-->
3838
<Rule Id="SA1012" Action="Error" /> <!-- Error SA1012: Opening brace should be followed by a space. (SA1012) -->
39-
<Rule Id="SA1512" Action="None" /> <!-- Error SA1502: Element should not be on a single line (SA1502) -->
39+
<Rule Id="SA1512" Action="Error" /> <!-- Error SA1502: Element should not be on a single line (SA1502) -->
4040
<Rule Id="SA1648" Action="None" /> <!-- Error SA1648: inheritdoc should be used with inheriting class (SA1648) -->
41-
<Rule Id="SA1616" Action="None" /> <!-- Error SA1616: Element return value documentation should have text (SA1616)-->
41+
<Rule Id="SA1616" Action="Error" /> <!-- Error SA1616: Element return value documentation should have text (SA1616)-->
4242
<Rule Id="SA1627" Action="Error" /> <!-- Error SA1627: The documentation text within the \'exception\' tag should not be empty. (SA1627)-->
4343
<Rule Id="SA1643" Action="Error" /> <!-- Error SA1643: Destructor summary documentation should begin with standard text (SA1643) -->
4444
<Rule Id="SA1614" Action="Error" /> <!-- Error SA1614: Element parameter documentation should have text (SA1614)-->

lib/PuppeteerSharp/BoundingBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace PuppeteerSharp
1010
public class BoundingBox : IEquatable<BoundingBox>
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="T:PuppeteerSharp.BoundingBox"/> class.
13+
/// Initializes a new instance of the <see cref="BoundingBox"/> class.
1414
/// </summary>
1515
public BoundingBox()
1616
{

lib/PuppeteerSharp/Browser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;

lib/PuppeteerSharp/BrowserFetcherOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class BrowserFetcherOptions
1313
/// </summary>
1414
/// <param name="address">address</param>
1515
/// <param name="fileName">fileName</param>
16-
/// <returns></returns>
16+
/// <returns>A Task that resolves when the download finishes.</returns>
1717
public delegate Task CustomFileDownloadAction(string address, string fileName);
1818

1919
/// <summary>

lib/PuppeteerSharp/CDPSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public async Task<JObject> SendAsync(string method, object args = null, bool wai
162162
/// <summary>
163163
/// Detaches session from target. Once detached, session won't emit any events and can't be used to send messages.
164164
/// </summary>
165-
/// <returns></returns>
165+
/// <returns>Task</returns>
166166
/// <exception cref="T:PuppeteerSharp.PuppeteerException">If the <see cref="Connection"/> is closed.</exception>
167167
public Task DetachAsync()
168168
{

lib/PuppeteerSharp/ChromiumLauncher.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
5-
using Microsoft.Extensions.Logging;
65
using PuppeteerSharp.Helpers;
76

87
namespace PuppeteerSharp
@@ -13,7 +12,27 @@ namespace PuppeteerSharp
1312
/// </summary>
1413
public class ChromiumLauncher : LauncherBase
1514
{
16-
internal static readonly string[] DefaultArgs = {
15+
private const string UserDataDirArgument = "--user-data-dir";
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="ChromiumLauncher"/> class.
19+
/// </summary>
20+
/// <param name="executable">Full path of executable.</param>
21+
/// <param name="options">Options for launching Chromium.</param>
22+
public ChromiumLauncher(string executable, LaunchOptions options)
23+
: base(executable, options)
24+
{
25+
List<string> chromiumArgs;
26+
(chromiumArgs, TempUserDataDir) = PrepareChromiumArgs(options);
27+
28+
Process.StartInfo.Arguments = string.Join(" ", chromiumArgs);
29+
}
30+
31+
/// <summary>
32+
/// The default flags that Chromium will be launched with.
33+
/// </summary>
34+
internal static string[] DefaultArgs { get; } =
35+
{
1736
"--disable-background-networking",
1837
"--enable-features=NetworkService,NetworkServiceInProcess",
1938
"--disable-background-timer-throttling",
@@ -40,22 +59,6 @@ public class ChromiumLauncher : LauncherBase
4059
"--enable-blink-features=IdleDetection",
4160
};
4261

43-
private const string UserDataDirArgument = "--user-data-dir";
44-
45-
/// <summary>
46-
/// Creates a new <see cref="ChromiumLauncher"/> instance.
47-
/// </summary>
48-
/// <param name="executable">Full path of executable.</param>
49-
/// <param name="options">Options for launching Chromium.</param>
50-
public ChromiumLauncher(string executable, LaunchOptions options)
51-
: base(executable, options)
52-
{
53-
List<string> chromiumArgs;
54-
(chromiumArgs, TempUserDataDir) = PrepareChromiumArgs(options);
55-
56-
Process.StartInfo.Arguments = string.Join(" ", chromiumArgs);
57-
}
58-
5962
/// <inheritdoc />
6063
public override string ToString() => $"Chromium process; EndPoint={EndPoint}; State={CurrentState}";
6164

@@ -109,7 +112,8 @@ internal static string[] GetDefaultArgs(LaunchOptions options)
109112

110113
if (options.Headless)
111114
{
112-
chromiumArguments.AddRange(new[] {
115+
chromiumArguments.AddRange(new[]
116+
{
113117
"--headless",
114118
"--hide-scrollbars",
115119
"--mute-audio"

lib/PuppeteerSharp/ChromiumProcessException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public ChromiumProcessException()
1818
}
1919

2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="ProcessException"/> class.
21+
/// Initializes a new instance of the <see cref="ChromiumProcessException"/> class.
2222
/// </summary>
2323
/// <param name="message">Message.</param>
2424
public ChromiumProcessException(string message) : base(message)
2525
{
2626
}
2727

2828
/// <summary>
29-
/// Initializes a new instance of the <see cref="ProcessException"/> class.
29+
/// Initializes a new instance of the <see cref="ChromiumProcessException"/> class.
3030
/// </summary>
3131
/// <param name="message">Message.</param>
3232
/// <param name="innerException">Inner exception.</param>

lib/PuppeteerSharp/Dialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace PuppeteerSharp
99
/// </summary>
1010
/// <example>
1111
/// An example of using Dialog class:
12-
///<code>
13-
///<![CDATA[
12+
/// <code>
13+
/// <![CDATA[
1414
/// Page.Dialog += async (sender, e) =>
1515
/// {
1616
/// await e.Dialog.Accept();

lib/PuppeteerSharp/ElementHandle.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -363,7 +363,7 @@ public async Task TypeAsync(string text, TypeOptions options = null)
363363
/// <remarks>
364364
/// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also be generated. The <see cref="DownOptions.Text"/> option can be specified to force an input event to be generated.
365365
/// </remarks>
366-
/// <returns></returns>
366+
/// <returns>Task which resolves when the key is successfully pressed</returns>
367367
public async Task PressAsync(string key, PressOptions options = null)
368368
{
369369
await FocusAsync().ConfigureAwait(false);
@@ -475,7 +475,7 @@ public async Task<BoxModel> BoxModelAsync()
475475
}
476476

477477
/// <summary>
478-
///Content frame for element handles referencing iframe nodes, or null otherwise.
478+
/// Content frame for element handles referencing iframe nodes, or null otherwise.
479479
/// </summary>
480480
/// <returns>Resolves to the content frame</returns>
481481
public async Task<Frame> ContentFrameAsync()
@@ -686,7 +686,8 @@ public async Task<BoxModelPoint> ClickablePointAsync(BoxModelPoint? offset = nul
686686
// Return the point of the first quad identified by offset.
687687
var minX = decimal.MaxValue;
688688
var minY = decimal.MaxValue;
689-
foreach (var point in quad) {
689+
foreach (var point in quad)
690+
{
690691
if (point.X < minX)
691692
{
692693
minX = point.X;
@@ -700,10 +701,11 @@ public async Task<BoxModelPoint> ClickablePointAsync(BoxModelPoint? offset = nul
700701
minX != decimal.MaxValue &&
701702
minY != decimal.MaxValue)
702703
{
703-
return new BoxModelPoint() {
704+
return new BoxModelPoint()
705+
{
704706
X = minX + offset.Value.X,
705707
Y = minY + offset.Value.Y
706-
};
708+
};
707709
}
708710
}
709711
var x = 0m;
@@ -715,7 +717,8 @@ public async Task<BoxModelPoint> ClickablePointAsync(BoxModelPoint? offset = nul
715717
y += point.Y;
716718
}
717719

718-
return new BoxModelPoint() {
720+
return new BoxModelPoint()
721+
{
719722
X = x / 4,
720723
Y = y / 4
721724
};

0 commit comments

Comments
 (0)