Skip to content

The linter fails badly on incomplete control comments #13

@lelit

Description

@lelit

I use JSL with Emacs flymake, and when you start writing a control comment and the check is triggered before the comment is complete, the linter exits with a traceback:

  File ".../javascriptlint/lint.py", line 73, in _parse_control_comment
    keyword = control_comment.lower().split()[0]
IndexError: list index out of range

and thus the flymake-mode gets turned off.

I fixed the issue in my own branch of the tool: since it's under darcs VC, it's not easy for me to provide a git patch, moreover you dropped the test suite so my patch would not apply cleanly.

Anyway, I basically rewrote the _parse_control_comment() in lint.py:

def _parse_control_comment(comment):
    """ Returns None or (keyword, parms) """
    atom = comment.atom.strip()
    if atom.lower().startswith('jsl:'):
        control_comment = atom[4:]
    elif atom.startswith('@') and atom.endswith('@'):
        control_comment = atom[1:-1]
    else:
        return None

    control_comment_lower = control_comment.lower()
    for keyword in ('ignoreall',
                    'ignore',
                    'end',
                    'option explicit',
                    'import',
                    'fallthru',
                    'pass',
                    'declare',
                    'unused',
                    'content-type'):
        if control_comment_lower.startswith(keyword):
            break
    else:
        return None

    parms = control_comment[len(keyword):].strip()
    return (comment, keyword, parms)

As you can see, I also chose a different way of recognizing the "keyword", since the upstream way of using a split() and checking the presence in a dictionary seemed weak to me, given the existence of "option explicit" that contains a space...

For the curious, my branch can be fetched with

darcs get http://darcs.metapensiero.it/our/lele/javascriptlint

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions