<NME> index.js
<BEF> /**
 * A plugin to identify unclear link text such as "more" and "click here,"
 * which can make for a bad experience when using a screen reader
 */

let $ = require("jquery");
let Plugin = require("../base");
let annotate = require("../shared/annotate")("link-text");

class LinkTextPlugin extends Plugin {
    getTitle() {
        return "Link text";
    }

    getDescription() {
        return `
            Identifies links that may be confusing when read by a screen
            reader
        `;
    }

    /**
     * Slightly modified unclear text checking that has been refactored into
     * a single method to be called with arbitrary strings.
     *
     * Original: https://github.com/GoogleChrome/accessibility-developer-tools/blob/9183b21cb0a02f5f04928f5cb7cb339b6bbc9ff8/src/audits/LinkWithUnclearPurpose.js#L55-67
     */
    isDescriptiveText(textContent) {
        textContent = textContent.replace(/[^a-zA-Z ]/g, "");
        let stopWords = [
            "click", "tap", "go", "here", "learn", "more", "this", "page",
            "link", "about"
        ];

        for (let i = 0; i < stopWords.length; i++) {
            let stopwordRE = new RegExp("\\b" + stopWords[i] + "\\b", "ig");
            textContent = textContent.replace(stopwordRE, "");
            if (textContent.trim() === "") {
                return false;
            }
        }

        return true;
    }

    /**
        // Return whether or not there is any text left
        return textContent.trim() !== "";
    }

    reportError($el, $description, content) {
        let entry = this.error("Link text is unclear", $description, $el);
        annotate.errorLabel($el, "",
            `Link text "${content}" is unclear`, entry);
    }

    /**
     * We can call linkWithUnclearPurpose from ADT directly once the following
     * issue has been resolved. There is some extra code here until then.
     * https://github.com/GoogleChrome/accessibility-developer-tools/issues/156
     */
    run() {
        $("a").each((i, el) => {
            let $el = $(el);

            // Ignore the tota11y UI
            if ($el.parents(".tota11y").length) {
                return;
            }

            // Ignore hidden links
            if (axs.utils.isElementOrAncestorHidden(el)) {
                return;
            }

            // Extract the text alternatives for this element: including
            // its text content, aria-label/labelledby, and alt text for
            // images.
            //
            // TODO: Read from `alts` to determine where the text is coming
            // from (for tailored error messages)
            let alts = {};
            let extractedText = axs.properties.findTextAlternatives(
                el, alts);

            if (!this.isDescriptiveText(extractedText)) {
                let $description = (
                    <div>
                        The text
                        {" "}
                        <i>"{extractedText}"</i>
                        {" "}
                        is unclear without context and may be confusing to
                        screen readers. Consider rearranging the
                        {" "}
                        <code>{"&lt;a&gt;&lt;/a&gt;"}</code>
                        {" "}
                        tags or including special screen reader text.
                    </div>
                );

                this.reportError($el, $description, extractedText);
            }
        });
    }

    cleanup() {
        annotate.removeAll();
    }
}

module.exports = LinkTextPlugin;

<MSG> rework regex

