Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StyleCop to maintain coding standards #1035

Closed
blairconrad opened this issue May 11, 2018 · 1 comment
Closed

Use StyleCop to maintain coding standards #1035

blairconrad opened this issue May 11, 2018 · 1 comment

Comments

@blairconrad
Copy link
Contributor

Sorry, this is totally unsolicited, but @moodmosaic and I were chatting about it a bit, and I figured I'd not pollute #1025 any more.

If you just plug StyleCop into the build, with no configuration at all, there are only 4506 errors. Here's a uniquified list. Roughly. I probably made some errors de-duplicating.

SA0001: XML comment analysis is disabled due to project configuration
SA1000: The keyword 'foreach' should be followed by a space.
SA1000: The keyword 'if' should be followed by a space.
SA1000: The keyword 'typeof' should not be followed by a space.
SA1002: Semicolons should be followed by a space.
SA1003: Operator '(AutoPropertiesCommand)' should not be followed by whitespace.
SA1003: Operator '(AutoPropertiesTarget)' should not be followed by whitespace.
SA1003: Operator '(IEnumerable<object>)' should not be followed by whitespace.
SA1003: Operator '(IRequestSpecification)' should not be followed by whitespace.
SA1003: Operator '(ISpecimenBuilder)' should not be followed by whitespace.
SA1003: Operator '(ISpecimenBuilderNode)' should not be followed by whitespace.
SA1003: Operator '(NodeComposer<T>)' should not be followed by whitespace.
SA1003: Operator '(Postprocessor)' should not be followed by whitespace.
SA1003: Operator '(TAttribute)' should not be followed by whitespace.
SA1003: Operator '(byte)' should not appear at the end of a line.
SA1003: Operator '(decimal)' should not appear at the end of a line.
SA1003: Operator '(double)' should not appear at the end of a line.
SA1003: Operator '(float)' should not appear at the end of a line.
SA1003: Operator '(int)' should not appear at the end of a line.
SA1003: Operator '(sbyte)' should not appear at the end of a line.
SA1003: Operator '(short)' should not appear at the end of a line.
SA1003: Operator '(uint)' should not appear at the end of a line.
SA1003: Operator '(ulong)' should not appear at the end of a line.
SA1003: Operator '(ushort)' should not appear at the end of a line.
SA1003: Operator '*' should be followed by whitespace.
SA1003: Operator '*' should be preceded by whitespace.
SA1003: Operator ':' should be preceded by whitespace.
SA1004: Documentation line should begin with a space.
SA1005: Single line comment should begin with a space.
SA1009: Closing parenthesis should be followed by a space.
SA1009: Closing parenthesis should not be followed by a space.
SA1009: Closing parenthesis should not be preceded by a space.
SA1012: Opening brace should be followed by a space.
SA1013: Closing brace should be preceded by a space.
SA1024: Colon should be preceded by a space.
SA1025: Code should not contain multiple whitespace characters in a row.
SA1026: The keyword 'new' should not be followed by a space or a blank line.
SA1027: Tabs and spaces should be used correctly
SA1028: Code should not contain trailing whitespace
SA1100: Do not prefix calls with base unless local implementation exists
SA1106: Code should not contain empty statements
SA1107: Code should not contain multiple statements on one line
SA1111: Closing parenthesis should be on line of last parameter
SA1115: The parameter should begin on the line after the previous parameter.
SA1116: The parameters should begin on the line after the declaration, whenever the parameter span across multiple lines
SA1117: The parameters should all be placed on the same line or each parameter should be placed on its own line.
SA1118: The parameter spans multiple lines
SA1119: Statement should not use unnecessary parenthesis
SA1121: Use built-in type alias
SA1122: Use string.Empty for empty strings
SA1124: Do not use regions
SA1127: Generic type constraints should be on their own line
SA1128: Put constructor initializers on their own line
SA1131: Constant values should appear on the right-hand side of comparisons
SA1133: Each attribute should be placed in its own set of square brackets.
SA1200: Using directive should appear within a namespace declaration
SA1201: A constructor should not follow a event
SA1201: A constructor should not follow a method
SA1201: A constructor should not follow a property
SA1201: A enum should not follow a method
SA1201: A field should not follow a method
SA1201: A field should not follow a property
SA1201: A indexer should not follow a method
SA1201: A interface should not follow a class
SA1201: A property should not follow a method
SA1202: 'internal' members should come before 'private' members
SA1202: 'public' members should come before 'internal' members
SA1202: 'public' members should come before 'private' members
SA1203: Constant fields should appear before non-constant fields
SA1204: Static members should appear before non-static members
SA1210: Using directives should be ordered alphabetically by the namespaces.
SA1214: Readonly fields should appear before non-readonly fields
SA1313: Parameter '_' should begin with lower-case letter
SA1401: Field should be private
SA1402: File may only contain a single type
SA1404: Code analysis suppression should have justification
SA1407: Arithmetic expressions should declare precedence
SA1408: Conditional expressions should declare precedence
SA1413: Use trailing comma in multi-line initializers
SA1500: Braces for multi-line statements should not share line
SA1502: Element should not be on a single line
SA1503: Braces should not be omitted
SA1505: An opening brace should not be followed by a blank line.
SA1507: Code should not contain multiple blank lines in a row
SA1508: A closing brace should not be preceded by a blank line.
SA1509: Opening braces should not be preceded by blank line.
SA1512: Single-line comments should not be followed by blank line
SA1513: Closing brace should be followed by blank line
SA1514: Element documentation header should be preceded by blank line
SA1516: Elements should be separated by blank line
SA1518: Code should not contain blank lines at the end of the file
SA1519: Braces should not be omitted from multi-line child statement
SA1600: Elements should be documented
SA1611: The documentation for parameter 'blah' is missing
SA1614: Element parameter documentation should have text
SA1615: Element return value should be documented
SA1616: Element return value documentation should have text
SA1618: The documentation for type parameter 'blah' is missing
SA1622: Generic type parameter documentation should have text.
SA1623: The property's documentation summary text should begin with: 'Gets a value indicating whether'
SA1623: The property's documentation summary text should begin with: 'Gets or sets a value indicating whether'
SA1623: The property's documentation summary text should begin with: 'Gets'
SA1625: Element documentation should not be copied and pasted
SA1627: The documentation text within the \'exception\' tag should not be empty.
SA1633: The file header XML is invalid.
SA1633: The file header is missing or not located at the top of the file.
SA1642: Constructor summary documentation should begin with standard text

