@@ -4,21 +4,21 @@ const {getJSXOpeningElementAttribute} = require('../utils/get-jsx-opening-elemen
4
4
5
5
const validHeadings = [ 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ] ;
6
6
7
- const isHeading = elem => getJSXOpeningElementName ( elem ) === 'Heading'
8
- const isUsingAs = elem => {
9
- const asUsage = getJSXOpeningElementAttribute ( elem , 'as' ) ;
7
+ const isHeadingComponent = elem => getJSXOpeningElementName ( elem ) === 'Heading'
8
+ const isUsingAsProp = elem => {
9
+ const componentAs = getJSXOpeningElementAttribute ( elem , 'as' ) ;
10
10
11
- if ( ! asUsage ) return ;
11
+ if ( ! componentAs ) return ;
12
12
13
- return asUsage . value ;
13
+ return componentAs . value ;
14
14
}
15
15
16
- const isValidAs = value => validHeadings . includes ( value . toLowerCase ( ) ) ;
16
+ const isValidAsUsage = value => validHeadings . includes ( value . toLowerCase ( ) ) ;
17
17
const isInvalid = elem => {
18
- const elemAs = isUsingAs ( elem ) ;
18
+ const elemAs = isUsingAsProp ( elem ) ;
19
19
20
20
if ( ! elemAs ) return 'nonExplicitHeadingLevel' ;
21
- if ( ! isValidAs ( elemAs . value ) ) return 'invalidAsValue' ;
21
+ if ( ! isValidAsUsage ( elemAs . value ) ) return 'invalidAsValue' ;
22
22
23
23
return false ;
24
24
}
@@ -36,15 +36,14 @@ module.exports = {
36
36
}
37
37
] ,
38
38
messages : {
39
- nonExplicitHeadingLevel : "Heading must have an explicit heading level applied through `as` prop." ,
40
- invalidAsValue : "Usage of `as` must only be used for headings (h1-h6)."
39
+ nonExplicitHeadingLevel : "Heading must have an explicit heading level applied through the `as` prop." ,
40
+ invalidAsValue : "Usage of `as` must only be used for heading elements (h1-h6)."
41
41
}
42
42
} ,
43
43
create : function ( context ) {
44
44
return {
45
- // callback functions
46
45
JSXOpeningElement ( jsxNode ) {
47
- if ( isPrimerComponent ( jsxNode . name , context . getScope ( jsxNode ) ) && isHeading ( jsxNode ) ) {
46
+ if ( isPrimerComponent ( jsxNode . name , context . getScope ( jsxNode ) ) && isHeadingComponent ( jsxNode ) ) {
48
47
const error = isInvalid ( jsxNode ) ;
49
48
50
49
if ( error ) {
0 commit comments