Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false negatives of "slot-scope" when "^3.0.0" is set in vue/no-unsupported-features rule. #1258

Merged
merged 1 commit into from Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 7 additions & 12 deletions lib/rules/no-unsupported-features.js
Expand Up @@ -9,7 +9,7 @@ const utils = require('../utils')

/**
* @typedef {object} SyntaxRule
* @property {string | ((range: semver.Range) => boolean)} supported
* @property {string} supported
* @property { (context: RuleContext) => TemplateListener } [createTemplateBodyVisitor]
* @property { (context: RuleContext) => RuleListener } [createScriptVisitor]
*/
Expand All @@ -28,6 +28,8 @@ const FEATURES = {
'v-is': require('./syntaxes/v-is')
}

const SYNTAX_NAMES = /** @type {(keyof FEATURES)[]} */ (Object.keys(FEATURES))

const cache = new Map()
/**
* Get the `semver.Range` object of a given range text.
Expand Down Expand Up @@ -71,7 +73,7 @@ module.exports = {
ignores: {
type: 'array',
items: {
enum: Object.keys(FEATURES)
enum: SYNTAX_NAMES
},
uniqueItems: true
}
Expand All @@ -82,7 +84,7 @@ module.exports = {
messages: {
// Vue.js 2.5.0+
forbiddenSlotScopeAttribute:
'`slot-scope` are not supported until Vue.js "2.5.0".',
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
// Vue.js 2.6.0+
forbiddenDynamicDirectiveArguments:
'Dynamic arguments are not supported until Vue.js "2.6.0".',
Expand Down Expand Up @@ -119,22 +121,15 @@ module.exports = {
* @returns {boolean} `true` if it's supporting.
*/
function isNotSupportingVersion(aCase) {
if (typeof aCase.supported === 'function') {
return !aCase.supported(versionRange)
}
return versionRange.intersects(getSemverRange(`<${aCase.supported}`))
return !semver.subset(versionRange, getSemverRange(aCase.supported))
}

const syntaxNames = /** @type {(keyof FEATURES)[]} */ (Object.keys(
FEATURES
))

/** @type {TemplateListener} */
let templateBodyVisitor = {}
/** @type {RuleListener} */
let scriptVisitor = {}

for (const syntaxName of syntaxNames) {
for (const syntaxName of SYNTAX_NAMES) {
/** @type {SyntaxRule} */
const syntax = FEATURES[syntaxName]
if (ignores.includes(syntaxName) || !isNotSupportingVersion(syntax)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/dynamic-directive-arguments.js
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'
module.exports = {
supported: '2.6.0',
supported: '>=2.6.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
/**
Expand Down
1 change: 1 addition & 0 deletions lib/rules/syntaxes/scope-attribute.js
Expand Up @@ -5,6 +5,7 @@
'use strict'
module.exports = {
deprecated: '2.5.0',
supported: '<3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
/**
Expand Down
1 change: 1 addition & 0 deletions lib/rules/syntaxes/slot-attribute.js
Expand Up @@ -5,6 +5,7 @@
'use strict'
module.exports = {
deprecated: '2.6.0',
supported: '<3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
const sourceCode = context.getSourceCode()
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/slot-scope-attribute.js
Expand Up @@ -5,7 +5,7 @@
'use strict'
module.exports = {
deprecated: '2.6.0',
supported: '2.5.0',
supported: '>=2.5.0 <3.0.0',
/**
* @param {RuleContext} context
* @param {object} option
Expand Down
8 changes: 1 addition & 7 deletions lib/rules/syntaxes/v-bind-prop-modifier-shorthand.js
Expand Up @@ -3,15 +3,9 @@
* See LICENSE file in root directory for full license.
*/
'use strict'
const semver = require('semver')
const unsupported = new semver.Range('<=2.5 || >=2.6.0')

module.exports = {
// >=2.6.0-beta.1 <=2.6.0-beta.3
/** @param {semver.Range} versionRange */
supported: (versionRange) => {
return !versionRange.intersects(unsupported)
},
supported: '>=2.6.0-beta.1 <=2.6.0-beta.3',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/v-is.js
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'
module.exports = {
supported: '3.0.0',
supported: '>=3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/v-model-argument.js
Expand Up @@ -5,7 +5,7 @@
'use strict'

module.exports = {
supported: '3.0.0',
supported: '>=3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/v-model-custom-modifiers.js
Expand Up @@ -11,7 +11,7 @@
const BUILTIN_MODIFIERS = new Set(['lazy', 'number', 'trim'])

module.exports = {
supported: '3.0.0',
supported: '>=3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/syntaxes/v-slot.js
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'
module.exports = {
supported: '2.6.0',
supported: '>=2.6.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
const sourceCode = context.getSourceCode()
Expand Down
Expand Up @@ -54,7 +54,7 @@ tester.run('no-unsupported-features/dynamic-directive-arguments', rule, {
<template>
<a :[href]="'/xxx'" />
</template>`,
options: buildOptions({ version: '2.6.0-beta.2' })
options: buildOptions({ version: '^3.0.0' })
}
],
invalid: [
Expand Down
23 changes: 21 additions & 2 deletions tests/lib/rules/no-unsupported-features/slot-scope-attribute.js
Expand Up @@ -70,7 +70,8 @@ tester.run('no-unsupported-features/slot-scope-attribute', rule, {
output: null,
errors: [
{
message: '`slot-scope` are not supported until Vue.js "2.5.0".',
message:
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
line: 4
}
]
Expand All @@ -86,7 +87,25 @@ tester.run('no-unsupported-features/slot-scope-attribute', rule, {
output: null,
errors: [
{
message: '`slot-scope` are not supported until Vue.js "2.5.0".',
message:
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
line: 4
}
]
},
{
code: `
<template>
<LinkList>
<a slot-scope />
</LinkList>
</template>`,
options: buildOptions({ version: '^3.0.0' }),
output: null,
errors: [
{
message:
'`slot-scope` are not supported except Vue.js ">=2.5.0 <3.0.0".',
line: 4
}
]
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-unsupported-features/v-slot.js
Expand Up @@ -70,7 +70,7 @@ tester.run('no-unsupported-features/v-slot', rule, {
<template v-slot:name ><a /></template>
</LinkList>
</template>`,
options: buildOptions({ version: '2.6.0-beta.2' })
options: buildOptions({ version: '^3.0.0' })
}
],
invalid: [
Expand Down