@@ -171,23 +171,20 @@ def trailing_whitespace(physical_line):
171171 return 0 , "W293 blank line contains whitespace"
172172
173173
174- def trailing_blank_lines (physical_line , lines , line_number ):
174+ def trailing_blank_lines (physical_line , lines , line_number , total_lines ):
175175 r"""Trailing blank lines are superfluous.
176176
177177 Okay: spam(1)
178178 W391: spam(1)\n
179- """
180- if not physical_line .rstrip () and line_number == len (lines ):
181- return 0 , "W391 blank line at end of file"
182-
183-
184- def missing_newline (physical_line ):
185- r"""The last line should have a newline.
186179
187- Reports warning W292.
180+ However the last line should end with a new line ( warning W292) .
188181 """
189- if physical_line .rstrip () == physical_line :
190- return len (physical_line ), "W292 no newline at end of file"
182+ if line_number == total_lines :
183+ stripped_last_line = physical_line .rstrip ()
184+ if not stripped_last_line :
185+ return 0 , "W391 blank line at end of file"
186+ if stripped_last_line == physical_line :
187+ return len (physical_line ), "W292 no newline at end of file"
191188
192189
193190def maximum_line_length (physical_line , max_line_length , multiline ):
@@ -1265,7 +1262,7 @@ def report_invalid_syntax(self):
12651262
12661263 def readline (self ):
12671264 """Get the next line from the input buffer."""
1268- if self .line_number >= len ( self .lines ) :
1265+ if self .line_number >= self .total_lines :
12691266 return ''
12701267 line = self .lines [self .line_number ]
12711268 self .line_number += 1
@@ -1408,6 +1405,7 @@ def maybe_check_physical(self, token):
14081405 def check_all (self , expected = None , line_offset = 0 ):
14091406 """Run all checks on the input file."""
14101407 self .report .init_file (self .filename , self .lines , expected , line_offset )
1408+ self .total_lines = len (self .lines )
14111409 if self ._ast_checks :
14121410 self .check_ast ()
14131411 self .line_number = 0
0 commit comments