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

Created on 9 Mar 2017  路  11Comments  路  Source: DotNetAnalyzers/StyleCopAnalyzers

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.

bug c# 7 fixed

Most helpful comment

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.

All 11 comments

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

Fixed:
pull request

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

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.

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));

@GammaFour It's closed because it was fixed in 1.1.0 Beta 2 馃槃

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

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

@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.

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.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mzhukovs picture mzhukovs  路  4Comments

batwad picture batwad  路  5Comments

wmjordan picture wmjordan  路  6Comments

SetTrend picture SetTrend  路  5Comments

SurajGupta picture SurajGupta  路  5Comments