From 6ab7da6ceff98e49f4fe69f9ed0fb61cc4f218b3 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 13 Dec 2024 16:11:05 +0100 Subject: [PATCH 1/4] Simplify `no-invalid-meta` internal rule --- eslint-internal-rules/no-invalid-meta.js | 43 ++++-------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/eslint-internal-rules/no-invalid-meta.js b/eslint-internal-rules/no-invalid-meta.js index 5969e5c5a..6484e8c69 100644 --- a/eslint-internal-rules/no-invalid-meta.js +++ b/eslint-internal-rules/no-invalid-meta.js @@ -23,38 +23,6 @@ function getPropertyFromObject(propertyName, node) { return null } -/** - * Extracts the `meta` property from the ObjectExpression that all rules export. - * - * @param {ASTNode} exportsNode ObjectExpression node that the rule exports. - * @returns {ASTNode} The `meta` Property node or null if not found. - */ -function getMetaPropertyFromExportsNode(exportsNode) { - return getPropertyFromObject('meta', exportsNode) -} - -/** - * Whether this `meta` ObjectExpression has a `docs` property defined or not. - * - * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule. - * @returns {boolean} `true` if a `docs` property exists. - */ -function hasMetaDocs(metaPropertyNode) { - return Boolean(getPropertyFromObject('docs', metaPropertyNode.value)) -} - -/** - * Whether this `meta` ObjectExpression has a `docs.category` property defined or not. - * - * @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule. - * @returns {boolean} `true` if a `docs.category` property exists. - */ -function hasMetaDocsCategories(metaPropertyNode) { - const metaDocs = getPropertyFromObject('docs', metaPropertyNode.value) - - return metaDocs && getPropertyFromObject('categories', metaDocs.value) -} - /** * Checks the validity of the meta definition of this rule and reports any errors found. * @@ -64,8 +32,7 @@ function hasMetaDocsCategories(metaPropertyNode) { * @returns {void} */ function checkMetaValidity(context, exportsNode) { - const metaProperty = getMetaPropertyFromExportsNode(exportsNode) - + const metaProperty = getPropertyFromObject('meta', exportsNode) if (!metaProperty) { context.report({ node: exportsNode, @@ -74,15 +41,17 @@ function checkMetaValidity(context, exportsNode) { return } - if (!hasMetaDocs(metaProperty)) { + const metaDocs = getPropertyFromObject('docs', metaProperty.value) + if (!metaDocs) { context.report({ - node: 'metaDocs', + node: metaProperty, messageId: 'missingMetaDocs' }) return } - if (!hasMetaDocsCategories(metaProperty)) { + const metaDocsCategories = getPropertyFromObject('categories', metaDocs.value) + if (!metaDocsCategories) { context.report({ node: metaProperty, messageId: 'missingMetaDocsCategories' From 9be8f18f968f1a67c04ccede5511b8a4bfe0c354 Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 13 Dec 2024 16:12:40 +0100 Subject: [PATCH 2/4] Improve report location for `no-invalid-meta` internal rule --- eslint-internal-rules/no-invalid-meta.js | 2 +- lib/rules/no-ref-object-destructure.js | 4 ++-- lib/rules/no-setup-props-destructure.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eslint-internal-rules/no-invalid-meta.js b/eslint-internal-rules/no-invalid-meta.js index 6484e8c69..251493318 100644 --- a/eslint-internal-rules/no-invalid-meta.js +++ b/eslint-internal-rules/no-invalid-meta.js @@ -53,7 +53,7 @@ function checkMetaValidity(context, exportsNode) { const metaDocsCategories = getPropertyFromObject('categories', metaDocs.value) if (!metaDocsCategories) { context.report({ - node: metaProperty, + node: metaDocs, messageId: 'missingMetaDocsCategories' }) return diff --git a/lib/rules/no-ref-object-destructure.js b/lib/rules/no-ref-object-destructure.js index 221c20b3d..ae9c8ccbf 100644 --- a/lib/rules/no-ref-object-destructure.js +++ b/lib/rules/no-ref-object-destructure.js @@ -6,10 +6,10 @@ const baseRule = require('./no-ref-object-reactivity-loss') module.exports = { - // eslint-disable-next-line eslint-plugin/require-meta-schema, eslint-plugin/prefer-message-ids, internal/no-invalid-meta, eslint-plugin/require-meta-type -- inherit schema from base rule + // eslint-disable-next-line eslint-plugin/require-meta-schema, eslint-plugin/prefer-message-ids, eslint-plugin/require-meta-type -- inherit schema from base rule meta: { ...baseRule.meta, - // eslint-disable-next-line eslint-plugin/require-meta-docs-description, internal/no-invalid-meta-docs-categories, eslint-plugin/meta-property-ordering + // eslint-disable-next-line eslint-plugin/require-meta-docs-description, internal/no-invalid-meta, internal/no-invalid-meta-docs-categories, eslint-plugin/meta-property-ordering docs: { ...baseRule.meta.docs, url: 'https://eslint.vuejs.org/rules/no-ref-object-destructure.html' diff --git a/lib/rules/no-setup-props-destructure.js b/lib/rules/no-setup-props-destructure.js index 7b49b0a45..882bdc952 100644 --- a/lib/rules/no-setup-props-destructure.js +++ b/lib/rules/no-setup-props-destructure.js @@ -6,10 +6,10 @@ const baseRule = require('./no-setup-props-reactivity-loss') module.exports = { - // eslint-disable-next-line eslint-plugin/require-meta-schema, eslint-plugin/prefer-message-ids, internal/no-invalid-meta, eslint-plugin/require-meta-type -- inherit schema from base rule + // eslint-disable-next-line eslint-plugin/require-meta-schema, eslint-plugin/prefer-message-ids, eslint-plugin/require-meta-type -- inherit schema from base rule meta: { ...baseRule.meta, - // eslint-disable-next-line eslint-plugin/require-meta-docs-description, internal/no-invalid-meta-docs-categories, eslint-plugin/meta-property-ordering + // eslint-disable-next-line eslint-plugin/require-meta-docs-description, internal/no-invalid-meta, internal/no-invalid-meta-docs-categories, eslint-plugin/meta-property-ordering docs: { ...baseRule.meta.docs, url: 'https://eslint.vuejs.org/rules/no-setup-props-destructure.html' From 69b75233007c8cb808d57fd27165874dc3a4d94d Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 13 Dec 2024 16:12:50 +0100 Subject: [PATCH 3/4] Also check for invalid `meta.docs.recommended` properties in `no-invalid-meta` internal rule --- eslint-internal-rules/no-invalid-meta.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/eslint-internal-rules/no-invalid-meta.js b/eslint-internal-rules/no-invalid-meta.js index 251493318..941cf2a39 100644 --- a/eslint-internal-rules/no-invalid-meta.js +++ b/eslint-internal-rules/no-invalid-meta.js @@ -58,6 +58,18 @@ function checkMetaValidity(context, exportsNode) { }) return } + + const metaDocsRecommended = getPropertyFromObject( + 'recommended', + metaDocs.value + ) + if (metaDocsRecommended) { + context.report({ + node: metaDocsRecommended, + messageId: 'invalidMetaDocsRecommended' + }) + return + } } module.exports = { @@ -72,7 +84,9 @@ module.exports = { missingMeta: 'Rule is missing a meta property.', missingMetaDocs: 'Rule is missing a meta.docs property.', missingMetaDocsCategories: - 'Rule is missing a meta.docs.categories property.' + 'Rule is missing a meta.docs.categories property.', + invalidMetaDocsRecommended: + 'Rule should not have a meta.docs.recommended property.' } }, From 110a8e0f97da0449c8fb33ec750b9b181c8f385d Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 13 Dec 2024 16:13:18 +0100 Subject: [PATCH 4/4] Remove invalid `meta.docs.recommended` properties from rules --- lib/rules/no-duplicate-attr-inheritance.js | 1 - lib/rules/no-potential-component-option-typo.js | 1 - lib/rules/require-typed-object-prop.js | 1 - lib/rules/sort-keys.js | 1 - lib/rules/v-for-delimiter-style.js | 1 - lib/rules/v-if-else-key.js | 1 - 6 files changed, 6 deletions(-) diff --git a/lib/rules/no-duplicate-attr-inheritance.js b/lib/rules/no-duplicate-attr-inheritance.js index ba20a52e5..1f0fb0fd3 100644 --- a/lib/rules/no-duplicate-attr-inheritance.js +++ b/lib/rules/no-duplicate-attr-inheritance.js @@ -40,7 +40,6 @@ module.exports = { description: 'enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"`', categories: undefined, - recommended: false, url: 'https://eslint.vuejs.org/rules/no-duplicate-attr-inheritance.html' }, fixable: null, diff --git a/lib/rules/no-potential-component-option-typo.js b/lib/rules/no-potential-component-option-typo.js index 50c710802..4f1b02775 100644 --- a/lib/rules/no-potential-component-option-typo.js +++ b/lib/rules/no-potential-component-option-typo.js @@ -12,7 +12,6 @@ module.exports = { docs: { description: 'disallow a potential typo in your component property', categories: undefined, - recommended: false, url: 'https://eslint.vuejs.org/rules/no-potential-component-option-typo.html' }, fixable: null, diff --git a/lib/rules/require-typed-object-prop.js b/lib/rules/require-typed-object-prop.js index eb7a278ae..b88e17537 100644 --- a/lib/rules/require-typed-object-prop.js +++ b/lib/rules/require-typed-object-prop.js @@ -116,7 +116,6 @@ module.exports = { docs: { description: 'enforce adding type declarations to object props', categories: undefined, - recommended: false, url: 'https://eslint.vuejs.org/rules/require-typed-object-prop.html' }, fixable: null, diff --git a/lib/rules/sort-keys.js b/lib/rules/sort-keys.js index 38d758e91..9598adf0b 100644 --- a/lib/rules/sort-keys.js +++ b/lib/rules/sort-keys.js @@ -71,7 +71,6 @@ module.exports = { description: 'enforce sort-keys in a manner that is compatible with order-in-components', categories: null, - recommended: false, url: 'https://eslint.vuejs.org/rules/sort-keys.html' }, fixable: null, diff --git a/lib/rules/v-for-delimiter-style.js b/lib/rules/v-for-delimiter-style.js index f59a43826..2b20cfd0a 100644 --- a/lib/rules/v-for-delimiter-style.js +++ b/lib/rules/v-for-delimiter-style.js @@ -14,7 +14,6 @@ module.exports = { docs: { description: "enforce `v-for` directive's delimiter style", categories: undefined, - recommended: false, url: 'https://eslint.vuejs.org/rules/v-for-delimiter-style.html' }, fixable: 'code', diff --git a/lib/rules/v-if-else-key.js b/lib/rules/v-if-else-key.js index a83d436b8..d8e913670 100644 --- a/lib/rules/v-if-else-key.js +++ b/lib/rules/v-if-else-key.js @@ -127,7 +127,6 @@ module.exports = { description: 'require key attribute for conditionally rendered repeated components', categories: null, - recommended: false, url: 'https://eslint.vuejs.org/rules/v-if-else-key.html' }, // eslint-disable-next-line eslint-plugin/require-meta-fixable -- fixer is not recognized