boakley / robotframework-lint

Linter for robot framework plain text files
Apache License 2.0
126 stars 48 forks source link

SimpleTableMixin.statements can produce a 'list index out of range' error #38

Open ntdaley opened 7 years ago

ntdaley commented 7 years ago

I don't know whether this affects any of the built in rules; but while writing some rules of my own, I used ResourceFile.settings, which uses SimpleTableMixin.statements.

One of my .robot files had a *** Settings *** table, with only two blank lines after it and no settings.

This seemed to get through to the last while loop in SimpleTableMixin.statements, where it popped off those two lines, but tried to keep going.

I suggest that

        # trim trailing blank statements                                                                                                                                                                       
        while (len(statements[-1]) == 0 or
           ((len(statements[-1]) == 1) and len(statements[-1][0]) == 0)):
            statements.pop()

needs to look more like

        # trim trailing blank statements                                                                                                                                                                       
        while (len(statements) > 0) and (
               (len(statements[-1]) == 0 or
           ((len(statements[-1]) == 1) and len(statements[-1][0]) == 0))
        ):
            statements.pop()
boakley commented 7 years ago

Thanks for the report and possible fix. I'll try to incorporate the fix soon.

On Tue, May 9, 2017 at 8:55 AM, Nicholas Daley notifications@github.com wrote:

I don't know whether this affects any of the built in rules; but while writing some rules of my own, I used ResourceFile.settings, which uses SimpleTableMixin.statements.

One of my .robot files had a Settings table, with only two blank lines after it and no settings.

This seemed to get through to the last while loop in SimpleTableMixin.statements, where it popped off those two lines, but tried to keep going.

I suggest that

    # trim trailing blank statements
    while (len(statements[-1]) == 0 or
     ((len(statements[-1]) == 1) and len(statements[-1][0]) == 0)):
        statements.pop()

needs to look more like

    # trim trailing blank statements
    while (len(statements) > 0) and (
           (len(statements[-1]) == 0 or
     ((len(statements[-1]) == 1) and len(statements[-1][0]) == 0))
    ):
        statements.pop()

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/boakley/robotframework-lint/issues/38, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEmYo6gZp0LMgxOkfrPhlxTsXyn_1W1ks5r4HA3gaJpZM4NVWrb .