Skip to content

Commit

Permalink
feat(checks/label-content-name-mismatch): deprecate occuranceThreshol…
Browse files Browse the repository at this point in the history
…d option in favor of occurrenceThreshold to fix typo (dequelabs#3782)

* Correct typos of "occurrence" across axe-core.

* Correct Markdown table spacing.

* Add fix to accomodate previous typos to avoid breaking the API per WilcoFiers' suggestions.

* Account for old spelling in subtreeText and minor formatting.

* run tests

* Add null-aware chaining where necessary.

* run tests

Co-authored-by: Steven Lambert <[email protected]>
  • Loading branch information
nolandanley and straker authored Nov 30, 2022
1 parent 1a7eecb commit 5026d65
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions doc/check-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ th</code></pre>

### label-content-name-mismatch

| Option | Default | Description |
| -------------------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pixelThreshold` | `0.1` | Percent of difference in pixel data or pixel width required to determine if a font is a ligature font. Ligature fonts are ignored when comparing the label to the content |
| `occuranceThreshold` | `3` | Number of times the font is encountered before auto-assigning the font as a ligature or not |
| Option | Default | Description |
| --------------------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pixelThreshold` | `0.1` | Percent of difference in pixel data or pixel width required to determine if a font is a ligature font. Ligature fonts are ignored when comparing the label to the content |
| `occurrenceThreshold` | `3` | Number of times the font is encountered before auto-assigning the font as a ligature or not |

### has-lang

Expand Down
5 changes: 3 additions & 2 deletions lib/checks/label/label-content-name-mismatch-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function curateString(str) {
}

function labelContentNameMismatchEvaluate(node, options, virtualNode) {
const { pixelThreshold, occuranceThreshold } = options || {};
const pixelThreshold = options?.pixelThreshold;
const occurrenceThreshold = options?.occurrenceThreshold ?? options?.occuranceThreshold;

const accText = accessibleText(node).toLowerCase();
if (isHumanInterpretable(accText) < 1) {
Expand All @@ -50,7 +51,7 @@ function labelContentNameMismatchEvaluate(node, options, virtualNode) {
subtreeDescendant: true,
ignoreIconLigature: true,
pixelThreshold,
occuranceThreshold
occurrenceThreshold
})
).toLowerCase();
if (!visibleText) {
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/label/label-content-name-mismatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"evaluate": "label-content-name-mismatch-evaluate",
"options": {
"pixelThreshold": 0.1,
"occuranceThreshold": 3
"occurrenceThreshold": 3
},
"metadata": {
"impact": "serious",
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/mobile/css-orientation-lock-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function cssOrientationLockEvaluate(node, options, virtualNode, context) {
}

/**
* get last match/occurence of a transformation function that can affect rotation along Z axis
* get last match/occurrence of a transformation function that can affect rotation along Z axis
*/
const matches = transformStyle.match(
/(rotate|rotateZ|rotate3d|matrix|matrix3d)\(([^)]+)\)(?!.*(rotate|rotateZ|rotate3d|matrix|matrix3d))/
Expand Down
5 changes: 3 additions & 2 deletions lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ function shouldIgnoreHidden(virtualNode, context) {
* @return {Boolean}
*/
function shouldIgnoreIconLigature(virtualNode, context) {
const { ignoreIconLigature, pixelThreshold, occuranceThreshold } = context;
const { ignoreIconLigature, pixelThreshold } = context;
const occurrenceThreshold = context.occurrenceThreshold ?? context.occuranceThreshold;
if (virtualNode.props.nodeType !== 3 || !ignoreIconLigature) {
return false;
}
return isIconLigature(virtualNode, pixelThreshold, occuranceThreshold);
return isIconLigature(virtualNode, pixelThreshold, occurrenceThreshold);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/commons/text/is-icon-ligature.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import cache from '../../core/base/cache';
* @memberof axe.commons.text
* @instance
* @param {VirtualNode} textVNode The virtual text node
* @param {Number} occuranceThreshold Number of times the font is encountered before auto-assigning the font as a ligature or not
* @param {Number} occurrenceThreshold Number of times the font is encountered before auto-assigning the font as a ligature or not
* @param {Number} differenceThreshold Percent of differences in pixel data or pixel width needed to determine if a font is a ligature font
* @return {Boolean}
*/
function isIconLigature(
textVNode,
differenceThreshold = 0.15,
occuranceThreshold = 3
occurrenceThreshold = 3
) {
/**
* Determine if the visible text is a ligature by comparing the
Expand Down Expand Up @@ -101,17 +101,17 @@ function isIconLigature(

if (!fonts[fontFamily]) {
fonts[fontFamily] = {
occurances: 0,
occurrences: 0,
numLigatures: 0
};
}
const font = fonts[fontFamily];

// improve the performance by only comparing the image data of a font
// a certain number of times
if (font.occurances >= occuranceThreshold) {
if (font.occurrences >= occurrenceThreshold) {
// if the font has always been a ligature assume it's a ligature font
if (font.numLigatures / font.occurances === 1) {
if (font.numLigatures / font.occurrences === 1) {
return true;
}
// inversely, if it's never been a ligature assume it's not a ligature font
Expand All @@ -124,7 +124,7 @@ function isIconLigature(
// other times. in these cases we would need to always check the text
// to know if it's an icon or not
}
font.occurances++;
font.occurrences++;

// 30px was chosen to account for common ligatures in normal fonts
// such as fi, ff, ffi. If a ligature would add a single column of
Expand Down
2 changes: 1 addition & 1 deletion test/commons/text/is-icon-ligature.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('text.isIconLigature', function () {
);
});

describe('occuranceThreshold', function () {
describe('occurrenceThreshold', function () {
(fontApiSupport ? it : it.skip)(
'should change the number of times a font is seen before returning',
function () {
Expand Down

0 comments on commit 5026d65

Please sign in to comment.