Skip to content

Commit 2852ce1

Browse files
committed
Add some more documentation.
1 parent 8086b92 commit 2852ce1

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/rules/img-uses-alt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const errorMessage = 'img elements must have an alt tag.';
1515
module.exports = context => ({
1616
JSXOpeningElement: node => {
1717
const type = node.name.name;
18+
// Only check img tags.
1819
if (type !== 'img') {
1920
return;
2021
}

src/util/getAttributeValue.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
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+
*/
311
const getAttributeValue = attribute => {
412
if (attribute.value === null) {
513
return null;

src/util/hasAttribute.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
import 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+
*/
513
const hasAttribute = (attributes, attribute) => {
614
let value = false;
715

src/util/isHiddenFromScreenReader.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
import 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+
*/
511
const isHiddenFromScreenReader = attributes => {
612
const hasAriaHidden = hasAttribute(attributes, 'aria-hidden');
713
return hasAriaHidden && (hasAriaHidden === true || hasAriaHidden === null);

src/util/isInteractiveElement.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
*/
2127
const isInteractiveElement = (tagName, attributes) => {
2228
if (interactiveMap.hasOwnProperty(tagName) === false) {
2329
return false;

0 commit comments

Comments
 (0)