@@ -23,38 +23,6 @@ function getPropertyFromObject(propertyName, node) {
2323 return null
2424}
2525
26- /**
27- * Extracts the `meta` property from the ObjectExpression that all rules export.
28- *
29- * @param {ASTNode } exportsNode ObjectExpression node that the rule exports.
30- * @returns {ASTNode } The `meta` Property node or null if not found.
31- */
32- function getMetaPropertyFromExportsNode ( exportsNode ) {
33- return getPropertyFromObject ( 'meta' , exportsNode )
34- }
35-
36- /**
37- * Whether this `meta` ObjectExpression has a `docs` property defined or not.
38- *
39- * @param {ASTNode } metaPropertyNode The `meta` ObjectExpression for this rule.
40- * @returns {boolean } `true` if a `docs` property exists.
41- */
42- function hasMetaDocs ( metaPropertyNode ) {
43- return Boolean ( getPropertyFromObject ( 'docs' , metaPropertyNode . value ) )
44- }
45-
46- /**
47- * Whether this `meta` ObjectExpression has a `docs.category` property defined or not.
48- *
49- * @param {ASTNode } metaPropertyNode The `meta` ObjectExpression for this rule.
50- * @returns {boolean } `true` if a `docs.category` property exists.
51- */
52- function hasMetaDocsCategories ( metaPropertyNode ) {
53- const metaDocs = getPropertyFromObject ( 'docs' , metaPropertyNode . value )
54-
55- return metaDocs && getPropertyFromObject ( 'categories' , metaDocs . value )
56- }
57-
5826/**
5927 * Checks the validity of the meta definition of this rule and reports any errors found.
6028 *
@@ -64,8 +32,7 @@ function hasMetaDocsCategories(metaPropertyNode) {
6432 * @returns {void }
6533 */
6634function checkMetaValidity ( context , exportsNode ) {
67- const metaProperty = getMetaPropertyFromExportsNode ( exportsNode )
68-
35+ const metaProperty = getPropertyFromObject ( 'meta' , exportsNode )
6936 if ( ! metaProperty ) {
7037 context . report ( {
7138 node : exportsNode ,
@@ -74,21 +41,35 @@ function checkMetaValidity(context, exportsNode) {
7441 return
7542 }
7643
77- if ( ! hasMetaDocs ( metaProperty ) ) {
44+ const metaDocs = getPropertyFromObject ( 'docs' , metaProperty . value )
45+ if ( ! metaDocs ) {
7846 context . report ( {
79- node : 'metaDocs' ,
47+ node : metaProperty ,
8048 messageId : 'missingMetaDocs'
8149 } )
8250 return
8351 }
8452
85- if ( ! hasMetaDocsCategories ( metaProperty ) ) {
53+ const metaDocsCategories = getPropertyFromObject ( 'categories' , metaDocs . value )
54+ if ( ! metaDocsCategories ) {
8655 context . report ( {
87- node : metaProperty ,
56+ node : metaDocs ,
8857 messageId : 'missingMetaDocsCategories'
8958 } )
9059 return
9160 }
61+
62+ const metaDocsRecommended = getPropertyFromObject (
63+ 'recommended' ,
64+ metaDocs . value
65+ )
66+ if ( metaDocsRecommended ) {
67+ context . report ( {
68+ node : metaDocsRecommended ,
69+ messageId : 'invalidMetaDocsRecommended'
70+ } )
71+ return
72+ }
9273}
9374
9475module . exports = {
@@ -103,7 +84,9 @@ module.exports = {
10384 missingMeta : 'Rule is missing a meta property.' ,
10485 missingMetaDocs : 'Rule is missing a meta.docs property.' ,
10586 missingMetaDocsCategories :
106- 'Rule is missing a meta.docs.categories property.'
87+ 'Rule is missing a meta.docs.categories property.' ,
88+ invalidMetaDocsRecommended :
89+ 'Rule should not have a meta.docs.recommended property.'
10790 }
10891 } ,
10992
0 commit comments