- 
                Notifications
    You must be signed in to change notification settings 
- Fork 512
update SA1518 to ignore empty (0 bytes) files #3927
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -72,6 +72,12 @@ public override void Initialize(AnalysisContext context) | |
|  | ||
| private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCopSettings settings) | ||
| { | ||
| if (context.Tree.IsEmpty(context.CancellationToken)) | ||
|          | ||
| { | ||
| // Empty file never contain line endings. | ||
| return; | ||
| } | ||
|  | ||
| var endOfFileToken = context.Tree.GetRoot().GetLastToken(includeZeroWidth: true); | ||
| TextSpan reportedSpan = new TextSpan(endOfFileToken.SpanStart, 0); | ||
|  | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests for SA1518 can be improved by checking a file with a single space or something like that.
firstToken.FullSpan.Length == 0can currently be removed without any tests failing,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added two test cases with white space only "files".
Of those (depending on the setting) one would fail if the
IsEmptyhelper does not check if the token is empty.