Commit ac914ce
authored
[ci] Add DevDiv required Roslyn analyzers, fix errors (#704)
As part of building secure software, Microsoft DevDiv has a set of
[Roslyn anaylzers][0] dealing with security that should be run on every
managed assembly.
Adds these analyzers and fix any errors they introduce.
~~ Running Analyzers ~~
In order to run the Roslyn analyzers, the NuGet package
[`Microsoft.CodeAnalysis.FxCopAnalyzers`][1] must be added to each
project. Rather than do this manually now, and for each new project
in the future, we instead add this to the `Directory.Build.props` file,
which automatically adds it to all projects.
By default, adding the NuGet package runs all included analyzers at
each analyzer's default severity level. At this time, we are only
concerned with the prescribed security set, so we use
`.editorconfig` to set those analyzers as `error`, and all other
analyzers as `none`.
Projects that wish to opt out of running the analyzers can set
`<DisableRoslynAnalyzers>True</DisableRoslynAnalyzers>`.
~~ Fixing Errors ~~
The only errors surfaced by these analyzers is
[CA3075: Insecure DTD Processing][2]. These were fixed by using
`new XmlReaderSettings { XmlResolver = null }`, which will not attempt
to resolve and download any DTD files.
~~ Move `NullableAttributes.cs` ~~
`NullableAttributes.cs` is moved to the `src\utils` directory.
This file was added to `Java.Interop.Tools.JavaCallableWrappers.csproj`
via `..\Java.Interop\`. However, because the file resided in the
directory containing the strict `.editorconfig` for `Java.Interop.dll`,
it was applying those `.editorconfig` rules to
`Java.Interop.Tools.JavaCallableWrappers.dll`.
Moving it to a neutral directory fixed this.
~~ Other Notes ~~
Updating the `Java.Interop.dll` to the latest analyzer NuGet version
triggered some errors we had handled for that specific assembly, which
likely did not exist in the old analyzers and thus were not being
surfaced as errors. They do not appear to be rules that we are
actually concerned with, so they were disabled:
* CA1021 - Don't use out parameters
* CA1045 - Don't use reference parameters
* CA1822 - Mark methods static if they don't reference instance members
* CA1002 - Don't expose generic Lists
[0]: https://github.com/dotnet/roslyn-analyzers
[1]: https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/
[2]: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca3075?view=vs-20191 parent a98c1ae commit ac914ce
File tree
9 files changed
+315
-13
lines changed- src
- Java.Interop.Tools.JavaCallableWrappers
- Java.Interop
- utils
- tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests
- tools/generator
9 files changed
+315
-13
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
71 | 80 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | | - | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
67 | 64 | | |
68 | 65 | | |
69 | 66 | | |
70 | | - | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 52 | | |
57 | 53 | | |
58 | 54 | | |
| |||
File renamed without changes.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
0 commit comments