<DFF> @@ -26,21 +26,21 @@ class LinkTextPlugin extends Plugin {
      * Original: https://github.com/GoogleChrome/accessibility-developer-tools/blob/9183b21cb0a02f5f04928f5cb7cb339b6bbc9ff8/src/audits/LinkWithUnclearPurpose.js#L55-67
      */
     isDescriptiveText(textContent) {
-        textContent = textContent.replace(/[^a-zA-Z ]/g, "");
         let stopWords = [
             "click", "tap", "go", "here", "learn", "more", "this", "page",
             "link", "about"
         ];
+        // Generate a regex to match each of the stopWords
+        let stopWordsRE = new RegExp(`\\b(${stopWords.join("|")})\\b`, "ig");
 
-        for (let i = 0; i < stopWords.length; i++) {
-            let stopwordRE = new RegExp("\\b" + stopWords[i] + "\\b", "ig");
-            textContent = textContent.replace(stopwordRE, "");
-            if (textContent.trim() === "") {
-                return false;
-            }
-        }
+        textContent = textContent
+            // Strip leading non-alphabetical characters
+            .replace(/[^a-zA-Z ]/g, "")
+            // Remove the stopWords
+            .replace(stopWordsRE, "");
 
-        return true;
+        // Return whether or not there is any text left
+        return textContent.trim() !== "";
     }
 
     /**

{'commit': 'diff --git a/plugins/link-text/index.js b/plugins/link-text/index.js\nindex 7586f46..3e2947b 100644\n--- a/plugins/link-text/index.js\n+++ b/plugins/link-text/index.js\n@@ -26,21 +26,21 @@ class LinkTextPlugin extends Plugin {\n      * Original: https://github.com/GoogleChrome/accessibility-developer-tools/blob/9183b21cb0a02f5f04928f5cb7cb339b6bbc9ff8/src/audits/LinkWithUnclearPurpose.js#L55-67\n      */\n     isDescriptiveText(textContent) {\n-        textContent = textContent.replace(/[^a-zA-Z ]/g, "");\n         let stopWords = [\n             "click", "tap", "go", "here", "learn", "more", "this", "page",\n             "link", "about"\n         ];\n+        // Generate a regex to match each of the stopWords\n+        let stopWordsRE = new RegExp(`\\\\b(${stopWords.join("|")})\\\\b`, "ig");\n \n-        for (let i = 0; i < stopWords.length; i++) {\n-            let stopwordRE = new RegExp("\\\\b" + stopWords[i] + "\\\\b", "ig");\n-            textContent = textContent.replace(stopwordRE, "");\n-            if (textContent.trim() === "") {\n-                return false;\n-            }\n-        }\n+        textContent = textContent\n+            // Strip leading non-alphabetical characters\n+            .replace(/[^a-zA-Z ]/g, "")\n+            // Remove the stopWords\n+            .replace(stopWordsRE, "");\n \n-        return true;\n+        // Return whether or not there is any text left\n+        return textContent.trim() !== "";\n     }\n \n     /**\n', 'commit_subject': 'rework regex', 'repo_name': 'Khan/tota11y', 'committer': {'name': 'Jordan Scales', 'email': '22d9a2ba2782538e8f589384cbaed93c583ed89d@gmail.com', 'time_sec': '1436396711', 'tz_offset': '-240', 'date': {'seconds': '1436396711'}}, 'commit_tree': 'e970eecc6a98e1d9c1ac74040fc47b7818466e74', 'commit_message': 'rework regex\n', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': '@@ -26,21 +26,21 @@ class LinkTextPlugin extends Plugin {\n      * Original: https://github.com/GoogleChrome/accessibility-developer-tools/blob/9183b21cb0a02f5f04928f5cb7cb339b6bbc9ff8/src/audits/LinkWithUnclearPurpose.js#L55-67\n      */\n     isDescriptiveText(textContent) {\n-        textContent = textContent.replace(/[^a-zA-Z ]/g, "");\n         let stopWords = [\n             "click", "tap", "go", "here", "learn", "more", "this", "page",\n             "link", "about"\n         ];\n+        // Generate a regex to match each of the stopWords\n+        let stopWordsRE = new RegExp(`\\\\b(${stopWords.join("|")})\\\\b`, "ig");\n \n-        for (let i = 0; i < stopWords.length; i++) {\n-            let stopwordRE = new RegExp("\\\\b" + stopWords[i] + "\\\\b", "ig");\n-            textContent = textContent.replace(stopwordRE, "");\n-            if (textContent.trim() === "") {\n-                return false;\n-            }\n-        }\n+        textContent = textContent\n+            // Strip leading non-alphabetical characters\n+            .replace(/[^a-zA-Z ]/g, "")\n+            // Remove the stopWords\n+            .replace(stopWordsRE, "");\n \n-        return true;\n+        // Return whether or not there is any text left\n+        return textContent.trim() !== "";\n     }\n \n     /**\n', 'addition_count': 9, 'deletion_count': 9, 'src_file': 'a/plugins/link-text/index.js', 'tgt_file': 'b/plugins/link-text/index.js', 'file_extension': '.js', 'before_file': '/**\n * A plugin to identify unclear link text such as "more" and "click here,"\n * which can make for a bad experience when using a screen reader\n */\n\nlet $ = require("jquery");\nlet Plugin = require("../base");\nlet annotate = require("../shared/annotate")("link-text");\n\nclass LinkTextPlugin extends Plugin {\n    getTitle() {\n        return "Link text";\n    }\n\n    getDescription() {\n        return `\n            Identifies links that may be confusing when read by a screen\n            reader\n        `;\n    }\n\n    /**\n     * Slightly modified unclear text checking that has been refactored into\n     * a single method to be called with arbitrary strings.\n     *\n     * Original: https://github.com/GoogleChrome/accessibility-developer-tools/blob/9183b21cb0a02f5f04928f5cb7cb339b6bbc9ff8/src/audits/LinkWithUnclearPurpose.js#L55-67\n     */\n    isDescriptiveText(textContent) {\n        textContent = textContent.replace(/[^a-zA-Z ]/g, "");\n        let stopWords = [\n            "click", "tap", "go", "here", "learn", "more", "this", "page",\n            "link", "about"\n        ];\n\n        for (let i = 0; i < stopWords.length; i++) {\n            let stopwordRE = new RegExp("\\\\b" + stopWords[i] + "\\\\b", "ig");\n            textContent = textContent.replace(stopwordRE, "");\n            if (textContent.trim() === "") {\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    /**\n        // Return whether or not there is any text left\n        return textContent.trim() !== "";\n    }\n\n    reportError($el, $description, content) {\n        let entry = this.error("Link text is unclear", $description, $el);\n        annotate.errorLabel($el, "",\n            `Link text "${content}" is unclear`, entry);\n    }\n\n    /**\n     * We can call linkWithUnclearPurpose from ADT directly once the following\n     * issue has been resolved. There is some extra code here until then.\n     * https://github.com/GoogleChrome/accessibility-developer-tools/issues/156\n     */\n    run() {\n        $("a").each((i, el) => {\n            let $el = $(el);\n\n            // Ignore the tota11y UI\n            if ($el.parents(".tota11y").length) {\n                return;\n            }\n\n            // Ignore hidden links\n            if (axs.utils.isElementOrAncestorHidden(el)) {\n                return;\n            }\n\n            // Extract the text alternatives for this element: including\n            // its text content, aria-label/labelledby, and alt text for\n            // images.\n            //\n            // TODO: Read from `alts` to determine where the text is coming\n            // from (for tailored error messages)\n            let alts = {};\n            let extractedText = axs.properties.findTextAlternatives(\n                el, alts);\n\n            if (!this.isDescriptiveText(extractedText)) {\n                let $description = (\n                    <div>\n                        The text\n                        {" "}\n                        <i>"{extractedText}"</i>\n                        {" "}\n                        is unclear without context and may be confusing to\n                        screen readers. Consider rearranging the\n                        {" "}\n                        <code>{"&lt;a&gt;&lt;/a&gt;"}</code>\n                        {" "}\n                        tags or including special screen reader text.\n                    </div>\n                );\n\n                this.reportError($el, $description, extractedText);\n            }\n        });\n    }\n\n    cleanup() {\n        annotate.removeAll();\n    }\n}\n\nmodule.exports = LinkTextPlugin;\n', 'message': 'rework regex\n', 'author_name': 'Jordan Scales', 'lang': 'js'}