Skip to content

Rules

Every StyleBro rule, by area. Each one has a code fix that dotnet format applies (Fix All included), and each page has an example, the reasons, the configuration and how it differs from StyleCop.

Default: on means the rule reports as a warning with the package's preset; off rules are opt-in (dotnet_diagnostic.BROxxxx.severity = warning in .editorconfig). stylebro-migrate sets each rule from your StyleCop setup instead, and turns off the rules StyleCop doesn't have.

Where the rules and the preset differ from StyleCop: differences-from-stylecop.md. How every StyleCop rule maps to StyleBro or the SDK: stylecop-mapping.md, and the ones StyleBro leaves out: skipped-rules.md.

Files from NuGet packages aren't checked: a source package's files (contentFiles, or files a package's build targets compile) live in the package folder, where nobody can fix them and dotnet format would edit the shared package cache. The package passes the restore's package folders (NuGetPackageFolders) to PackageFileSuppressor, which hides every StyleBro finding there; without them (no package build targets), a path with a contentFiles folder counts. Shared source linked from elsewhere in the repository is still checked.

Source generator output isn't checked either: dotnet format can't fix or report a generated document, and the generator writes it again on every build. Roslyn only treats a file as generated by its name (.g.cs) or an <auto-generated> header, which generators don't have to write. The compiler puts every generated file under the project's obj folder (or CompilerGeneratedFilesOutputPath with EmitCompilerGeneratedFiles); the package passes both to GeneratedFileSuppressor, which hides every StyleBro finding there; without them, a path with an obj folder counts.

Ordering, spacing and comments

ID Title Replaces Default
BRO1001 Members should be ordered SA1201-SA1204, SA1214 on
BRO1002 Single-line comments should begin with a space SA1005 on
BRO1003 Property accessors should follow order SA1212 on
BRO1004 Event accessors should follow order SA1213 on
BRO1005 Documentation lines should begin with single space SA1004 on
BRO1006 Preprocessor keywords should not be preceded by a space SA1006 on
BRO1007 Partial elements should declare an access modifier SA1205 on
BRO1008 Using directives should be placed correctly SA1200 on

Readability

ID Title Replaces Default
BRO1101 Code should not contain empty statements SA1106 on
BRO1102 Each attribute should be in its own brackets SA1133 on
BRO1103 Constants should be on the right-hand side of comparisons SA1131 on
BRO1104 Use default instead of a value type's default constructor SA1129 on
BRO1105 Constructor initializers should be on their own line SA1128 on
BRO1106 Use string.Empty for empty strings SA1122 on
BRO1107 Split parameters should start on the line after the declaration SA1116 on
BRO1108 Parameters should be on the same line or on separate lines SA1117 on
BRO1109 Opening parenthesis or bracket should be on the declaration line SA1110 on
BRO1110 Closing parenthesis or bracket should be on the line of the last item SA1111 on
BRO1111 Generic type constraints should be on their own line SA1127 on
BRO1112 Do not use regions SA1124 off in the preset
BRO1113 Regions should not be placed inside code elements SA1123 on
BRO1114 Do not combine fields SA1132 on
BRO1115 Use shorthand for nullable types SA1125 on
BRO1116 Closing parenthesis should be on line of opening parenthesis SA1112 on
BRO1117 Comma should be on the same line as previous parameter SA1113 on
BRO1118 Parameter list should follow declaration SA1114 on
BRO1119 Parameter should follow comma SA1115 on
BRO1120 Comments should contain text SA1120 on
BRO1121 Enum values should be on separate lines SA1136 on
BRO1122 Use literal suffix notation instead of casting SA1139 on
BRO1123 Use tuple syntax SA1141 on
BRO1124 Refer to tuple elements by name SA1142 on
BRO1125 Use lambda syntax SA1130 on
BRO1126 Using directives should be qualified SA1135 on
BRO1127 Query clause should follow previous clause SA1102 on
BRO1128 Query clauses should be on separate lines or all on one line SA1103 on
BRO1129 Query clause should begin on new line when previous clause spans multiple lines SA1104 on
BRO1130 Query clauses spanning multiple lines should begin on own line SA1105 on
BRO1131 Do not prefix calls with base unless local implementation exists SA1100 on
BRO1132 Block statements should not contain embedded comments SA1108 on
BRO1133 Check for null in one form (none; Roslynator RCS1248) on
BRO1134 Declarations should not contain embedded comments (none; StyleCop issue #605) on
BRO1135 Integer literal suffixes should be upper case (none; Sonar S818) on
BRO1136 A lambda's single parameter should not be in parentheses (none; StyleCop issue #762) on
BRO1137 Remove a redundant 'return;' or 'yield break;' (none; StyleCop issue #760, Roslynator RCS1134) on
BRO1138 A string literal should be a plain string when nothing needs more (none; Roslynator RCS1214/RCS1192/RCS1262) on
BRO1139 Write 'else if' on one line (none; Roslynator RCS0041/RCS1006) on
BRO1140 A record with an empty body should end with ';' (none; Roslynator RCS1251) on
BRO1141 Object creation with an initializer: parentheses in one style (none; Roslynator RCS1050) on
BRO1142 Do not combine local variables (none; Roslynator RCS1081) on
BRO1143 No 'else' after a branch that ends in a jump (none; Meziantou MA0071, Roslynator RCS1211) off
BRO1144 Escape identifiers that C# 14 reads as keywords (none; Sonar S8367/S8368/S8380, no fix) on
BRO1145 A class, struct or interface with an empty body should end with ';' (none; Meziantou MA0206) off
BRO1146 Write 'record' without 'class' (none; Meziantou MA0174) on
BRO1147 No redundant null-forgiving ! (none; Sonar S8969, IDE0370) off
BRO1148 x is not null instead of x.HasValue (none; Meziantou MA0171) off
BRO1149 Merge an 'if' into the enclosing 'if' (none; Sonar S1066) on
BRO1150 Pass the predicate to the LINQ call instead of calling Where first (none; Sonar S2971) on
BRO1151 Pass the elements, not an array, to a params parameter (none; Sonar S3878) on

Naming

ID Title Replaces Default
BRO1301 Variable names should begin with a lower-case letter SA1312 on
BRO1302 Parameter names should begin with a lower-case letter SA1313 on
BRO1303 Private field names should be camelCase SA1306, SA1309 on
BRO1304 Interface names should begin with I SA1302 on
BRO1305 Type parameter names should begin with T SA1314 on
BRO1306 Constant, static readonly and non-private field names should be PascalCase SA1303, SA1304, SA1307, SA1311 on
BRO1307 Field names should not begin with a prefix SA1308 on
BRO1308 Field names should not contain an underscore SA1310 on
BRO1309 Element names should begin with an upper-case letter SA1300 on
BRO1310 Field names should not use Hungarian notation SA1305 off
BRO1311 Tuple element names should use correct casing SA1316 on
BRO1312 Namespace names should begin with an upper-case letter SA1300 off
BRO1313 Parameter names should match the base member (none; SA1315 proposed, never implemented; SDK CA1725) off
BRO1314 Asynchronous method names should end with Async (none; Roslynator RCS1046, Meziantou MA0137) off

Maintainability

ID Title Replaces Default
BRO1401 Use a trailing comma in multi-line initializers SA1413 on
BRO1402 Attribute constructor should not use unnecessary parenthesis SA1411 on
BRO1403 Remove delegate parenthesis when possible SA1410 on
BRO1404 Access modifier should be declared SA1400 on
BRO1405 Statement should not use unnecessary parenthesis SA1119 on
BRO1406 Arithmetic expressions should declare precedence SA1407 on
BRO1407 Conditional expressions should declare precedence SA1408 on
BRO1408 Remove a redundant base type (none; Roslynator RCS1042) on
BRO1409 Methods of internal types should be internal, not public (none; StyleCop issue #2981, never implemented) off
BRO1410 Patterns should not use unnecessary parentheses (none; SA1119 checks expressions only) on

Layout

ID Title Replaces Default
BRO1501 Opening braces should not be preceded by a blank line SA1509 on
BRO1502 Chained blocks should not be preceded by a blank line SA1510 on
BRO1503 Opening braces should not be followed by a blank line SA1505 on
BRO1504 Single-line comments should be preceded by a blank line SA1515 on
BRO1505 Elements should be separated by a blank line SA1516 on
BRO1506 Single-line comments should not be followed by a blank line SA1512 on
BRO1507 Files should not end with blank lines SA1518 on
BRO1508 A block should not be on a single line SA1501 on
BRO1509 An element should not be on a single line SA1502 on
BRO1510 Accessors should all be single-line or all multi-line SA1504 on
BRO1511 Element documentation headers should not be followed by blank line SA1506 on
BRO1512 While-do footer should not be preceded by blank line SA1511 on
BRO1513 Element documentation header should be preceded by blank line SA1514 on
BRO1514 Braces should not be omitted SA1503 on
BRO1515 Braces should not be omitted from multi-line child statement SA1519 on
BRO1516 Use braces consistently SA1520 on
BRO1517 Code should not contain multiple blank lines in a row SA1507 on
BRO1518 Closing braces should not be preceded by blank line SA1508 on
BRO1519 Closing brace should be followed by blank line SA1513 on
BRO1520 Place the operator consistently when an expression wraps (none; Roslynator RCS0027/RCS0028) on
BRO1521 Place '=>' consistently when an expression body wraps (none; Roslynator RCS0032) on
BRO1522 Place '=' consistently when an assignment wraps (none; Roslynator RCS0052) on
BRO1523 Each call of a split call chain starts its own line (none; Roslynator RCS0054) on
BRO1524 A split conditional expression has the condition, '?' and ':' parts on their own lines (none; StyleCop issue #651) on
BRO1525 Attributes should not be followed by a blank line (none; SA1521 proposed, never implemented) on
BRO1526 Blank line between switch sections (none; Roslynator RCS0061) on
BRO1527 Auto-accessors should be on one line (none; Roslynator RCS0042) on

Documentation

ID Title Replaces Default
BRO1601 Overrides and implementations should inherit their documentation SA1600 (these members) on
BRO1602 Single-line comments should not use documentation style slashes SA1626 on
BRO1603 Documentation text should end with a period SA1629 on
BRO1604 Property summary documentation should match accessors SA1623 on
BRO1605 Property summary documentation should omit accessor with restricted access SA1624 on
BRO1606 Constructor summary documentation should begin with standard text SA1642 on
BRO1607 Destructor summary documentation should begin with standard text SA1643 on
BRO1608 Void return value should not be documented SA1617 on
BRO1609 Do not use placeholder elements SA1651 on
BRO1610 Documentation text should not be empty SA1627 on
BRO1611 Element parameter documentation should match element parameters SA1612 on
BRO1612 Element parameter documentation should declare parameter name SA1613 on
BRO1613 Generic type parameter documentation should match type parameters SA1620 on
BRO1614 Generic type parameter documentation should declare parameter name SA1621 on
BRO1615 File should have the XML copyright header (needs stylebro_file_header_company) SA1633-SA1638, SA1640, SA1641 on
BRO1616 Write the summary's tags consistently on their own lines or on the text's line (none; Roslynator RCS1253, Meziantou MA0177/MA0211) on
BRO1617 Write a cref's type arguments in braces (none; StyleCop's proposed SA1653) on
BRO1618 Write a C# keyword in documentation as <see langword="..."/> (none; Meziantou MA0154) on
BRO1619 Put the documentation elements in the standard order (none) on