Skip to content

Commit b715d32

Browse files
author
Kapil Borle
committed
Ignore endofinput token kind
1 parent 1c34b25 commit b715d32

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Rules/PlaceOpenBrace.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ private IEnumerable<DiagnosticRecord> FindViolationsForNoNewLineAfterBrace(
122122
{
123123
for (int k = 0; k < tokens.Length - 1; k++)
124124
{
125+
// typically the last element is of kind endofinput,
126+
// but this checks adds additional safeguard
127+
if (tokens[k].Kind == TokenKind.EndOfInput)
128+
{
129+
break;
130+
}
131+
125132
if (tokens[k].Kind == TokenKind.LCurly
126133
&& tokens[k + 1].Kind != TokenKind.NewLine)
127134
{
@@ -162,6 +169,11 @@ private IEnumerable<DiagnosticRecord> FindViolationsForBraceShouldNotBeOnSameLin
162169
{
163170
for (int k = 1; k < tokens.Length; k++)
164171
{
172+
if (tokens[k].Kind == TokenKind.EndOfInput)
173+
{
174+
break;
175+
}
176+
165177
if (tokens[k].Kind == TokenKind.LCurly
166178
&& tokens[k - 1].Kind != TokenKind.NewLine)
167179
{

Rules/UseConsistentIndentation.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
6767
var tokens = Helper.Instance.Tokens;
6868
var diagnosticRecords = new List<DiagnosticRecord>();
6969
var indentationLevel = 0;
70-
bool onNewLine = true;
70+
var onNewLine = true;
7171
for (int k = 0; k < tokens.Length; k++)
7272
{
7373
var token = tokens[k];
74+
75+
if (token.Kind == TokenKind.EndOfInput)
76+
{
77+
break;
78+
}
79+
7480
switch (token.Kind)
7581
{
7682
case TokenKind.LCurly:

0 commit comments

Comments
 (0)