<commit_before>/**
 * 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) {
        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");

        textContent = textContent
            // Strip leading non-alphabetical characters
            .replace(/[^a-zA-Z ]/g, "")
            // Remove the stopWords
            .replace(stopWordsRE, "");

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

    /**
     * Checks whether or not the text content of an element (including things
     * like `aria-label`) is unclear.
     */
    validateTextContent(el) {
        let extractedText = $.axs.properties.getTextFromDescendantContent(el);
        return {
            extractedText: extractedText,
            result: this.isDescriptiveText(extractedText),<commit_msg>Handled when the textContent is passed into the isDescriptiveText function as undefined or null in the link-text plugin. This fixes the error "Unable to get property 'replace' of undefined or null reference"<commit_after>/**
 * 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) {
        // Handle when the text is undefined or null
        if (typeof textContent === "undefined" || textContent === null) {
            return false;
        }

        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");

        textContent = textContent
            // Strip leading non-alphabetical characters
            .replace(/[^a-zA-Z ]/g, "")
            // Remove the stopWords
            .replace(stopWordsRE, "");

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

    /**
     * Checks whether or not the text content of an element (including things
     * like `aria-label`) is unclear.
     */
    validateTextContent(el) {
        let extractedText = $.axs.properties.getTextFromDescendantContent(el);
        return {
            extractedText: extractedText,
            result: this.isDescriptiveText(extractedText),
{'fraction_non_alphanumeric': 0.11403940886699507, 'fraction_numerical': 0.013300492610837438, 'mean_word_length': 2.3926482873851294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '633723', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1104, 'n_words': 350}