<commit_before>const util = require('../../util');
const self = {
    name: 'heuristic.shortname'
,   section: 'front-matter'
,   rule: 'docIDLatestVersion'
};

exports.name = self.name;

exports.check = function (sr, done) {
    var dl = sr.jsDocument.querySelector("body div.head dl")
    ,   subType = sr.config.submissionType
    ,   topLevel = "TR"
    ;

    if (subType === "member") topLevel = "Submission";
    else if (subType === "team") topLevel = "TeamSubmission";

    var extractLatestURI = function (dl) {
        var latestAnchor;
        dl.querySelectorAll("dt").forEach(function (dt) {
            var txt = sr.norm(dt.textContent)
                        .replace(":", "")
                        .toLowerCase()
                        .replace("published ", "")
            ,   dd = util.next(dt, 'dd')
            ;
            if (txt.lastIndexOf("latest version", 0) === 0)
                latestAnchor = dd && dd.querySelector("a");
        });
        return latestAnchor;
    };

    var linkLate = extractLatestURI(dl);
    if (linkLate && linkLate.getAttribute("href") !== "") {
        var lateRex = "^https?:\\/\\/www\\.w3\\.org\\/" + topLevel + "\\/(.+?)\\/?$"
        ,   matches = (linkLate.getAttribute("href") || "").trim().match(new RegExp(lateRex));
            if (matches) {
                var sn = matches[1];
                sr.metadata('shortname', sn);
            }
    }
    else
        sr.error(self, 'latest-link');

    return done();

};<commit_msg>check if var is defined before running the test.<commit_after>const util = require('../../util');
const self = {
    name: 'heuristic.shortname'
,   section: 'front-matter'
,   rule: 'docIDLatestVersion'
};

exports.name = self.name;

exports.check = function (sr, done) {
    var dl = sr.jsDocument.querySelector("body div.head dl")
    ,   subType = sr.config.submissionType
    ,   topLevel = "TR"
    ;

    if (subType === "member") topLevel = "Submission";
    else if (subType === "team") topLevel = "TeamSubmission";

    var extractLatestURI = function (dl) {
        var latestAnchor;
        if (dl) {
            dl.querySelectorAll("dt").forEach(function (dt) {
                var txt = sr.norm(dt.textContent)
                            .replace(":", "")
                            .toLowerCase()
                            .replace("published ", "")
                ,   dd = util.next(dt, 'dd')
                ;
                if (txt.lastIndexOf("latest version", 0) === 0)
                    latestAnchor = dd && dd.querySelector("a");
            });
            return latestAnchor;
        }
    };

    var linkLate = extractLatestURI(dl);
    if (linkLate && linkLate.getAttribute("href") !== "") {
        var lateRex = "^https?:\\/\\/www\\.w3\\.org\\/" + topLevel + "\\/(.+?)\\/?$"
        ,   matches = (linkLate.getAttribute("href") || "").trim().match(new RegExp(lateRex));
            if (matches) {
                var sn = matches[1];
                sr.metadata('shortname', sn);
            }
    }
    else
        sr.error(self, 'latest-link');

    return done();

};
{'fraction_non_alphanumeric': 0.17132754741240758, 'fraction_numerical': 0.0025715204114432656, 'mean_word_length': 1.8036036036036036, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6865763', 'n_tokens_mistral': 967, 'n_tokens_neox': 923, 'n_words': 190}