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

style(lib/rules): var -> const & let #4493

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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 lib/rules/data-table-large-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isDataTable, toArray } from '../commons/table';

function dataTableLargeMatches(node) {
if (isDataTable(node)) {
var tableArray = toArray(node);
const tableArray = toArray(node);
return (
tableArray.length >= 3 &&
tableArray[0].length >= 3 &&
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/frame-title-has-text-matches.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sanitize } from '../commons/text';

function frameTitleHasTextMatches(node) {
var title = node.getAttribute('title');
const title = node.getAttribute('title');
return !!sanitize(title);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/label-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function labelMatches(node, virtualNode) {
return true;
}

var type = virtualNode.attr('type').toLowerCase();
const type = virtualNode.attr('type').toLowerCase();
return (
['hidden', 'image', 'button', 'submit', 'reset'].includes(type) === false
);
Expand Down
21 changes: 21 additions & 0 deletions lib/rules/landmark-unique-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { isVisibleToScreenReaders } from '../commons/dom';
import { closest } from '../core/utils';
import { getRole } from '../commons/aria';
import { getAriaRolesByType } from '../commons/standards';
import { accessibleTextVirtual } from '../commons/text';

/*
* Since this is a best-practice rule, we are filtering elements as dictated by ARIA 1.1 Practices regardless of treatment by browser/AT combinations.
*
* Info: https://www.w3.org/TR/wai-aria-practices-1.1/#aria_landmark
*/
const excludedParentsForHeaderFooterLandmarks = [
'article',
'aside',
'main',
'nav',
'section'
].join(',');
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved

export default function landmarkUniqueMatches(node, virtualNode) {
return (
isLandmarkVirtual(virtualNode) && isVisibleToScreenReaders(virtualNode)
Expand All @@ -17,6 +31,9 @@ function isLandmarkVirtual(vNode) {
}

const { nodeName } = vNode.props;
if (nodeName === 'header' || nodeName === 'footer') {
return isHeaderFooterLandmark(vNode);
}

if (nodeName === 'section' || nodeName === 'form') {
const accessibleText = accessibleTextVirtual(vNode);
Expand All @@ -25,3 +42,7 @@ function isLandmarkVirtual(vNode) {

return landmarkRoles.indexOf(role) >= 0 || role === 'region';
}

function isHeaderFooterLandmark(headerFooterElement) {
return !closest(headerFooterElement, excludedParentsForHeaderFooterLandmarks);
}
4 changes: 2 additions & 2 deletions lib/rules/link-in-text-block-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { sanitize } from '../commons/text';
import { isVisibleOnScreen, isInTextBlock } from '../commons/dom';

function linkInTextBlockMatches(node) {
var text = sanitize(node.innerText);
var role = node.getAttribute('role');
const text = sanitize(node.innerText);
const role = node.getAttribute('role');

if (role && role !== 'link') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/scrollable-region-focusable-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { querySelectorAll, getScroll } from '../core/utils';
export default function scrollableRegionFocusableMatches(node, virtualNode) {
return (
// The element scrolls
// And there's something actually worth scrolling to
getScroll(node, 13) !== undefined &&
// It's not a combobox popup, which commonly has keyboard focus added
isComboboxPopup(virtualNode) === false &&
// And there's something actually worth scrolling to
isNoneEmptyElement(virtualNode)
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/svg-namespace-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function svgNamespaceMatches(node, virtualNode) {

// element is svg namespace if its parent is an svg element
return !!closest(virtualNode, 'svg');
} catch {
} catch (e) {
console.debug(e);
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
}
Expand Down
Loading