Skip to content

Commit 0a6f0f2

Browse files
authored
Fix false negatives of "slot-scope" when "^3.0.0" is set in "no-unsupported-features" rule. (#1258)
1 parent 95cccec commit 0a6f0f2

13 files changed

+39
-29
lines changed

lib/rules/no-unsupported-features.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const utils = require('../utils')
99

1010
/**
1111
* @typedef {object} SyntaxRule
12-
* @property {string | ((range: semver.Range) => boolean)} supported
12+
* @property {string} supported
1313
* @property { (context: RuleContext) => TemplateListener } [createTemplateBodyVisitor]
1414
* @property { (context: RuleContext) => RuleListener } [createScriptVisitor]
1515
*/
@@ -28,6 +28,8 @@ const FEATURES = {
2828
'v-is': require('./syntaxes/v-is')
2929
}
3030

31+
const SYNTAX_NAMES = /** @type {(keyof FEATURES)[]} */ (Object.keys(FEATURES))
32+
3133
const cache = new Map()
3234
/**
3335
* Get the `semver.Range` object of a given range text.
@@ -71,7 +73,7 @@ module.exports = {
7173
ignores: {
7274
type: 'array',
7375
items: {
74-
enum: Object.keys(FEATURES)
76+
enum: SYNTAX_NAMES
7577
},
7678
uniqueItems: true
7779
}
@@ -82,7 +84,7 @@ module.exports = {
8284
messages: {
8385
// Vue.js 2.5.0+
8486
forbiddenSlotScopeAttribute:
85-
'`slot-scope` are not supported until Vue.js "2.5.0".',
87+
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
8688
// Vue.js 2.6.0+
8789
forbiddenDynamicDirectiveArguments:
8890
'Dynamic arguments are not supported until Vue.js "2.6.0".',
@@ -119,22 +121,15 @@ module.exports = {
119121
* @returns {boolean} `true` if it's supporting.
120122
*/
121123
function isNotSupportingVersion(aCase) {
122-
if (typeof aCase.supported === 'function') {
123-
return !aCase.supported(versionRange)
124-
}
125-
return versionRange.intersects(getSemverRange(`<${aCase.supported}`))
124+
return !semver.subset(versionRange, getSemverRange(aCase.supported))
126125
}
127126

128-
const syntaxNames = /** @type {(keyof FEATURES)[]} */ (Object.keys(
129-
FEATURES
130-
))
131-
132127
/** @type {TemplateListener} */
133128
let templateBodyVisitor = {}
134129
/** @type {RuleListener} */
135130
let scriptVisitor = {}
136131

137-
for (const syntaxName of syntaxNames) {
132+
for (const syntaxName of SYNTAX_NAMES) {
138133
/** @type {SyntaxRule} */
139134
const syntax = FEATURES[syntaxName]
140135
if (ignores.includes(syntaxName) || !isNotSupportingVersion(syntax)) {

lib/rules/syntaxes/dynamic-directive-arguments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict'
66
module.exports = {
7-
supported: '2.6.0',
7+
supported: '>=2.6.0',
88
/** @param {RuleContext} context @returns {TemplateListener} */
99
createTemplateBodyVisitor(context) {
1010
/**

lib/rules/syntaxes/scope-attribute.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict'
66
module.exports = {
77
deprecated: '2.5.0',
8+
supported: '<3.0.0',
89
/** @param {RuleContext} context @returns {TemplateListener} */
910
createTemplateBodyVisitor(context) {
1011
/**

lib/rules/syntaxes/slot-attribute.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict'
66
module.exports = {
77
deprecated: '2.6.0',
8+
supported: '<3.0.0',
89
/** @param {RuleContext} context @returns {TemplateListener} */
910
createTemplateBodyVisitor(context) {
1011
const sourceCode = context.getSourceCode()

lib/rules/syntaxes/slot-scope-attribute.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'use strict'
66
module.exports = {
77
deprecated: '2.6.0',
8-
supported: '2.5.0',
8+
supported: '>=2.5.0 <3.0.0',
99
/**
1010
* @param {RuleContext} context
1111
* @param {object} option

lib/rules/syntaxes/v-bind-prop-modifier-shorthand.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
* See LICENSE file in root directory for full license.
44
*/
55
'use strict'
6-
const semver = require('semver')
7-
const unsupported = new semver.Range('<=2.5 || >=2.6.0')
86

97
module.exports = {
10-
// >=2.6.0-beta.1 <=2.6.0-beta.3
11-
/** @param {semver.Range} versionRange */
12-
supported: (versionRange) => {
13-
return !versionRange.intersects(unsupported)
14-
},
8+
supported: '>=2.6.0-beta.1 <=2.6.0-beta.3',
159
/** @param {RuleContext} context @returns {TemplateListener} */
1610
createTemplateBodyVisitor(context) {
1711
/**

lib/rules/syntaxes/v-is.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict'
66
module.exports = {
7-
supported: '3.0.0',
7+
supported: '>=3.0.0',
88
/** @param {RuleContext} context @returns {TemplateListener} */
99
createTemplateBodyVisitor(context) {
1010
/**

lib/rules/syntaxes/v-model-argument.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'use strict'
66

77
module.exports = {
8-
supported: '3.0.0',
8+
supported: '>=3.0.0',
99
/** @param {RuleContext} context @returns {TemplateListener} */
1010
createTemplateBodyVisitor(context) {
1111
return {

lib/rules/syntaxes/v-model-custom-modifiers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
const BUILTIN_MODIFIERS = new Set(['lazy', 'number', 'trim'])
1212

1313
module.exports = {
14-
supported: '3.0.0',
14+
supported: '>=3.0.0',
1515
/** @param {RuleContext} context @returns {TemplateListener} */
1616
createTemplateBodyVisitor(context) {
1717
return {

lib/rules/syntaxes/v-slot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
'use strict'
66
module.exports = {
7-
supported: '2.6.0',
7+
supported: '>=2.6.0',
88
/** @param {RuleContext} context @returns {TemplateListener} */
99
createTemplateBodyVisitor(context) {
1010
const sourceCode = context.getSourceCode()

tests/lib/rules/no-unsupported-features/dynamic-directive-arguments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ tester.run('no-unsupported-features/dynamic-directive-arguments', rule, {
5454
<template>
5555
<a :[href]="'/xxx'" />
5656
</template>`,
57-
options: buildOptions({ version: '2.6.0-beta.2' })
57+
options: buildOptions({ version: '^3.0.0' })
5858
}
5959
],
6060
invalid: [

tests/lib/rules/no-unsupported-features/slot-scope-attribute.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ tester.run('no-unsupported-features/slot-scope-attribute', rule, {
7070
output: null,
7171
errors: [
7272
{
73-
message: '`slot-scope` are not supported until Vue.js "2.5.0".',
73+
message:
74+
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
7475
line: 4
7576
}
7677
]
@@ -86,7 +87,25 @@ tester.run('no-unsupported-features/slot-scope-attribute', rule, {
8687
output: null,
8788
errors: [
8889
{
89-
message: '`slot-scope` are not supported until Vue.js "2.5.0".',
90+
message:
91+
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
92+
line: 4
93+
}
94+
]
95+
},
96+
{
97+
code: `
98+
<template>
99+
<LinkList>
100+
<a slot-scope />
101+
</LinkList>
102+
</template>`,
103+
options: buildOptions({ version: '^3.0.0' }),
104+
output: null,
105+
errors: [
106+
{
107+
message:
108+
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
90109
line: 4
91110
}
92111
]

tests/lib/rules/no-unsupported-features/v-slot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ tester.run('no-unsupported-features/v-slot', rule, {
7070
<template v-slot:name ><a /></template>
7171
</LinkList>
7272
</template>`,
73-
options: buildOptions({ version: '2.6.0-beta.2' })
73+
options: buildOptions({ version: '^3.0.0' })
7474
}
7575
],
7676
invalid: [

0 commit comments

Comments
 (0)