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

SA1008 triggered by typle return types on a method (c# version 7) #2308

Closed
jimmymain opened this issue Mar 9, 2017 · 11 comments
Closed

SA1008 triggered by typle return types on a method (c# version 7) #2308

jimmymain opened this issue Mar 9, 2017 · 11 comments
Assignees
Milestone

Comments

@jimmymain
Copy link

The following method triggers SA1008

public (string primary, string alternate) CalculateMetaphone(string word)
      ~
{
}

the only way to avoid the rule is thus:

public(string primary, string alternate) CalculateMetaphone(string word)

which is clearly incorrect.
if the return type is a tuple, then a space should be inserted.

@vweijsters vweijsters added the bug label Mar 9, 2017
@vweijsters
Copy link
Contributor

Hi, thanks for reporting this. StyleCop Analyzers is not fully C# 7 compatible yet at the moment unfortunately. We are tracking work for this in #2268

@sharwell sharwell added the c# 7 label Mar 13, 2017
Nozziel added a commit to Nozziel/StyleCopAnalyzers that referenced this issue Mar 19, 2017
@Nozziel
Copy link

Nozziel commented Mar 19, 2017

Fixed:
pull request

@GregReddick
Copy link

Running into the same issue. Would be nice to drop a new beta sometime soon.

@menees
Copy link

menees commented May 19, 2017

I'm also running into it. I'm working around it by using correct spacing and then putting a SuppressMessage attribute above it.

[SuppressMessage("StyleCop", "SA1008", Justification = "StyleCop doesn't understand C#7 tuple return types yet.")]

VS 2017 suggests #pragma warning default SA1008 and #pragma warning restore SA1008 directives before and after the offending line. But I prefer SuppressMessage because it only takes a single line, and it contains the justification for why it's there (i.e., letting me know it's a temporary workaround). Once StyleCop.Analyzers is updated, I can search for and remove these SuppressMessage usages easily.

@DonaldAirey
Copy link

DonaldAirey commented Mar 29, 2019

Why do you think this is closed? I'm using v1.0.2 and getting this warning on this line of code (generated from Roslyn):

this.deletedCollection.Insert(0, (DateTime.Now, accountCanonMap));

@sharwell
Copy link
Member

@gammafour It's closed because it was fixed in 1.1.0 Beta 2 😄

@c9952594
Copy link

This is still a problem when deconstructing a tuple both in the var and the =

var (a, b) = (1, 2);

@sharwell
Copy link
Member

@c9952594 We have a test covering that case specifically. I suspect you are using an older version.

[Fact]
public async Task TestTupleVariablesAsync()
{
var testCode = @"namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
var( x1, y1) = (1, 2);
var(x2, y2) = (1, 2);
var ( x3, y3) = (1, 2);
}
}
}
";
var fixedCode = @"namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
var (x1, y1) = (1, 2);
var (x2, y2) = (1, 2);
var (x3, y3) = (1, 2);
}
}
}
";
DiagnosticResult[] expectedDiagnostics =
{
Diagnostic(DescriptorPreceded).WithLocation(7, 16),
Diagnostic(DescriptorNotFollowed).WithLocation(7, 16),
Diagnostic(DescriptorPreceded).WithLocation(8, 16),
Diagnostic(DescriptorNotFollowed).WithLocation(9, 17),
};
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

@c9952594
Copy link

c9952594 commented Nov 30, 2020

@sharwell,

Thank you. That was a fast reply!

After looking I'm using .net core 3.1 so C# 8.0 (compiler version 3.7.0-6.20459.4).
Can't see the same test in SA1008CSharp8UnitTests.cs but then I don't know this code base well so it might be elsewhere.

@sharwell
Copy link
Member

Can't see the same test in SA1008CSharp8UnitTests.cs

This test class is derived from SA1008CSharp7UnitTests, which is in turn derived from SA1008UnitTests. Each version can add new tests, but retains the tests for previous versions.

@c9952594
Copy link

@sharwell,

Cheers. I can see that now so the latest version should work.
This lead me to take a look at StyleCop.Analyzers and saw it was out of date. Updated from 1.0.2 to 1.1.118 which has solved it.

Thank you very much.

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

8 participants