microsoft / microsoft/component-detection

Fix analyzer warnings

Open
#202 1 comment 0 reactions 0 assignees View on GitHub
good first issue status:in-progress type:refactor
Dominant language
C#
Stars
553
Forks
135
Avg merge
20h 58m
Merged PRs (30d)
6

Description

This is an overarching issue to track analyzer warnings that are currently silenced. To fix a single warning:

1. Remove the warning silence from [`.editorconfig`](https://github.com/microsoft/component-detection/blob/main/.editorconfig)
2. Run a build locally
3. Fix any warnings that are emitted
4. Create a pull request
5. Link it to this issue
6. Once merged check the relevant box below

Table of Contents

- `StyleCop.Analyzers`
- `Microsoft.VisualStudio.Threading.Analyzers`
- `Roslyn`
- Introduced with .NET 6 migration
- Language rules
- Code quality rules
- `StyleCop.Analyzers`

## [`StyleCop.Analyzers`](https://github.com/DotNetAnalyzers/StyleCopAnalyzers)

- [x] [SA1001](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1001.md)
- Commas should not be preceded by whitespace
- #204
- [x] [SA1005](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1005.md)
- Single line comment should begin with a space
- #205
- [x] [SA1101](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1101.md)
- Prefix local calls with this
- #236
- [x] [SA1105](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1105.md)
- Single line comment should begin with a space
- #206
- [x] [SA1008](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1008.md)
- Opening parenthesis should not be followed by a space.
- #212
- [x] [SA1009](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1009.md)
- Closing parenthesis should not be followed by a space
- #210
- [x] [SA1011](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1011.md)
- Closing square bracket should be followed by a space
- #211
- [x] [SA1012](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1012.md)
- Opening brace should be preceded by a space
- #213
- [x] [SA1013](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1013.md)
- Closing brace should be preceded by a space
- #213
- [x] [SA1026](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1026.md)
- The keyword 'new' should not be followed by a space or a blank line
- #213
- [x] [SA1108](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1108.md)
- Block statements should not contain embedded comments
- #237
- [x] [SA1114](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1114.md)
- Parameter list should follow declaration
- #238
- [x] [SA1117](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1117.md)
- The parameters should all be placed on the same line or each parameter should be placed on its own line
- #214
- [x] [SA1118](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1118.md)
- The parameter spans multiple lines
- #213
- [x] [SA1135](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1135.md)
- Using directive for namespace '...' should be qualified
- #225
- [x] [SA1137](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1137.md)
- Elements should have the same indentation
- #209
- [x] [SA1142](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1142.md)
- Refer to tuple fields by name
- ~#239~
- #308
- [x] [SA1200](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md)
- Using directive should appear within a namespace declaration
- ~#239~
- #416
- [x] [SA1201](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1201.md)
- A field should not follow a property
- ~#239~
- #308
- [x] [SA1202](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1202.md)
- Constant fields should appear before non-constant fields
- [x] [SA1203](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1203.md)
- 'public' members should come before 'private' members
- #264
- #319
- [x] [SA1204](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1204.md)
- Static members should appear before non-static members
- #219
- [x] [SA1208](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1208.md)
- Using directive for '...' should appear before directive for '...'
- #218
- [x] [SA1210](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)
- Using directives should be ordered alphabetically by the namespaces
- #227
- [x] [SA1214](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1214.md)
- Readonly fields should appear before non-readonly fields
- #250
- [x] [SA1216](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1216.md)
- Using static directives should be placed at the correct location
- #265
- #319
- [x] [SA1316](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1316.md)
- Tuple element names should use correct casing
- #319
- [x] [SA1401](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1401.md)
- Field should be private
- #319
- [x] [SA1413](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1413.md)
- Use trailing comma in multi-line initializers
- #249
- [ ] [SA1414](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1414.md)
- Tuple types in signatures should have element names
- [x] [SA1500](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1500.md)
- Braces for multi-line statements should not share line
- #223
- #317
- [x] [SA1515](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1515.md)
- Single-line comment should be preceded by blank line
- #248
- #317
- [x] [SA1518](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1518.md)
- File is required to end with a single newline character
- #208
- [ ] [SA1600](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1600.md)
- Elements should be documented
- [ ] [SA1602](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1602.md)
- Enumeration items should be documented
- [ ] [SA1604](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1604.md)
- Element documentation should have summary
- [ ] [SA1611](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1611.md)
- The documentation for parameter '...' is missing
- [x] [SA1614](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1614.md)
- Element parameter documentation should have text
- [x] [SA1615](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1615.md)
- Element return value should be documented
- [x] [SA1616](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1616.md)
- Element return value documentation should have text
- [x] [SA1617](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1617.md)
- Void return value should not be documented
- [x] [SA1629](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1629.md)
- Documentation text should end with a period
- #226
- [ ] [SA1633](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)
- The file header is missing or not located at the top of the file.
- [ ] [SA1642](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1642.md)
- Constructor summary documentation should begin with standard text
- [x] [SA1648](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1648.md)
- inheritdoc should be used with inheriting class
- #207

## [`Microsoft.VisualStudio.Threading.Analyzers`](https://github.com/Microsoft/vs-threading)

- [ ] [VSTHRD002](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD002.md)
- Synchronously waiting on tasks or awaiters may cause deadlocks. Use await or JoinableTaskFactory.Run instead.
- [ ] [VSTHRD103](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD103.md)
- Result synchronously blocks. Use await instead.
- [ ] [VSTHRD101](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md)
- Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process
- [ ] [VSTHRD104](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD104.md)
- Expose an async version of this method that does not synchronously block. Then simplify this method to call that async method within a JoinableTaskFactory.Run delegate.
- [ ] [VSTHRD111](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD111.md)
- Add .ConfigureAwait(bool) to your await expressio
- [x] [VSTHRD200](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md)
- Use "Async" suffix in names of methods that return an awaitable type
- #416

## [`Roslyn`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/)
- [ ] [CS0618](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0618)
- '...' is obsolete
- [ ] [CS1591](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1591)
- Missing XML comment for publicly visible type or member '...'

## Introduced with .NET 6 migration

### [Language rules](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules)

- [ ] [IDE0003](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009)
- Remove this or Me qualification
- [x] IDE0004
- Cast is redundant
- #305
- [x] IDE0005
- Using directive is unnecessary
- #303
- [x] IDE0007
- use 'var' instead of explicit type
- #305
- [ ] [IDE0008](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008)
- 'var' preferences
- [x] IDE0009
- Add 'this' or 'Me' qualification
- #303
- [x] IDE0010
- Populate switch
- #317
- [x] IDE0016
- Null check can be simplified
- #305
- [x] IDE0017
- Object initialization can be simplified
- #305
- [x] IDE0018
- Variable declaration can be inlined
- #305
- [x] [IDE0019](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0019)
- Use pattern matching to avoid 'as' followed by a 'null' check
- #326
- [x] IDE0021
- Use expression body for constructors
- #326
- [ ] IDE0022
- Use expression body for methods
- [x] IDE0024
- Use expression body for operators
- #317
- [ ] IDE0025
- Use expression body for properties
- [x] IDE0031
- Null check can be simplified
- #305
- [x] [IDE0032](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0032)
- Use auto property
- #319
- [x] IDE0033
- Prefer explicitly provided tuple element name
- #303
- [ ] [IDE0034](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0034)
- Simplify 'default' expression
- [ ] IDE0036
- Order modifiers
- [x] IDE0037
- Member name can be simplified
- #326
- [x] IDE0039
- Use local function
- #317
- [x] IDE0041
- Null check can be
- #303
- [x] IDE0042
- Variable declaration can be deconstructed
- #305
- [x] IDE0044
- Add readonly modifier
- #317
- [x] IDE0051
- Private member is unused
- #303
- [x] IDE0052
- Private member 'TabularStringFormat.totalWidth' can be removed as the value assigned to it is never read
- #319
- [x] IDE0054
- Use compound assignment
- #319
- [x] IDE0055
- Formatting rule
- #326
- [x] IDE0057
- Substring can be simplified
- #326
- [ ] IDE0060
- Remove unused parameter
- [ ] IDE0065
- 'using' directive placement
- [x] IDE0066
- Use 'switch'
- #317
- [x] IDE0071
- Interpolation can be simplified
- #319
- [x] IDE0074
- Use compound assignment
- #317
- [x] IDE0075
- Conditional expression can be simplified
- #317
- [ ] IDE0078
- Use pattern matching (may change code meaning)
- [ ] IDE0083
- Use pattern matchin
- [ ] IDE0090
- Simplify new expression
- [x] IDE0120
- Simplify LINQ
- #319
- [x] IDE0150
- Null check can be clarified
- #303
- [ ] IDE0160 and IDE0161
- Namespace declaration preferences
- [ ] IDE0220
- N/A
- [ ] IDE1006
- Naming rule violation

### [Code quality rules](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/)

- [ ] CA1001
- Types that own disposable fields should be disposable
- [ ] CA1002
- Do not expose generic lists
- [ ] CA1014
- Mark assemblies with CLSCompliantAttribute
- [x] CA1018
- Mark attributes with AttributeUsageAttribute
- #416
- [ ] CA1024
- Use properties where appropriate
- [ ] CA1027
- Mark enums with FlagsAttribute
- [ ] CA1028
- Enum Storage should be Int32
- [ ] CA1031
- Do not catch general exception types
- [x] CA1032
- Implement standard exception constructors
- #416
- [x] CA1033
- Interface methods should be callable by child types
- #416
- [ ] CA1034
- Nested types should not be visible
- [ ] CA1036
- Override methods on comparable types
- [x] CA1040
- Avoid empty interfaces
- #337
- [ ] CA1051
- Do not declare visible instance fields
- [x] CA1052
- Static holder types should be Static or NotInheritable
- #416
- [ ] CA1054
- URI-like parameters should not be strings
- [ ] CA1056
- URI-like properties should not be strings
- [ ] CA1062
- Validate arguments of public methods
- [ ] CA1064
- Exceptions should be public
- [ ] CA1303
- Do not pass literals as localized parameters
- [ ] CA1304
- Specify CultureInfo
- [ ] CA1305
- Specify IFormatProvider
- [ ] CA1307
- Specify StringComparison for clarity
- [x] CA1308
- Normalize strings to uppercase
- #335
- [ ] CA1309
- Use ordinal string comparison
- [ ] CA1310
- Specify StringComparison for correctness
- [x] CA1401
- P/Invokes should not be visible
- #416
- [x] CA1508
- Avoid dead conditional code
- #416
- [x] CA1707
- Identifiers should not contain underscores
- #337
- [ ] CA1711
- Identifiers should not have incorrect suffix
- [ ] CA1724
- Type names should not match namespaces
- [x] CA1725
- Parameter names should match base declaration
- #416
- [x] CA1805
- Do not initialize unnecessarily
- #416
- [ ] CA1806
- Do not ignore method results
- [x] CA1813
- Avoid unsealed attributes
- #416
- [ ] CA1819
- Properties should not return arrays
- [ ] CA1820
- Test for empty strings using string length
- [ ] CA1822
- Mark members as static
- [ ] CA1823
- Avoid unused private fields
- [ ] CA1824
- Mark assemblies with NeutralResourcesLanguageAttribute
- [x] CA1825
- Avoid zero-length array allocations
- #416
- [x] CA1827
- Do not use Count() or LongCount() when Any() can be used
- #317
- [x] CA1836
- Prefer IsEmpty over Count
- #416
- [x] CA1829
- Use Length/Count property instead of Count() when available
- #338
- [x] CA1834
- Consider using 'StringBuilder.Append(char)' when applicable
- #338
- [x] CA1835
- Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
- #416
- [ ] CA1837
- Use 'Environment.ProcessId'
- [x] CA1838
- Avoid 'StringBuilder' parameters for P/Invokes
- #416
- [x] CA1846
- Prefer 'AsSpan' over 'Substring'
- #338
- [x] CA1847
- Use char literal for a single character lookup
- #338
- [ ] CA1849
- Call async methods when in an async method
- [x] CA2000
- Dispose objects before losing scope
- #416
- [ ] CA2007
- Consider calling ConfigureAwait on the awaited task
- [x] CA2016
- Forward the 'CancellationToken' parameter to methods
- #416
- [x] CA2101
- Specify marshaling for P/Invoke string arguments
- #416
- [x] CA2201
- Exception type System.Exception is not sufficiently specific
- #416
- [x] CA2208
- Instantiate argument exceptions correctly
- #416
- [ ] CA2211
- Non-constant fields should not be visible
- [ ] CA2219
- Do not raise exceptions in finally clauses
- [x] CA2234
- Pass system uri objects instead of strings
- #416
- [ ] CA2251
- Use 'string.Equals'
- [ ] CA2227
- Collection properties should be read only
- [x] CA2249
- Consider using 'string.Contains' instead of 'string.IndexOf'
- #416
- [x] CA5392
- Use DefaultDllImportSearchPaths attribute for P/Invokes
- #416

### [`StyleCop.Analyzers`](https://github.com/DotNetAnalyzers/StyleCopAnalyzers)

- [x] SA1028
- Code should not contain trailing whitespace
- #303
- [ ] SA1101
- Prefix local calls with this
- [ ] SA1201
- Elements should appear in the correct order
- [ ] SA1202
- Elements should be ordered by access
- [x] SA1500
- Braces for multi-line statements should not share line
- #317
- [x] SA1515
- Single-line comment should be preceded by blank line
- #317

Contributor guide

Open the contributing guide

Research direction

Start with .editorconfig and choose one unchecked analyzer rule from the issue, then run a local build to identify its warnings. Read the linked analyzer documentation and update the affected code; done means the warning is fixed, the build completes without it, and the relevant checklist item is checked after the pull request is merged.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.