Skip to content

Commit c4356d5

Browse files
mysticateamichalsnik
authored andcommitted
Fix: unintentional disabling (#338)
1 parent 085f1ca commit c4356d5

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

lib/processor.js

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ module.exports = {
4343
state[group].disableRules.delete(rule)
4444
}
4545
break
46+
case 'clear':
47+
state.block.disableAll = false
48+
state.block.disableRules.clear()
49+
state.line.disableAll = false
50+
state.line.disableRules.clear()
51+
break
4652
}
4753
return false
4854
} else {

lib/rules/comment-directive.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,21 @@ function processLine (context, comment) {
107107
function create (context) {
108108
return {
109109
Program (node) {
110-
const comments = (node.templateBody && node.templateBody.comments) || []
111-
for (const comment of comments) {
110+
if (!node.templateBody) {
111+
return
112+
}
113+
114+
// Send directives to the post-process.
115+
for (const comment of node.templateBody.comments) {
112116
processBlock(context, comment)
113117
processLine(context, comment)
114118
}
119+
120+
// Send a clear mark to the post-process.
121+
context.report({
122+
loc: node.templateBody.loc.end,
123+
message: 'clear'
124+
})
115125
}
116126
}
117127
}

tests/lib/rules/comment-directive.js

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const linter = new eslint.CLIEngine({
2626
},
2727
plugins: ['vue'],
2828
rules: {
29+
'no-unused-vars': 'error',
2930
'vue/comment-directive': 'error',
3031
'vue/no-parsing-error': 'error',
3132
'vue/no-duplicate-attributes': 'error'
@@ -108,6 +109,22 @@ describe('comment-directive', () => {
108109
assert.deepEqual(messages[0].ruleId, 'vue/no-duplicate-attributes')
109110
assert.deepEqual(messages[0].line, 6)
110111
})
112+
113+
it('should not affect to the code in <script>.', () => {
114+
const code = `
115+
<template>
116+
<!-- eslint-disable -->
117+
<div id id="a">Hello</div>
118+
</template>
119+
<script>
120+
var a
121+
</script>
122+
`
123+
const messages = linter.executeOnText(code, 'test.vue').results[0].messages
124+
125+
assert.strictEqual(messages.length, 1)
126+
assert.strictEqual(messages[0].ruleId, 'no-unused-vars')
127+
})
111128
})
112129

113130
describe('eslint-disable-line', () => {

0 commit comments

Comments
 (0)