Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2802809

Browse files
authored
Restrict the vue/no-console rule to the <template> block (#2221)
1 parent e944bb8 commit 2802809

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

‎lib/rules/no-console.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const utils = require('../utils')
88

99
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
1010
module.exports = utils.wrapCoreRule('no-console', {
11+
skipCoreHandlers: true,
1112
create(context) {
1213
const options = context.options[0] || {}
1314
const allowed = options.allow || []

‎lib/utils/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ module.exports = {
382382
* @param {boolean} [options.skipDynamicArguments] If `true`, skip validation within dynamic arguments.
383383
* @param {boolean} [options.skipDynamicArgumentsReport] If `true`, skip report within dynamic arguments.
384384
* @param {boolean} [options.applyDocument] If `true`, apply check to document fragment.
385+
* @param {boolean} [options.skipCoreHandlers] If `true`, skip core handlers.
385386
* @param {WrapCoreRulePreprocess} [options.preprocess] Preprocess to calling create of core rule.
386387
* @param {WrapCoreRuleCreate} [options.create] If define, extend core rule.
387388
* @returns {RuleModule} The wrapped rule implementation.
@@ -418,6 +419,7 @@ module.exports = {
418419
categories,
419420
skipDynamicArguments,
420421
skipDynamicArgumentsReport,
422+
skipCoreHandlers,
421423
applyDocument,
422424
preprocess,
423425
create
@@ -457,7 +459,9 @@ module.exports = {
457459
}
458460

459461
const coreHandlers = coreRule.create(context)
460-
compositingVisitors(handlers, coreHandlers)
462+
if (!skipCoreHandlers) {
463+
compositingVisitors(handlers, coreHandlers)
464+
}
461465

462466
// Move `Program` handlers to `VElement[parent.type!='VElement']`
463467
if (handlers.Program) {

‎tests/lib/rules/no-console.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ tester.run('no-console', rule, {
5353
</template>
5454
`,
5555
options: [{ allow: ['log', 'warn', 'info'] }]
56+
},
57+
{
58+
filename: 'test.vue',
59+
code: `
60+
<template><div /></template>
61+
<script setup>
62+
console.log('test')
63+
</script>
64+
`
5665
}
5766
],
5867
invalid: [

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /