Skip to content

Commit 37ea569

Browse files
authored
Add analyzers (#1379)
1 parent 3b61a78 commit 37ea569

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+563
-256
lines changed

lib/.editorconfig

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# editorconfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Default settings:
7+
# A newline ending every file
8+
# Use 4 spaces as indentation
9+
[*]
10+
insert_final_newline = true
11+
indent_style = space
12+
indent_size = 4
13+
trim_trailing_whitespace = true
14+
charset = utf-8
15+
end_of_line = lf
16+
17+
[*.json]
18+
indent_size = 2
19+
20+
# C# files
21+
[*.cs]
22+
# New line preferences
23+
csharp_new_line_before_open_brace = all
24+
csharp_new_line_before_else = true
25+
csharp_new_line_before_catch = true
26+
csharp_new_line_before_finally = true
27+
csharp_new_line_before_members_in_object_initializers = true
28+
csharp_new_line_before_members_in_anonymous_types = true
29+
csharp_new_line_between_query_expression_clauses = true
30+
31+
# Indentation preferences
32+
csharp_indent_block_contents = true
33+
csharp_indent_braces = false
34+
csharp_indent_case_contents = true
35+
csharp_indent_case_contents_when_block = true
36+
csharp_indent_switch_labels = true
37+
csharp_indent_labels = one_less_than_current
38+
39+
# Modifier preferences
40+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
41+
42+
# avoid this. unless absolutely necessary
43+
dotnet_style_qualification_for_field = false:suggestion
44+
dotnet_style_qualification_for_property = false:suggestion
45+
dotnet_style_qualification_for_method = false:suggestion
46+
dotnet_style_qualification_for_event = false:suggestion
47+
48+
# Types: use keywords instead of BCL types, and permit var only when the type is clear
49+
csharp_style_var_for_built_in_types = false:error
50+
csharp_style_var_when_type_is_apparent = false:none
51+
csharp_style_var_elsewhere = true:suggestion
52+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
53+
dotnet_style_predefined_type_for_member_access = true:suggestion
54+
55+
# name all constant fields using PascalCase
56+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
57+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
58+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
59+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
60+
dotnet_naming_symbols.constant_fields.required_modifiers = const
61+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
62+
63+
# internal and private fields should be _camelCase
64+
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
65+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
66+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
67+
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
68+
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
69+
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
70+
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
71+
72+
# Code style defaults
73+
csharp_using_directive_placement = outside_namespace:suggestion
74+
dotnet_sort_system_directives_first = true
75+
csharp_prefer_braces = true:refactoring
76+
csharp_preserve_single_line_blocks = true:none
77+
csharp_preserve_single_line_statements = false:none
78+
csharp_prefer_static_local_function = true:suggestion
79+
csharp_prefer_simple_using_statement = false:none
80+
csharp_style_prefer_switch_expression = true:suggestion
81+
82+
# Code quality
83+
dotnet_style_readonly_field = true:error
84+
dotnet_code_quality_unused_parameters = non_public:suggestion
85+
86+
# Expression-level preferences
87+
dotnet_style_object_initializer = true:suggestion
88+
dotnet_style_collection_initializer = true:suggestion
89+
dotnet_style_explicit_tuple_names = true:suggestion
90+
dotnet_style_coalesce_expression = true:suggestion
91+
dotnet_style_null_propagation = true:suggestion
92+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
93+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
94+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
95+
dotnet_style_prefer_auto_properties = true:suggestion
96+
dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring
97+
dotnet_style_prefer_conditional_expression_over_return = true:refactoring
98+
csharp_prefer_simple_default_expression = true:suggestion
99+
100+
# Expression-bodied members
101+
csharp_style_expression_bodied_methods = true:refactoring
102+
csharp_style_expression_bodied_constructors = true:refactoring
103+
csharp_style_expression_bodied_operators = true:refactoring
104+
csharp_style_expression_bodied_properties = true:refactoring
105+
csharp_style_expression_bodied_indexers = true:refactoring
106+
csharp_style_expression_bodied_accessors = true:refactoring
107+
csharp_style_expression_bodied_lambdas = true:refactoring
108+
csharp_style_expression_bodied_local_functions = true:refactoring
109+
110+
# Pattern matching
111+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
112+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
113+
csharp_style_inlined_variable_declaration = true:suggestion
114+
115+
# Null checking preferences
116+
csharp_style_throw_expression = true:suggestion
117+
csharp_style_conditional_delegate_call = true:suggestion
118+
119+
# Other features
120+
csharp_style_prefer_index_operator = false:none
121+
csharp_style_prefer_range_operator = false:none
122+
csharp_style_pattern_local_over_anonymous_function = false:none
123+
124+
# Space preferences
125+
csharp_space_after_cast = false
126+
csharp_space_after_colon_in_inheritance_clause = true
127+
csharp_space_after_comma = true
128+
csharp_space_after_dot = false
129+
csharp_space_after_keywords_in_control_flow_statements = true
130+
csharp_space_after_semicolon_in_for_statement = true
131+
csharp_space_around_binary_operators = before_and_after
132+
csharp_space_around_declaration_statements = do_not_ignore
133+
csharp_space_before_colon_in_inheritance_clause = true
134+
csharp_space_before_comma = false
135+
csharp_space_before_dot = false
136+
csharp_space_before_open_square_brackets = false
137+
csharp_space_before_semicolon_in_for_statement = false
138+
csharp_space_between_empty_square_brackets = false
139+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
140+
csharp_space_between_method_call_name_and_opening_parenthesis = false
141+
csharp_space_between_method_call_parameter_list_parentheses = false
142+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
143+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
144+
csharp_space_between_method_declaration_parameter_list_parentheses = false
145+
csharp_space_between_parentheses = false
146+
csharp_space_between_square_brackets = false
147+
148+
# Analyzers
149+
dotnet_code_quality.ca1802.api_surface = private, internal
150+
151+
# C++ Files
152+
[*.{cpp,h,in}]
153+
curly_bracket_next_line = true
154+
indent_brace_style = Allman
155+
156+
# Xml project files
157+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
158+
indent_size = 2
159+
160+
# Xml build files
161+
[*.builds]
162+
indent_size = 2
163+
164+
# Xml files
165+
[*.{xml,stylecop,resx,ruleset}]
166+
indent_size = 2
167+
168+
# Xml config files
169+
[*.{props,targets,config,nuspec}]
170+
indent_size = 2
171+
172+
# Shell scripts
173+
[*.sh]
174+
end_of_line = lf
175+
[*.{cmd, bat}]
176+
end_of_line = crlf

lib/PuppeteerSharp.ruleset

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<RuleSet Name="Rules for PlaywrightSharp" Description="Rules for PlaywrightSharp" ToolsVersion="10.0">
2+
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
3+
<Rule Id="SA1633" Action="None" />
4+
<Rule Id="SA1200" Action="None" />
5+
<Rule Id="SA1623" Action="None" />
6+
<Rule Id="SA1101" Action="None" />
7+
<Rule Id="SA1128" Action="None" />
8+
<Rule Id="SA1309" Action="None" />
9+
<Rule Id="SX1309" Action="Error" />
10+
11+
<Rule Id="SA1624" Action="None" /> <!-- Error SA1624: Because the property only contains a visible get accessor, the documentation summary text should begin with 'Gets'. (SA1624)-->
12+
<Rule Id="SA1028" Action="None" /> <!-- Error SA1028: Code should not contain trailing whitespace (SA1028)-->
13+
<Rule Id="SA1600" Action="None" /> <!-- Error SA1600: Elements should be documented (SA1600)-->
14+
<Rule Id="SA1516" Action="None" /> <!-- Error SA1516: Elements should be separated by blank line (SA1516)-->
15+
<Rule Id="SA1629" Action="None" /> <!-- Error SA1629: Documentation text should end with a period (SA1629)-->
16+
<Rule Id="SA1514" Action="None" /> <!-- Error SA1514: Element documentation header should be preceded by blank line (SA1514)-->
17+
<Rule Id="SA1201" Action="None" /> <!-- Error SA1201: A constructor should not follow a property (SA1201)-->
18+
<Rule Id="SA1202" Action="None" /> <!-- Error SA1202: 'public' members should come before 'internal' members (SA1202)-->
19+
<Rule Id="SA1210" Action="None" /> <!-- Error SA1210: Using directives should be ordered alphabetically by the namespaces. (SA1210)-->
20+
<Rule Id="SA1208" Action="None" /> <!-- Error SA1208: Order usings-->
21+
<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)-->
23+
<Rule Id="SA1513" Action="None" /> <!-- Error SA1513: Closing brace should be followed by blank line (SA1513)-->
24+
<Rule Id="SA1124" Action="None" /> <!-- Error SA1124: Don't use regions-->
25+
<Rule Id="SA1009" Action="None" /> <!-- Error SA1009: Closing parenthesis should not be preceded by a space. (SA1009)-->
26+
<Rule Id="SA1413" Action="None" /> <!-- Error SA1413: Use trailing comma in multi-line initializers (SA1413)-->
27+
<Rule Id="SA1602" Action="None" /> <!-- Error SA1602: Enumeration items should be documented (SA1602)-->
28+
<Rule Id="SA1005" Action="None" /> <!-- 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)-->
33+
<Rule Id="SA1214" Action="None" /> <!-- 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)-->
35+
<Rule Id="SA1013" Action="None" /> <!-- Error SA1013: Closing brace should be preceded by a space. (SA1013) -->
36+
<Rule Id="SA1515" Action="None" /> <!-- Error SA1515: Single-line comment should be preceded by blank line (SA1515) -->
37+
<Rule Id="SA1012" Action="None" /> <!-- Error SA1012: Opening brace should be followed by a space. (SA1012) -->
38+
<Rule Id="SA1512" Action="None" /> <!-- Error SA1502: Element should not be on a single line (SA1502) -->
39+
<Rule Id="SA1648" Action="None" /> <!-- Error SA1648: inheritdoc should be used with inheriting class (SA1648) -->
40+
<Rule Id="SA1616" Action="None" /> <!-- Error SA1616: Element return value documentation should have text (SA1616)-->
41+
<Rule Id="SA1643" Action="None" /> <!-- Error SA1643: Destructor summary documentation should begin with standard text (SA1643) -->
42+
<Rule Id="SA1614" Action="None" /> <!-- Error SA1614: Element parameter documentation should have text (SA1614)-->
43+
<Rule Id="SA1627" Action="None" /> <!-- Error SA1627: The documentation text within the \'exception\' tag should not be empty. (SA1627)-->
44+
<Rule Id="SA1622" Action="None" /> <!-- Error SA1622: Generic type parameter documentation should have text. (SA1622)-->
45+
<Rule Id="SA1116" Action="None" /> <!-- Error SA1116: The parameters should begin on the line after the declaration, whenever the parameter span across multiple lines (SA1116)-->
46+
<Rule Id="SA1111" Action="None" /> <!-- Error SA1111: Closing parenthesis should be on line of last parameter (SA1111)-->
47+
<Rule Id="SA1505" Action="None" /> <!-- Error SA1505: An opening brace should not be followed by a blank line. (SA1505) -->
48+
<Rule Id="SA1612" Action="None" /> <!-- Error SA1612: The parameter documentation for 'filePaths' should be at position 2. (SA1612) -->
49+
<Rule Id="SA1620" Action="None" /> <!-- Error SA1620: The type parameter documentation for 'T4' should be at position 4. (SA1620) -->
50+
<Rule Id="SA1118" Action="None" /> <!-- Error SA1118: The parameter spans multiple lines (SA1118) -->
51+
</Rules>
52+
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
53+
<Rule Id="CA1054" Action="None" /> <!-- Overloads to System.Uri-->
54+
<Rule Id="CA1056" Action="None" /> <!-- Change string to System.Uri-->
55+
<Rule Id="CA1040" Action="None" /> <!-- Avoid empty interfaces-->
56+
<Rule Id="CA2007" Action="Error" /> <!-- Use ConfigureAwait -->
57+
<Rule Id="CA1819" Action="Info" /> <!-- Properties should not return arrays. -->
58+
<Rule Id="CA1815" Action="Info" /> <!-- should override equality and inequality. -->
59+
<Rule Id="CA2227" Action="Info" /> <!-- Change '...' to be read-only by removing the property setter. -->
60+
<Rule Id="CA1200" Action="Info" /> <!-- Avoid using cref tags with a prefix -->
61+
<Rule Id="CA2101" Action="None" /> <!-- Marshaling for P/Invoke-->
62+
<Rule Id="CA1801" Action="Info" /><!-- Unused parameter-->
63+
<Rule Id="CA1822" Action="None" /><!-- Method can be marked as static-->
64+
<Rule Id="CA1823" Action="Error" /><!-- avoid unused fields-->
65+
66+
<Rule Id="CA1063" Action="None" /> <!-- Error CA1063: Provide an overridable implementation of Dispose(bool) -->
67+
<Rule Id="CA1001" Action="None" /> <!-- Error CA1001: A class owns a disposable -->
68+
<Rule Id="CA1721" Action="None" /> <!-- Error CA1721: The property name 'DefaultArgs' is confusing given the existence of method 'GetDefaultArgs'. Rename or remove one of these members. (CA1721)-->
69+
<Rule Id="CA1032" Action="None" /> <!-- Error CA1032: Add the following constructor to SelectorException: public SelectorException(). (CA1032) -->
70+
<Rule Id="CA2220" Action="None" /> <!-- Error CA2229: Add a constructor to SelectorException with the following signature: 'protected SelectorException(SerializationInfo info, StreamingContext context)'. (CA2229) (PuppeteerSharp)-->
71+
<Rule Id="CA1064" Action="None" /> <!-- Error CA1064: Exceptions should be public (CA1064)-->
72+
<Rule Id="CA2229" Action="None" /> <!-- Error CA2229: Add a constructor to SelectorException with the following signature: 'protected SelectorException(SerializationInfo info, StreamingContext context)'. (CA2229)-->
73+
<Rule Id="CA2237" Action="None" /> <!-- Error CA2237: Add [Serializable] to TargetClosedException as this type implements ISerializable (CA2237)-->
74+
<Rule Id="CA1720" Action="None" /> <!-- Error SA1720: Name contains type-->
75+
<Rule Id="CA2008" Action="None" /> <!-- Error ca2008: Pass TaskScheduler-->
76+
<Rule Id="CA1062" Action="None" /> <!-- Error CA1062: VALIDATE OPTIONS-->
77+
<Rule Id="CA1062" Action="None" /> <!-- Error CA1031: Modify 'DeleteAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
78+
<Rule Id="CA1305" Action="None" /> <!-- String.Format with culture-->
79+
<Rule Id="CA1031" Action="None" /> <!-- Error CA1031: Modify 'SendAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
80+
<Rule Id="CA1806" Action="None" /> <!-- Error CA1806: DownloadAsync calls Chmod but does not use the HRESULT or error code that the method returns. This could lead to unexpected behavior in error conditions or low-resource situations. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. (CA1806)-->
81+
<Rule Id="CA1816" Action="None" /> <!-- Error CA1816: Change Connection.Dispose() to call GC.SuppressFinalize(object). This will prevent derived types that introduce a finalizer from needing to re-implement 'IDisposable' to call it. (CA1816) -->
82+
<Rule Id="CA1304" Action="None" /> <!-- Error CA1304: The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'JSHandle.ToString()' with a call to 'string.ToLower(CultureInfo)'. (CA1304) -->
83+
<Rule Id="CA2200" Action="None" /> <!-- Error CA2200: Re-throwing caught exception changes stack information. (CA2200) -->
84+
<Rule Id="CA1724" Action="None" /> <!-- Error CA1724: The type name Extensions conflicts in whole or in part with the namespace name 'Microsoft.Extensions'. Change either name to eliminate the conflict. (CA1724) -->
85+
<Rule Id="CA2213" Action="None" /> <!-- Error CA2213: 'WebSocketTransport' contains field '_readerCancellationSource' that is of IDisposable type 'CancellationTokenSource', but it is never disposed. Change the Dispose method on 'WebSocketTransport' to call Close or Dispose on this field. (CA2213) -->
86+
<Rule Id="CA2000" Action="None" /> <!-- Error CA2000: Call System.IDisposable.Dispose on object created by 'new Process()' before all references to it are out of scope. (CA2000) -->
87+
</Rules>
88+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
89+
<Rule Id="CA1303" Action="None" />
90+
</Rules>
91+
</RuleSet>

