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

Commit

Permalink
[#289] react-a11y-anchors false positive when anchor href is undefined
Browse files Browse the repository at this point in the history
closes #289
closes #284

if href is empty, do not check different text
  • Loading branch information
ipip2005 authored and HamletDRC committed Sep 30, 2016
1 parent 344aa44 commit 69473fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/reactA11yAnchorsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ReactA11yAnchorsRuleWalker extends ErrorTolerantWalker {
while (this.anchorInfoList.length > 0) {
const current: AnchorInfo = this.anchorInfoList.shift();
this.anchorInfoList.forEach((anchorInfo: AnchorInfo): void => {
if (current.href === anchorInfo.href &&
if (current.href &&
current.href === anchorInfo.href &&
current.text !== anchorInfo.text &&
!Utils.contains(sameHrefDifferentTexts, anchorInfo)) {

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

describe('Link text should be at least 4 characters long', () => {
describe('Link text should be at least 4 characters long', (): void => {
it('should pass when length of text equals or larger than 4', () => {
const script: string = `
import React = require('react');
Expand All @@ -96,7 +96,7 @@ describe('reactA11yAnchorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, []);
});

it('should fail when length of text less than 4', () => {
it('should fail when length of text less than 4', (): void => {
const script: string = `
import React = require('react');
const anchor1 = <a href="someRef1">ok</a>;
Expand Down Expand Up @@ -132,6 +132,18 @@ describe('reactA11yAnchorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [ ]);
});

it('shoud pass when hrefs undefiend and texts are variant', (): void => {
const script : string = `
import React = require('react');
const anchor1 = <a>someTitle1</a>;
const anchor2 = <a>someTitle2</a>;
const anchor3 = <a>someTitle3</a>;
const anchor4 = <a>someTitle4</a>;
`;

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

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

0 comments on commit 69473fe

Please sign in to comment.