Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(has-text-content): add generic check has-text-content #2234

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Rules that do not necessarily conform to WCAG success criterion but are industry
| :----------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- | :----------------- | :----------------------------------------- | :------------------------- |
| [accesskeys](https://dequeuniversity.com/rules/axe/3.5/accesskeys?application=RuleDescription) | Ensures every accesskey attribute value is unique | Serious | best-practice, cat.keyboard | failure |
| [aria-allowed-role](https://dequeuniversity.com/rules/axe/3.5/aria-allowed-role?application=RuleDescription) | Ensures role attribute has an appropriate value for the element | Minor | cat.aria, best-practice | failure, needs review |
| [empty-heading](https://dequeuniversity.com/rules/axe/3.5/empty-heading?application=RuleDescription) | Ensures headings have discernible text | Minor | cat.name-role-value, best-practice | failure |
| [empty-heading](https://dequeuniversity.com/rules/axe/3.5/empty-heading?application=RuleDescription) | Ensures headings have discernible text | Serious | cat.name-role-value, best-practice | failure |
straker marked this conversation as resolved.
Show resolved Hide resolved
| [frame-tested](https://dequeuniversity.com/rules/axe/3.5/frame-tested?application=RuleDescription) | Ensures <iframe> and <frame> elements contain the axe-core script | Critical | cat.structure, review-item, best-practice | failure, needs review |
| [frame-title-unique](https://dequeuniversity.com/rules/axe/3.5/frame-title-unique?application=RuleDescription) | Ensures <iframe> and <frame> elements contain a unique title attribute | Serious | cat.text-alternatives, best-practice | failure |
| [heading-order](https://dequeuniversity.com/rules/axe/3.5/heading-order?application=RuleDescription) | Ensures the order of headings is semantically correct | Moderate | cat.semantics, best-practice | failure |
Expand Down
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
7 changes: 0 additions & 7 deletions lib/checks/shared/has-visible-text-evaluate.js

This file was deleted.

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
6 changes: 2 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 pageNoDuplicateAfter from '../../checks/generic/page-no-duplicate-after';
import pageNoDuplicateEvaluate from '../../checks/generic/page-no-duplicate-evaluate';

Expand All @@ -62,11 +63,9 @@ 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 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 roleNoneEvaluate from '../../checks/shared/role-none-evaluate';
Expand Down Expand Up @@ -205,6 +204,7 @@ const metadataFunctionMap = {
'attr-non-space-content-evaluate': attrNonSpaceContentEvaluate,
'has-descendant-after': hasDescendantAfter,
'has-descendant-evaluate': hasDescendantEvaluate,
'has-text-content-evaluate': hasTextContentEvaluate,
'page-no-duplicate-after': pageNoDuplicateAfter,
'page-no-duplicate-evaluate': pageNoDuplicateEvaluate,

Expand All @@ -225,11 +225,9 @@ 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-alt-evaluate': hasAltEvaluate,
'has-visible-text-evaluate': hasVisibleTextEvaluate,
'is-on-screen-evaluate': isOnScreenEvaluate,
'non-empty-if-present-evaluate': nonEmptyIfPresentEvaluate,
'role-none-evaluate': roleNoneEvaluate,
Expand Down
7 changes: 6 additions & 1 deletion lib/rules/empty-heading.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"help": "Headings must not be empty"
},
"all": [],
"any": ["has-visible-text"],
straker marked this conversation as resolved.
Show resolved Hide resolved
"any": [
"has-visible-text",
"aria-label",
"aria-labelledby",
"non-empty-title"
],
"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