It probably wouldn't be too bad to initially turn most rules off and then turn the ones you care about on in small batches, transforming the code as one went. This could be merged in one or multiple PRs.

I shouldn't say it out loud, but it's the kind of work that I enjoy. If there was interest, and the owners agreed on an initial set of rules, I'd noodle away at hooking stuff up and resolving violations.

@blairconrad
Copy link
Contributor Author

blairconrad commented May 17, 2018

Here's a different view of the violations in master (as of 11066d7), with counts on the left. In some cases, the description of a rule will differ, for example, if you look above, you see SA1202 has several incarnations, all about how member visibility affects ordering. Below, all violations of the same type have been lumped together.

  • 1861 - SA1200: Using directive should appear within a namespace declaration
  • 1076 - SA1503: Braces should not be omitted
  • 824 - SA1633: The file header is missing or not located at the top of the file.
  • 545 - SA1028: Code should not contain trailing whitespace
  • 159 - SA1121: Use built-in type alias
  • 136 - SA1600: Elements should be documented
  • 111 - SA1513: Closing brace should be followed by blank line
  • 104 - SA1201: A interface should not follow a class
  • 87 - SA1623: The property's documentation summary text should begin with: 'Gets'
  • 87 - SA1117: The parameters should all be placed on the same line or each parameter should be placed on its own line.
  • 77 - SA1009: Closing parenthesis should not be followed by a space.
  • 77 - SA1003: Operator '(ISpecimenBuilder)' should not be followed by whitespace.
  • 51 - SA1519: Braces should not be omitted from multi-line child statement
  • 48 - SA1642: Constructor summary documentation should begin with standard text
  • 42 - SA1000: The keyword 'if' should be followed by a space.
  • 42 - SA1116: The parameters should begin on the line after the declaration, whenever the parameter span across multiple lines
  • 39 - SA1618: The documentation for type parameter 'TProperty' is missing
  • 39 - SA1118: The parameter spans multiple lines
  • 27 - SA1111: Closing parenthesis should be on line of last parameter
  • 27 - SA1214: Readonly fields should appear before non-readonly fields
  • 27 - SA1611: The documentation for parameter 'delegateSpecification' is missing
  • 23 - SA1402: File may only contain a single type
  • 22 - SA1413: Use trailing comma in multi-line initializers
  • 21 - SA1204: Static members should appear before non-static members
  • 20 - SA1202: 'public' members should come before 'private' members
  • 18 - SA1407: Arithmetic expressions should declare precedence
  • 15 - SA1115: The parameter should begin on the line after the previous parameter.
  • 15 - SA1508: A closing brace should not be preceded by a blank line.
  • 15 - SA1615: Element return value should be documented
  • 14 - SA1401: Field should be private
  • 14 - SA1128: Put constructor initializers on their own line
  • 10 - SA1127: Generic type constraints should be on their own line
  • 10 - SA1516: Elements should be separated by blank line
  • 9 - SA1507: Code should not contain multiple blank lines in a row
  • 9 - SA1616: Element return value documentation should have text
  • 9 - SA1625: Element documentation should not be copied and pasted
  • 8 - SA1005: Single line comment should begin with a space.
  • 8 - SA1013: Closing brace should be preceded by a space.
  • 6 - SA1622: Generic type parameter documentation should have text.
  • 6 - SA1627: The documentation text within the 'exception' tag should not be empty.
  • 6 - SA1404: Code analysis suppression should have justification
  • 6 - SA1133: Each attribute should be placed in its own set of square brackets.
  • 6 - SA1614: Element parameter documentation should have text
  • 6 - SA1408: Conditional expressions should declare precedence
  • 6 - SA1012: Opening brace should be followed by a space.
  • 6 - SA1512: Single-line comments should not be followed by blank line
  • 4 - SA1313: Parameter '_' should begin with lower-case letter
  • 4 - SA1002: Semicolons should be followed by a space.
  • 3 - SA1026: The keyword 'new' should not be followed by a space or a blank line.
  • 3 - SA1210: Using directives should be ordered alphabetically by the namespaces.
  • 3 - SA1004: Documentation line should begin with a space.
  • 3 - SA1500: Braces for multi-line statements should not share line
  • 3 - SA1509: Opening braces should not be preceded by blank line.
  • 3 - SA1027: Tabs and spaces should be used correctly
  • 3 - SA1119: Statement should not use unnecessary parenthesis
  • 3 - SA1122: Use string.Empty for empty strings
  • 3 - SA1107: Code should not contain multiple statements on one line
  • 3 - SA1203: Constant fields should appear before non-constant fields
  • 3 - SA1106: Code should not contain empty statements
  • 3 - SA1518: Code should not contain blank lines at the end of the file
  • 3 - SA1514: Element documentation header should be preceded by blank line
  • 3 - SA1505: An opening brace should not be followed by a blank line.
  • 2 - SA0001: XML comment analysis is disabled due to project configuration
  • 2 - SA1024: Colon should be preceded by a space.
  • 2 - SA1502: Element should not be on a single line

I've been playing a bit in https://github.com/blairconrad/AutoFixture/tree/stylecop (not rebased on to the new merge, and missing some changes I've made at home) and drastically reduced the number of violations, either fixing the easy things or suppressing warnings that I think you'd want suppressed, such as the bits about putting usings inside namespaces. (And omitting braces.)

I imagine that within a week, I could finish things up enough to send a rough PR, and you can either reject it outright or wrangle about which rules you wanted fixed or ignored.

@blairconrad blairconrad changed the title Talk about StyleCop Use StyleCop to maintain coding standards May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants