Skip to content

Commit

Permalink
Fix #53: Document should not be considered empty if it contains prepr…
Browse files Browse the repository at this point in the history
…ocessor directive.
  • Loading branch information
josefpihrt committed Feb 27, 2017
1 parent 207fce1 commit 62f5c38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -41,7 +42,11 @@ private void AnalyzeCompilationUnit(SyntaxNodeAnalysisContext context)

DeclareEachTypeInSeparateFileRefactoring.Analyze(context, compilationUnit);

if (compilationUnit.Span == compilationUnit.EndOfFileToken.Span)
SyntaxToken token = compilationUnit.EndOfFileToken;

if (compilationUnit.Span == token.Span
&& !token.HasTrailingTrivia
&& token.LeadingTrivia.All(f => !f.IsDirective))
{
context.ReportDiagnostic(
DiagnosticDescriptors.RemoveFileWithNoCode,
Expand Down
1 change: 1 addition & 0 deletions source/Tests/AnalyzersTests/AnalyzersTests.csproj
Expand Up @@ -66,6 +66,7 @@
<Compile Include="AvoidUsageOfWhileStatementToCreateInfiniteLoop.cs" />
<Compile Include="CallFindMethodInsteadOfFirstOrDefaultMethod.cs" />
<Compile Include="MarkFieldAsReadOnly.cs" />
<Compile Include="RemoveFileWithNoCode2.cs" />
<Compile Include="UnusedParameter.cs" />
<Compile Include="ParameterNameDiffersFromBase.cs" />
<Compile Include="OverridingMethodCannotChangeAccessModifiers.cs" />
Expand Down
12 changes: 12 additions & 0 deletions source/Tests/AnalyzersTests/RemoveFileWithNoCode2.cs
@@ -0,0 +1,12 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if ABC
// Copyright(c) Josef Pihrt.All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Roslynator.CSharp.Analyzers.Tests
{
public static class RemoveFileWithNoCode
{
}
}
#endif

0 comments on commit 62f5c38

Please sign in to comment.