Skip to content

New rule directive-comment doesn't work as expected #334

Closed
@bozzaj

Description

@bozzaj

eslint-plugin-vue Version: 4.1.0
eslint Version: 4.14.0

The directive-comment rule has an issue with the way the regular expressions are calculated. Consider the following line:
<!-- eslint-disable-next-line max-len -->

This should disable the rule max-len for the next line only. However, the current implementation disables the rule for the remainder of the file. This seems to be with the block regexp:
const COMMENT_DIRECTIVE_B = /^\s*(eslint-(?:en|dis)able)\s*(?:(\S|\S[\s\S]*\S)\s*)?$/

This matches the above line as such:
match[1] = 'eslint-disable'
match[2] = '-next-line max-len'

and that gets passed as a successful parse, causing eslint to disable max-len for the remainder of the file.

I couldn't work out a good regexp that would match "eslint-disable" (with no space between the statement and the --> for the comment) correctly so another alternative fix would be to call processLine() first and if that is successful, don't call processBlock().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions