Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit e1fe896

Browse files
committed
Readonly field formatter
Add the readonly keyword to fields that are provably never written to. Only mark private and internal fields, and the following are considered "writing" to a field: - Assignments (_field = 5) - Compound assignments (_field += 5) - ref/out calls (Method(ref _field)) - ref of parent to extern method. While not technically required the fields can possibly change (even when marked readonly) - internal fields that are exposed via InternalsVisibleTo an assembly that is not in the input project - fields marked with [Import] or [ImportMany] - fields of struct types that have methods called on them Fix #104
1 parent eee50a9 commit e1fe896

File tree

8 files changed

+978
-9
lines changed

8 files changed

+978
-9
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Microsoft.DotNet.CodeFormatting.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<SpecificVersion>False</SpecificVersion>
6969
<HintPath>..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
7070
</Reference>
71+
<Reference Include="System.ComponentModel.Composition" />
7172
<Reference Include="System.Composition.AttributedModel, Version=1.0.27.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
7273
<SpecificVersion>False</SpecificVersion>
7374
<HintPath>..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll</HintPath>
@@ -113,6 +114,7 @@
113114
<Compile Include="Rules\NewLineAboveRuleTests.cs" />
114115
<Compile Include="Rules\PrivateFieldNamingRuleTests.cs" />
115116
<Compile Include="Rules\NonAsciiCharactersAreEscapedInLiteralsRuleTests.cs" />
117+
<Compile Include="Rules\MarkReadonlyFieldTests.cs" />
116118
<Compile Include="Rules\UsingLocationRuleTests.cs" />
117119
</ItemGroup>
118120
<ItemGroup>

0 commit comments

Comments
 (0)