File tree Expand file tree Collapse file tree 5 files changed +29
-0
lines changed Expand file tree Collapse file tree 5 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const errorMessage = 'img elements must have an alt tag.';
15
15
module . exports = context => ( {
16
16
JSXOpeningElement : node => {
17
17
const type = node . name . name ;
18
+ // Only check img tags.
18
19
if ( type !== 'img' ) {
19
20
return ;
20
21
}
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ /**
4
+ * Returns the value of a given attribute.
5
+ * Different types of attributes have their associated
6
+ * values in different properties on the object.
7
+ *
8
+ * This function should return the most *closely* associated
9
+ * value with the intention of the JSX.
10
+ */
3
11
const getAttributeValue = attribute => {
4
12
if ( attribute . value === null ) {
5
13
return null ;
Original file line number Diff line number Diff line change 2
2
3
3
import getAttributeValue from './getAttributeValue' ;
4
4
5
+ /**
6
+ * Returns the value of the attribute or false, indicating the attribute
7
+ * is not present on the JSX opening element. This skips over spread attributes
8
+ * as the purpose of this linter is to do hard checks of explicit JSX props.
9
+ *
10
+ * This treats undefined values as missing props, as they will not be used for
11
+ * rendering on elements that live closest to the DOM (pure html JSX elements).
12
+ */
5
13
const hasAttribute = ( attributes , attribute ) => {
6
14
let value = false ;
7
15
Original file line number Diff line number Diff line change 2
2
3
3
import hasAttribute from './hasAttribute' ;
4
4
5
+ /**
6
+ * Returns boolean indicating that the aria-hidden prop
7
+ * is present or the value is true.
8
+ *
9
+ * <div aria-hidden /> is equivalent to the DOM as <div aria-hidden=true />.
10
+ */
5
11
const isHiddenFromScreenReader = attributes => {
6
12
const hasAriaHidden = hasAttribute ( attributes , 'aria-hidden' ) ;
7
13
return hasAriaHidden && ( hasAriaHidden === true || hasAriaHidden === null ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ const interactiveMap = {
18
18
textarea : ( ) => true
19
19
} ;
20
20
21
+ /**
22
+ * Returns boolean indicating whether the given element is
23
+ * interactive on the DOM or not. Usually used when an element
24
+ * has a dynamic handler on it and we need to discern whether or not
25
+ * it's intention is to be interacted with on the DOM.
26
+ */
21
27
const isInteractiveElement = ( tagName , attributes ) => {
22
28
if ( interactiveMap . hasOwnProperty ( tagName ) === false ) {
23
29
return false ;
You can’t perform that action at this time.
0 commit comments