diff --git a/lib/processor.js b/lib/processor.js index 785276df1..fcd8aaf67 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -43,6 +43,12 @@ module.exports = { state[group].disableRules.delete(rule) } break + case 'clear': + state.block.disableAll = false + state.block.disableRules.clear() + state.line.disableAll = false + state.line.disableRules.clear() + break } return false } else { diff --git a/lib/rules/comment-directive.js b/lib/rules/comment-directive.js index 1e53749d4..4e13840e6 100644 --- a/lib/rules/comment-directive.js +++ b/lib/rules/comment-directive.js @@ -107,11 +107,21 @@ function processLine (context, comment) { function create (context) { return { Program (node) { - const comments = (node.templateBody && node.templateBody.comments) || [] - for (const comment of comments) { + if (!node.templateBody) { + return + } + + // Send directives to the post-process. + for (const comment of node.templateBody.comments) { processBlock(context, comment) processLine(context, comment) } + + // Send a clear mark to the post-process. + context.report({ + loc: node.templateBody.loc.end, + message: 'clear' + }) } } } diff --git a/tests/lib/rules/comment-directive.js b/tests/lib/rules/comment-directive.js index 367d29dd8..f76c904b6 100644 --- a/tests/lib/rules/comment-directive.js +++ b/tests/lib/rules/comment-directive.js @@ -26,6 +26,7 @@ const linter = new eslint.CLIEngine({ }, plugins: ['vue'], rules: { + 'no-unused-vars': 'error', 'vue/comment-directive': 'error', 'vue/no-parsing-error': 'error', 'vue/no-duplicate-attributes': 'error' @@ -108,6 +109,22 @@ describe('comment-directive', () => { assert.deepEqual(messages[0].ruleId, 'vue/no-duplicate-attributes') assert.deepEqual(messages[0].line, 6) }) + + it('should not affect to the code in + ` + const messages = linter.executeOnText(code, 'test.vue').results[0].messages + + assert.strictEqual(messages.length, 1) + assert.strictEqual(messages[0].ruleId, 'no-unused-vars') + }) }) describe('eslint-disable-line', () => {