1

I want to make sure my whole code works and clear from warnings in JSlint. I almost made it to be clean but it seems like docCookies framework have all the warning with JSlint.

i.e:

Unexpected '\' before '.'. Unexpected '\' before '+'.

I can't really find anything wrong with the regex, hope that someone can help me on this.

the docCookies framework that I have been working with is:

docCookies: {
    getItem: function(e) {
        if (!e) {
            return null
        }
        return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null
    },
    setItem: function(e, t, n, a, i, r) {
        if (!e || /^(?:expires|max\-age|path|domain|secure)$/i.test(e)) {
            return false
        }
        var o = "";
        if (n) {
            switch (n.constructor) {
                case Number:
                    o = n === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + n;
                    break;
                case String:
                    o = "; expires=" + n;
                    break;
                case Date:
                    o = "; expires=" + n.toUTCString();
                    break
            }
        }
        document.cookie = encodeURIComponent(e) + "=" + encodeURIComponent(t) + o + (i ? "; domain=" + i : "") + (a ? "; path=" + a : "") + (r ? "; secure" : "");
        return true
    },
    removeItem: function(e, t, n) {
        if (!this.hasItem(e)) {
            return false
        }
        document.cookie = encodeURIComponent(e) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (n ? "; domain=" + n : "") + (t ? "; path=" + t : "");
        return true
    },
    hasItem: function(e) {
        if (!e) {
            return false
        }
        return new RegExp("(?:^|;\\s*)" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=").test(document.cookie)
    },
    keys: function() {
        var e = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
        for (var t = e.length, n = 0; n < t; n++) {
            e[n] = decodeURIComponent(e[n])
        }
        return e
    }
}

some warnings are like the image below:

JSlint Warnings

Thanks in advance for any help. :)

EDIT: Sorry I forgot to add this for the JS lint setting: JSlint settings

Assume: "a Browser" Tolerate: "This" and "Whitespace mess"

Felix Agung
  • 21
  • 1
  • 1
  • 3
  • This isn't your code, correct? That is, docCookies is a third-party framework, right? If it is yours, try fixing the other existing JSLint errors. You're missing all sorts of semi-colors, and the `var` declarations don't pass muster either. The quick answer is that you don't need to escape (afaict after skimming) some of those characters in regexes, but I'd also suggest [you don't need to lint a 3rd party library](http://stackoverflow.com/questions/29177993/should-i-worry-about-these-jslint-warnings-on-html5shiv-min-js-version-3-7-2/29178308#29178308), as that's what this appears to be. – ruffin Sep 12 '16 at 13:05
  • Hi ruffin , Yes it is not part of my code, this is just a framework that I copied across to help. Thanks a lot for your suggestion, I am not yet an expert in regex thats why I haven't really play around with it to get rid of the "\" as you said. – Felix Agung Sep 12 '16 at 23:18

0 Answers0