Skip to content

Commit

Permalink
Add additional tests for rename conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 27, 2015
1 parent eae2771 commit b8251f9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ public class Test { }";
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}

[Fact]
public async Task TestLowerCaseEnumWithMemberMatchingTargetNameAsync()
{
var testCode = @"public enum test
{
Test
}";
var fixedCode = @"public enum Test
{
Test
}";

DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 13);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}

[Fact]
public async Task TestUpperCaseDelegateAsync()
{
Expand Down Expand Up @@ -807,15 +826,17 @@ public event System.EventHandler fooBar
public void foo()
{
}
public string iInterface { get; }
}
public interface IInterface
{
void foo();
int bar { get; }
event System.EventHandler fooBar;
string iInterface { get; }
}";
var fixedCode = @"public class TestClass : IInterface
{
Expand All @@ -835,22 +856,25 @@ public event System.EventHandler FooBar
public void Foo()
{
}
public string IInterface { get; }
}
public interface IInterface
{
void Foo();
int Bar { get; }
event System.EventHandler FooBar;
string IInterface { get; }
}";

var expected = new[]
{
this.CSharpDiagnostic().WithLocation(25, 10).WithArguments("foo"),
this.CSharpDiagnostic().WithLocation(26, 9).WithArguments("bar"),
this.CSharpDiagnostic().WithLocation(27, 31).WithArguments("fooBar"),
this.CSharpDiagnostic().WithLocation(26, 10).WithArguments("foo"),
this.CSharpDiagnostic().WithLocation(27, 9).WithArguments("bar"),
this.CSharpDiagnostic().WithLocation(28, 31).WithArguments("fooBar"),
this.CSharpDiagnostic().WithLocation(29, 12).WithArguments("iInterface"),
};

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down
27 changes: 21 additions & 6 deletions documentation/SA1300.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,30 @@ The name of a C# element does not begin with an upper-case letter.

## Rule description

A violation of this rule occurs when the names of certain types of elements do not begin with an upper-case letter. The following types of elements should use an upper-case letter as the first letter of the element name: *namespaces, classes, enums, structs, delegates, events, methods,* and *properties*.

In addition, any field which is public, internal, or marked with the const attribute should begin with an upper-case letter. Non-private readonly fields must also be named using an upper-case letter.

If the field or variable name is intended to match the name of an item associated with Win32 or COM, and thus needs to begin with a lower-case letter, place the field or variable within a special *NativeMethods* class. A NativeMethods class is any class which contains a name ending in NativeMethods, and is intended as a placeholder for Win32 or COM wrappers. StyleCop will ignore this violation if the item is placed within a NativeMethods class.
A violation of this rule occurs when the names of certain types of elements do not begin with an upper-case letter. The
following types of elements should use an upper-case letter as the first letter of the element name:

* Namespaces
* Classes
* Enums
* Structs
* Delegates
* Events
* Methods
* Properties

In addition, any field which is public, internal, or marked with the const attribute should begin with an upper-case
letter. Non-private readonly fields must also be named using an upper-case letter.

If the field or variable name is intended to match the name of an item associated with Win32 or COM, and thus needs to
begin with a lower-case letter, place the field or variable within a special `NativeMethods` class. A `NativeMethods`
class is any class which contains a name ending in `NativeMethods`, and is intended as a placeholder for Win32 or COM
wrappers. StyleCop will ignore this violation if the item is placed within a `NativeMethods` class.

## How to fix violations

To fix a violation of this rule, change the name of the element so that it begins with an upper-case letter, or place the item within a NativeMethods class if appropriate.
To fix a violation of this rule, change the name of the element so that it begins with an upper-case letter, or place
the item within a `NativeMethods` class if appropriate.

## How to suppress violations

Expand Down

0 comments on commit b8251f9

Please sign in to comment.