Skip to content

Commit c87f25b

Browse files
authored
Enable rule SA1202 (#2054)
* Enable SA1101 * Fix BoundingBox * Fix BrowserFetcher * Fix CDPSession * Fix ChromiumLauncher * Fix Browser * Fix Connection * Fix DOMWorld * Fix Page * Fix CustomQueriesManager * Fix ElementHandle * Fix ExecutionContext * Fix FirefoxLauncher * Fix Frame * Fix FrameManager * Fix WebSocketTransport * Fix WaitTask * Fix Target * Fix State * Fix Response * Fix AXNode * Fix NetworkManager * Fix NetworkEventManager * Fix DeviceDescriptors * Fix LifecycleWatcher * Fix LauncherBase * Fix Launcher * Fix JSHandle * Fix Key * Fix TempDirectory * Fix TaskQueue * Fix RemoteObjectHelper * Fix ConcurrentSet
1 parent 3c91d1d commit c87f25b

33 files changed

+969
-971
lines changed

lib/PuppeteerSharp.ruleset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Rule Id="SA1629" Action="None" /> <!-- Error SA1629: Documentation text should end with a period (SA1629)-->
1616
<Rule Id="SA1514" Action="Error" /> <!-- Error SA1514: Element documentation header should be preceded by blank line (SA1514)-->
1717
<Rule Id="SA1201" Action="Error" /> <!-- Error SA1201: Elements must appear in the correct order (SA1201)-->
18-
<Rule Id="SA1202" Action="None" /> <!-- Error SA1202: 'public' members should come before 'internal' members (SA1202)-->
18+
<Rule Id="SA1202" Action="Error" /> <!-- Error SA1202: 'public' members should come before 'internal' members (SA1202)-->
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="Error" /> <!-- Error SA1204: Static members should appear before non-static members (SA1204)-->

lib/PuppeteerSharp/BoundingBox.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ public BoundingBox(decimal x, decimal y, decimal width, decimal height)
5555
/// <value>The height.</value>
5656
public decimal Height { get; set; }
5757

58-
internal Clip ToClip()
59-
{
60-
return new Clip
61-
{
62-
X = X,
63-
Y = Y,
64-
Width = Width,
65-
Height = Height,
66-
};
67-
}
68-
6958
/// <inheritdoc/>
7059
public override bool Equals(object obj)
7160
{
@@ -96,5 +85,16 @@ public override int GetHashCode()
9685
^ Y.GetHashCode() * 397
9786
^ Width.GetHashCode() * 397
9887
^ Height.GetHashCode() * 397;
88+
89+
internal Clip ToClip()
90+
{
91+
return new Clip
92+
{
93+
X = X,
94+
Y = Y,
95+
Width = Width,
96+
Height = Height,
97+
};
98+
}
9999
}
100100
}

lib/PuppeteerSharp/Browser.cs

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ void TargetHandler(object sender, TargetChangedArgs e)
198198
public void RegisterCustomQueryHandler(string name, CustomQueryHandler queryHandler)
199199
=> CustomQueriesManager.RegisterCustomQueryHandler(name, queryHandler);
200200

201-
/// <inheritdoc/>
202-
internal IEnumerable<string> GetCustomQueryHandlerNames()
203-
=> CustomQueriesManager.GetCustomQueryHandlerNames();
204-
205201
/// <inheritdoc/>
206202
public void UnregisterCustomQueryHandler(string name)
207203
=> CustomQueriesManager.UnregisterCustomQueryHandler(name);
@@ -210,6 +206,89 @@ public void UnregisterCustomQueryHandler(string name)
210206
public void ClearCustomQueryHandlers()
211207
=> CustomQueriesManager.ClearCustomQueryHandlers();
212208

209+
/// <inheritdoc />
210+
public void Dispose()
211+
{
212+
Dispose(true);
213+
GC.SuppressFinalize(this);
214+
}
215+
216+
/// <summary>
217+
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
218+
/// created by Puppeteer.
219+
/// </summary>
220+
/// <returns>ValueTask</returns>
221+
public ValueTask DisposeAsync() => new ValueTask(CloseAsync());
222+
223+
internal static async Task<Browser> CreateAsync(
224+
Connection connection,
225+
string[] contextIds,
226+
bool ignoreHTTPSErrors,
227+
ViewPortOptions defaultViewPort,
228+
LauncherBase launcher,
229+
Func<TargetInfo, bool> targetFilter,
230+
Action<IBrowser> initAction = null)
231+
{
232+
var browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewPort, launcher, targetFilter);
233+
234+
initAction?.Invoke(browser);
235+
236+
await connection.SendAsync("Target.setDiscoverTargets", new TargetSetDiscoverTargetsRequest
237+
{
238+
Discover = true,
239+
}).ConfigureAwait(false);
240+
241+
return browser;
242+
}
243+
244+
/// <inheritdoc/>
245+
internal IEnumerable<string> GetCustomQueryHandlerNames()
246+
=> CustomQueriesManager.GetCustomQueryHandlerNames();
247+
248+
internal void ChangeTarget(Target target)
249+
{
250+
var args = new TargetChangedArgs { Target = target };
251+
TargetChanged?.Invoke(this, args);
252+
((BrowserContext)target.BrowserContext).OnTargetChanged(this, args);
253+
}
254+
255+
internal async Task<IPage> CreatePageInContextAsync(string contextId)
256+
{
257+
var createTargetRequest = new TargetCreateTargetRequest
258+
{
259+
Url = "about:blank",
260+
};
261+
262+
if (contextId != null)
263+
{
264+
createTargetRequest.BrowserContextId = contextId;
265+
}
266+
267+
var targetId = (await Connection.SendAsync<TargetCreateTargetResponse>("Target.createTarget", createTargetRequest)
268+
.ConfigureAwait(false)).TargetId;
269+
var target = TargetsMap[targetId];
270+
await target.InitializedTask.ConfigureAwait(false);
271+
return await target.PageAsync().ConfigureAwait(false);
272+
}
273+
274+
internal async Task DisposeContextAsync(string contextId)
275+
{
276+
await Connection.SendAsync("Target.disposeBrowserContext", new TargetDisposeBrowserContextRequest
277+
{
278+
BrowserContextId = contextId,
279+
}).ConfigureAwait(false);
280+
_contexts.TryRemove(contextId, out var _);
281+
}
282+
283+
/// <summary>
284+
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
285+
/// created by Puppeteer.
286+
/// </summary>
287+
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
288+
protected virtual void Dispose(bool disposing) => _ = CloseAsync()
289+
.ContinueWith(
290+
_ => ScreenshotTaskQueue.DisposeAsync(), TaskScheduler.Default);
291+
213292
private async Task CloseCoreAsync()
214293
{
215294
try
@@ -259,41 +338,6 @@ private async Task CloseCoreAsync()
259338
Closed?.Invoke(this, new EventArgs());
260339
}
261340

262-
internal void ChangeTarget(Target target)
263-
{
264-
var args = new TargetChangedArgs { Target = target };
265-
TargetChanged?.Invoke(this, args);
266-
((BrowserContext)target.BrowserContext).OnTargetChanged(this, args);
267-
}
268-
269-
internal async Task<IPage> CreatePageInContextAsync(string contextId)
270-
{
271-
var createTargetRequest = new TargetCreateTargetRequest
272-
{
273-
Url = "about:blank",
274-
};
275-
276-
if (contextId != null)
277-
{
278-
createTargetRequest.BrowserContextId = contextId;
279-
}
280-
281-
var targetId = (await Connection.SendAsync<TargetCreateTargetResponse>("Target.createTarget", createTargetRequest)
282-
.ConfigureAwait(false)).TargetId;
283-
var target = TargetsMap[targetId];
284-
await target.InitializedTask.ConfigureAwait(false);
285-
return await target.PageAsync().ConfigureAwait(false);
286-
}
287-
288-
internal async Task DisposeContextAsync(string contextId)
289-
{
290-
await Connection.SendAsync("Target.disposeBrowserContext", new TargetDisposeBrowserContextRequest
291-
{
292-
BrowserContextId = contextId,
293-
}).ConfigureAwait(false);
294-
_contexts.TryRemove(contextId, out var _);
295-
}
296-
297341
private async void Connection_Disconnected(object sender, EventArgs e)
298342
{
299343
try
@@ -402,50 +446,5 @@ private async Task CreateTargetAsync(TargetCreatedResponse e)
402446
context.OnTargetCreated(this, args);
403447
}
404448
}
405-
406-
internal static async Task<Browser> CreateAsync(
407-
Connection connection,
408-
string[] contextIds,
409-
bool ignoreHTTPSErrors,
410-
ViewPortOptions defaultViewPort,
411-
LauncherBase launcher,
412-
Func<TargetInfo, bool> targetFilter,
413-
Action<IBrowser> initAction = null)
414-
{
415-
var browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewPort, launcher, targetFilter);
416-
417-
initAction?.Invoke(browser);
418-
419-
await connection.SendAsync("Target.setDiscoverTargets", new TargetSetDiscoverTargetsRequest
420-
{
421-
Discover = true,
422-
}).ConfigureAwait(false);
423-
424-
return browser;
425-
}
426-
427-
/// <inheritdoc />
428-
public void Dispose()
429-
{
430-
Dispose(true);
431-
GC.SuppressFinalize(this);
432-
}
433-
434-
/// <summary>
435-
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
436-
/// created by Puppeteer.
437-
/// </summary>
438-
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
439-
protected virtual void Dispose(bool disposing) => _ = CloseAsync()
440-
.ContinueWith(
441-
_ => ScreenshotTaskQueue.DisposeAsync(),
442-
TaskScheduler.Default);
443-
444-
/// <summary>
445-
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
446-
/// created by Puppeteer.
447-
/// </summary>
448-
/// <returns>ValueTask</returns>
449-
public ValueTask DisposeAsync() => new ValueTask(CloseAsync());
450449
}
451450
}

0 commit comments

Comments
 (0)