Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
[#269] react-a11y-anchors false positive when test is 4 chars long
Browse files Browse the repository at this point in the history
closes #269

fix anchor fail when text length is exactly 4
  • Loading branch information
ipip2005 authored and HamletDRC committed Sep 30, 2016
1 parent 60335c5 commit 344aa44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reactA11yAnchorsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ReactA11yAnchorsRuleWalker extends ErrorTolerantWalker {
this.addFailure(this.createFailure(anchorInfo.start, anchorInfo.width, NO_HASH_FAILURE_STRING));
}

if (!anchorInfo.text || anchorInfo.text.length <= 4) {
if (!anchorInfo.text || anchorInfo.text.length < 4) {
this.addFailure(this.createFailure(anchorInfo.start, anchorInfo.width, LINK_TEXT_TOO_SHORT_FAILURE_STRING));
}

Expand Down
36 changes: 36 additions & 0 deletions tests/ReactA11yAnchorsRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,42 @@ describe('reactA11yAnchorsRule', () : void => {
]);
});

describe('Link text should be at least 4 characters long', () => {
it('should pass when length of text equals or larger than 4', () => {
const script: string = `
import React = require('react');
const anchor1 = <a href="someRef1">save</a>;
const anchor2 = <a href="someRef2">Delete</a>;
const anchor3 = <a href="someRef3"><span>cancel</span></a>;
`;

TestHelper.assertViolations(ruleName, script, []);
});

it('should fail when length of text less than 4', () => {
const script: string = `
import React = require('react');
const anchor1 = <a href="someRef1">ok</a>;
const anchor2 = <a href="someRef2"><span>Go</span></a>;
`;

TestHelper.assertViolations(ruleName, script, [
{
"failure": "Link text should be at least 4 characters long.",
"name": "file.tsx",
"ruleName": "react-a11y-anchors",
"startPosition": { "character": 33, "line": 3 }
},
{
"failure": "Link text should be at least 4 characters long.",
"name": "file.tsx",
"ruleName": "react-a11y-anchors",
"startPosition": { "character": 33, "line": 4 }
}
]);
});
});

it('should pass when hrefs and texts both are identical', () : void => {
const script : string = `
import React = require('react');
Expand Down

0 comments on commit 344aa44

Please sign in to comment.