Skip to content

Commit

Permalink
feat(has-text-content): add generic check has-text-content (#2234)
Browse files Browse the repository at this point in the history
* feat(has-text-content): add generic check has-text-content

* make empty-heading minor
  • Loading branch information
straker committed Jun 5, 2020
1 parent 8b14ccc commit 60ddc65
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
7 changes: 7 additions & 0 deletions lib/checks/generic/has-text-content-evaluate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sanitize, subtreeText } from '../../commons/text';

function hasTextContentEvaluate(node, options, virtualNode) {
return sanitize(subtreeText(virtualNode)) !== '';
}

export default hasTextContentEvaluate;
18 changes: 0 additions & 18 deletions lib/checks/shared/button-has-visible-text-evaluate.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/checks/shared/button-has-visible-text.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "button-has-visible-text",
"evaluate": "button-has-visible-text-evaluate",
"evaluate": "has-text-content-evaluate",
"metadata": {
"impact": "critical",
"messages": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { accessibleTextVirtual } from '../../commons/text';

function hasVisibleTextEvaluate(node, options, virtualNode) {
function hasAccessibleTextEvaluate(node, options, virtualNode) {
return accessibleTextVirtual(virtualNode).length > 0;
}

export default hasVisibleTextEvaluate;
export default hasAccessibleTextEvaluate;
11 changes: 11 additions & 0 deletions lib/checks/shared/has-accessible-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "has-accessible-text",
"evaluate": "has-accessible-text-evaluate",
"metadata": {
"impact": "minor",
"messages": {
"pass": "Element has text that is visible to screen readers",
"fail": "Element does not have text that is visible to screen readers"
}
}
}
2 changes: 1 addition & 1 deletion lib/checks/shared/has-visible-text.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "has-visible-text",
"evaluate": "has-visible-text-evaluate",
"evaluate": "has-text-content-evaluate",
"metadata": {
"impact": "minor",
"messages": {
Expand Down
8 changes: 4 additions & 4 deletions lib/core/base/metadata-function-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import autocompleteValidEvaluate from '../../checks/forms/autocomplete-valid-eva
import attrNonSpaceContentEvaluate from '../../checks/generic/attr-non-space-content-evaluate';
import hasDescendantAfter from '../../checks/generic/has-descendant-after';
import hasDescendantEvaluate from '../../checks/generic/has-descendant-evaluate';
import hasTextContentEvaluate from '../../checks/generic/has-text-content-evaluate';
import matchesDefinitionEvaluate from '../../checks/generic/matches-definition-evaluate';
import pageNoDuplicateAfter from '../../checks/generic/page-no-duplicate-after';
import pageNoDuplicateEvaluate from '../../checks/generic/page-no-duplicate-evaluate';
Expand All @@ -63,11 +64,10 @@ import uniqueFrameTitleEvaluate from '../../checks/navigation/unique-frame-title
import ariaLabelEvaluate from '../../checks/shared/aria-label-evaluate';
import ariaLabelledbyEvaluate from '../../checks/shared/aria-labelledby-evaluate';
import avoidInlineSpacingEvaluate from '../../checks/shared/avoid-inline-spacing-evaluate';
import buttonHasVisibleTextEvaluate from '../../checks/shared/button-has-visible-text-evaluate';
import docHasTitleEvaluate from '../../checks/shared/doc-has-title-evaluate';
import existsEvaluate from '../../checks/shared/exists-evaluate';
import hasAccessibleTextEvaluate from '../../checks/shared/has-accessible-text-evaluate';
import hasAltEvaluate from '../../checks/shared/has-alt-evaluate';
import hasVisibleTextEvaluate from '../../checks/shared/has-visible-text-evaluate';
import isOnScreenEvaluate from '../../checks/shared/is-on-screen-evaluate';
import nonEmptyIfPresentEvaluate from '../../checks/shared/non-empty-if-present-evaluate';
import svgNonEmptyTitleEvaluate from '../../checks/shared/svg-non-empty-title-evaluate';
Expand Down Expand Up @@ -204,6 +204,7 @@ const metadataFunctionMap = {
'attr-non-space-content-evaluate': attrNonSpaceContentEvaluate,
'has-descendant-after': hasDescendantAfter,
'has-descendant-evaluate': hasDescendantEvaluate,
'has-text-content-evaluate': hasTextContentEvaluate,
'matches-definition-evaluate': matchesDefinitionEvaluate,
'page-no-duplicate-after': pageNoDuplicateAfter,
'page-no-duplicate-evaluate': pageNoDuplicateEvaluate,
Expand All @@ -225,11 +226,10 @@ const metadataFunctionMap = {
'aria-label-evaluate': ariaLabelEvaluate,
'aria-labelledby-evaluate': ariaLabelledbyEvaluate,
'avoid-inline-spacing-evaluate': avoidInlineSpacingEvaluate,
'button-has-visible-text-evaluate': buttonHasVisibleTextEvaluate,
'doc-has-title-evaluate': docHasTitleEvaluate,
'exists-evaluate': existsEvaluate,
'has-accessible-text-evaluate': hasAccessibleTextEvaluate,
'has-alt-evaluate': hasAltEvaluate,
'has-visible-text-evaluate': hasVisibleTextEvaluate,
'is-on-screen-evaluate': isOnScreenEvaluate,
'non-empty-if-present-evaluate': nonEmptyIfPresentEvaluate,
'svg-non-empty-title-evaluate': svgNonEmptyTitleEvaluate,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/empty-heading.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"help": "Headings must not be empty"
},
"all": [],
"any": ["has-visible-text"],
"any": ["has-accessible-text"],
"none": []
}
2 changes: 0 additions & 2 deletions test/checks/shared/button-has-visible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('button-has-visible-text', function() {
.getCheckEvaluate('button-has-visible-text')
.apply(checkContext, checkArgs)
);
assert.deepEqual(checkContext._data, 'Name');
});

it('should return true if ARIA button has text', function() {
Expand All @@ -42,7 +41,6 @@ describe('button-has-visible-text', function() {
.getCheckEvaluate('button-has-visible-text')
.apply(checkContext, checkArgs)
);
assert.deepEqual(checkContext._data, 'Text');
});

it('should return false if ARIA button has no text', function() {
Expand Down

0 comments on commit 60ddc65

Please sign in to comment.