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

SA1100 autofix should replace base with 'this' #763

Closed
AArnott opened this issue May 1, 2015 · 3 comments
Closed

SA1100 autofix should replace base with 'this' #763

AArnott opened this issue May 1, 2015 · 3 comments
Labels

Comments

@AArnott
Copy link
Contributor

AArnott commented May 1, 2015

SA1100 tells me to not use base unless a local implementation exists. Its auto-fixer simply removes the base. prefix, which then produces an SA1101 violation (to prefix local calls with this.).

Can the SA1100 auto-fixer be fixed to replace base. with this. so that fixing it does not produce a new violation of another one of SA11xx's own rules?

@pdelvo
Copy link
Member

pdelvo commented May 1, 2015

Our code fix should do exactly that. It might be a visual studio code fix that is doing that.

private static Task<Document> GetTransformedDocument(Document document, SyntaxNode root, SyntaxNode node)
{
var thisExpressionSyntax = SyntaxFactory.ThisExpression()
.WithTriviaFrom(node)
.WithoutFormatting();
SyntaxNode newSyntaxRoot = root.ReplaceNode(node, thisExpressionSyntax);
return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
}

@sharwell
Copy link
Member

sharwell commented May 2, 2015

You are seeing a code fix for IDE0002 (a built-in diagnostic). Unfortunately, we cannot just disable this one like IDE0003 (#532) right now because it applies to other situations where it is helpful.

I'm going to assume this is caused by one of the following. Please reopen it if you believe this is incorrect.

  1. The light bulb contained a fix for IDE0002 and SA1100, and you clicked the one for IDE0002. The one you want to click has the following label:

    Replace 'base.' with 'this.'

  2. You are using Visual Studio 2015 RC and experiencing issues where StyleCopAnalyzers code fixes are not being presented in the light bulb. We encountered this with CTP 5 and again with CTP 6; in each case updating StyleCopAnalyzers to use the correct version of Roslyn resolved the problem. See Update code to use Roslyn RC2 #712 for the ongoing work on this migration for the recent update.

@AArnott
Copy link
Contributor Author

AArnott commented May 4, 2015

Yes, it appears you're correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants