Ejemplo n.º 1
0
        public async Task<Solution> EnforceAsync(Document document)
        {
            if (document == null) { throw new ArgumentNullException(nameof(document)); }

            IReadOnlyList<string> headerComments = document.GetOption(HeaderComments);
            string newLineText = document.GetOption(GlobalOptions.NewLineText);
            SyntaxTriviaList commentTrivia = this.commentCache.GetOrAdd(
                headerComments, c => BuildCommentTrivia(headerComments, newLineText));

            SyntaxNode syntaxRoot = await document.GetSyntaxRootAsync();

            if (syntaxRoot.HasLeadingTrivia)
            {
                SyntaxTriviaList leadingTrivia = syntaxRoot.GetLeadingTrivia();
                if (!leadingTrivia.IsEquivalentTo(commentTrivia))
                {
                    Log.WriteInformation("{0}: Rewriting non-conforming header comment", document.Name);
                    syntaxRoot = syntaxRoot.WithLeadingTrivia().WithLeadingTrivia(commentTrivia);
                    document = document.WithSyntaxRoot(syntaxRoot);
                }
            }
            else if (commentTrivia.Count > 0)
            {
                Log.WriteInformation("{0}: Adding missing header comment", document.Name);
                syntaxRoot = syntaxRoot.WithLeadingTrivia(commentTrivia);
                document = document.WithSyntaxRoot(syntaxRoot);
            }

            return document.Project.Solution;
        }
Ejemplo n.º 2
0
        public async Task<bool> IsMatchAsync(Document document)
        {
            SemanticModel semanticModel = await document.GetSemanticModelAsync();

            var matcher = new AttributeSyntaxMatcher(document.GetOption(AttributeNames), semanticModel);
            matcher.Visit(await document.GetSyntaxRootAsync());

            return matcher.HasMatch;
        }
        public async Task<Solution> EnforceAsync(Document document)
        {
            if (document == null) { throw new ArgumentNullException(nameof(document)); }

            SemanticModel semanticModel = await document.GetSemanticModelAsync();
            var syntaxRewriter = new ImplicitVariableSyntaxRewriter(
                document.GetOption(EnforceForEachStatements), semanticModel);

            SyntaxNode oldRoot = await document.GetSyntaxRootAsync();
            SyntaxNode newRoot = syntaxRewriter.Visit(oldRoot);

            if (oldRoot != newRoot)
            {
                Log.WriteInformation("{0}: Correcting implicit variable declarations", document.Name);
                document = document.WithSyntaxRoot(newRoot);
            }

            return document.Project.Solution;
        }
Ejemplo n.º 4
0
 public UsingTriviaFixer(Document document)
 {
     this.newLineTrivia = SyntaxFactory.EndOfLine(document.GetOption(GlobalOptions.NewLineText));
 }
Ejemplo n.º 5
0
            public Task<Solution> EnforceAsync(Document document)
            {
                document.GetOption(GlobalOptions.NewLineText).Should().Be(
                    NewLineText, "Unexpected newLineText global option value");

                onComponentExecuted(typeof(TestRule2), document.Name);

                return Task.FromResult(document.Project.Solution);
            }
Ejemplo n.º 6
0
            public Task<Solution> EnforceAsync(Document document)
            {
                document.GetOption(BooleanOption).Should().Be(
                    TestRuleBooleanOption, "Unexpected boolean option value");
                document.GetOption(StringsOption).ShouldBeEquivalentTo(
                    TestRuleStringsOption, "Unexpected strings option value");

                onComponentExecuted(typeof(TestRule1), document.Name);

                return Task.FromResult(document.Project.Solution);
            }
Ejemplo n.º 7
0
            public Task<bool> IsMatchAsync(Document document)
            {
                document.GetOption(BooleanOption).Should().Be(
                    TestMatcherBooleanOption, "Unexpected boolean option value");

                onComponentExecuted(typeof(TestMatcher), document.Name);

                return Task.FromResult(isMatch(document.Name));
            }