lib/PuppeteerSharp.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuppeteerSharp.Tests.DumpIO
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PuppeteerSharp.DevicesFetcher", "PuppeteerSharp.DevicesFetcher\PuppeteerSharp.DevicesFetcher.csproj", "{A500694A-3649-4474-BC71-C835FA19B865}"
1515
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5993B99D-AC7B-4D6F-832C-6784D7EFE9B3}"
17+
ProjectSection(SolutionItems) = preProject
18+
PuppeteerSharp.ruleset = PuppeteerSharp.ruleset
19+
.editorconfig = .editorconfig
20+
EndProjectSection
21+
EndProject
1622
Global
1723
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1824
Debug|Any CPU = Debug|Any CPU

lib/PuppeteerSharp/AddTagOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
namespace PuppeteerSharp
22
{
33
/// <summary>
4-
/// Options used by <see cref="Page.AddScriptTagAsync(AddTagOptions)"/> &amp; <see cref="Page.AddStyleTagAsync(AddTagOptions)"/>
4+
/// Options used by <see cref="Page.AddScriptTagAsync(AddTagOptions)"/> &amp; <see cref="Page.AddStyleTagAsync(AddTagOptions)"/>.
55
/// </summary>
66
public class AddTagOptions
77
{
88
/// <summary>
9-
/// Url of a script to be added
9+
/// Url of a script to be added.
1010
/// </summary>
1111
public string Url { get; set; }
1212

1313
/// <summary>
14-
/// Path to the JavaScript file to be injected into frame. If its a relative path, then it is resolved relative to <see cref="System.IO.Directory.GetCurrentDirectory"/>
14+
/// Path to the JavaScript file to be injected into frame. If its a relative path, then it is resolved relative to <see cref="System.IO.Directory.GetCurrentDirectory"/>.
1515
/// </summary>
1616
public string Path { get; set; }
1717

1818
/// <summary>
19-
/// Raw JavaScript content to be injected into frame
19+
/// Raw JavaScript content to be injected into frame.
2020
/// </summary>
2121
public string Content { get; set; }
2222

2323
/// <summary>
24-
/// Script type. Use <c>module</c> in order to load a Javascript ES6 module
24+
/// Script type. Use <c>module</c> in order to load a Javascript ES6 module.
2525
/// </summary>
2626
/// <seealso href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script"/>
2727
public string Type { get; set; }

0 commit comments

Comments
 (0)