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

Lines changed: 7 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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()

0 commit comments

Comments
 (0)