diff --git a/src/reactA11yAnchorsRule.ts b/src/reactA11yAnchorsRule.ts
index 2041bb581..91bd5e762 100644
--- a/src/reactA11yAnchorsRule.ts
+++ b/src/reactA11yAnchorsRule.ts
@@ -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));
}
diff --git a/tests/ReactA11yAnchorsRuleTests.ts b/tests/ReactA11yAnchorsRuleTests.ts
index 66c496276..ca2f21154 100644
--- a/tests/ReactA11yAnchorsRuleTests.ts
+++ b/tests/ReactA11yAnchorsRuleTests.ts
@@ -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 = save;
+ const anchor2 = Delete;
+ const anchor3 = cancel;
+ `;
+
+ TestHelper.assertViolations(ruleName, script, []);
+ });
+
+ it('should fail when length of text less than 4', () => {
+ const script: string = `
+ import React = require('react');
+ const anchor1 = ok;
+ const anchor2 = Go;
+ `;
+
+ 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');