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.';
1515module . exports = context => ( {
1616 JSXOpeningElement : node => {
1717 const type = node . name . name ;
18+ // Only check img tags.
1819 if ( type !== 'img' ) {
1920 return ;
2021 }
Original file line number Diff line number Diff line change 11'use strict' ;
22
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+ */
311const getAttributeValue = attribute => {
412 if ( attribute . value === null ) {
513 return null ;
Original file line number Diff line number Diff line change 22
33import getAttributeValue from './getAttributeValue' ;
44
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+ */
513const hasAttribute = ( attributes , attribute ) => {
614 let value = false ;
715
Original file line number Diff line number Diff line change 22
33import hasAttribute from './hasAttribute' ;
44
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+ */
511const isHiddenFromScreenReader = attributes => {
612 const hasAriaHidden = hasAttribute ( attributes , 'aria-hidden' ) ;
713 return hasAriaHidden && ( hasAriaHidden === true || hasAriaHidden === null ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ const interactiveMap = {
1818 textarea : ( ) => true
1919} ;
2020
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+ */
2127const isInteractiveElement = ( tagName , attributes ) => {
2228 if ( interactiveMap . hasOwnProperty ( tagName ) === false ) {
2329 return false ;
You can’t perform that action at this time.
0 commit comments