Skip to content

Commit

Permalink
use the 2.x (stable) branch of jshint
Browse files Browse the repository at this point in the history
also commit the updated jshint modules themselves
  • Loading branch information
stepheneb committed Dec 8, 2013
1 parent 626b66f commit 31d94d6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Support/jshint-tm.js
Expand Up @@ -18,16 +18,16 @@ function html(s) {
}

/**
* Downloads the latest JSHint version from GitHub and invokes the callback when done.
* https://raw.github.com/jshint/jshint/master/src/jshint.js
* Downloads the latest JSHint from the 2.x branch from GitHub and invokes the callback when done.
* https://raw.github.com/jshint/jshint/2.x/src/jshint.js
*/
function download_jshint_resources(ready) {
var req,
jshint_resources = ["jshint.js", "vars.js", "messages.js", "lex.js", "reg.js", "state.js", "style.js"],
jshint_data_resources = ["ascii-identifier-data.js", "non-ascii-identifier-part-only.js", "non-ascii-identifier-start.js"];

jshint_resources.forEach(function(resource) {
req = https.get({host: 'raw.github.com', port: 443, path: '/jshint/jshint/master/src/' + resource}, function(res) {
req = https.get({host: 'raw.github.com', port: 443, path: '/jshint/jshint/2.x/src/' + resource}, function(res) {
if (res.statusCode === 200) {
res.setEncoding('utf8');
var data = '';
Expand Down
93 changes: 51 additions & 42 deletions Support/jshint.js
Expand Up @@ -311,18 +311,10 @@ var JSHINT = (function () {
});
}

function combine(t, o) {
var n;
for (n in o) {
if (_.has(o, n) && !_.has(JSHINT.blacklist, n)) {
t[n] = o[n];
}
}
}

function updatePredefined() {
Object.keys(JSHINT.blacklist).forEach(function (key) {
delete predefined[key];
function combine(dest, src) {
Object.keys(src).forEach(function (name) {
if (JSHINT.blacklist.hasOwnProperty(name)) return;
dest[name] = src[name];
});
}

Expand Down Expand Up @@ -547,8 +539,7 @@ var JSHINT = (function () {
}
}
} else {
if (!state.option.shadow && type !== "exception" ||
(funct["(blockscope)"].getlabel(t))) {
if (!state.option.shadow && type !== "exception" || (funct["(blockscope)"].getlabel(t))) {
warning("W004", state.tokens.next, t);
}
}
Expand Down Expand Up @@ -604,7 +595,7 @@ var JSHINT = (function () {
val = false;

JSHINT.blacklist[key] = key;
updatePredefined();
delete predefined[key];
} else {
predef[key] = (val === "true");
}
Expand Down Expand Up @@ -697,15 +688,14 @@ var JSHINT = (function () {

if (key === "validthis") {
// `validthis` is valid only within a function scope.
if (funct["(global)"]) {
error("E009");
} else {
if (val === "true" || val === "false") {
state.option.validthis = (val === "true");
} else {
error("E002", nt);
}
}

if (funct["(global)"])
return void error("E009");

if (val !== "true" && val !== "false")
return void error("E002", nt);

state.option.validthis = (val === "true");
return;
}

Expand Down Expand Up @@ -1948,17 +1938,13 @@ var JSHINT = (function () {


function note_implied(tkn) {
var name = tkn.value, line = tkn.line, a = implied[name];
if (typeof a === "function") {
a = false;
}
var name = tkn.value;
var desc = Object.getOwnPropertyDescriptor(implied, name);

if (!a) {
a = [line];
implied[name] = a;
} else if (a[a.length - 1] !== line) {
a.push(line);
}
if (!desc)
implied[name] = [tkn.line];
else
desc.value.push(tkn.line);
}


Expand Down Expand Up @@ -3045,7 +3031,11 @@ var JSHINT = (function () {
}

i = property_name();
if (!i) {

// ES6 allows for get() {...} and set() {...} method
// definition shorthand syntax, so we don't produce an error
// if the esnext option is enabled.
if (!i && !state.option.inESNext()) {
error("E035");
}

Expand All @@ -3055,13 +3045,19 @@ var JSHINT = (function () {
error("E049", state.tokens.next, "class getter method", i);
}

saveGetter(tag + i);
// We don't want to save this getter unless it's an actual getter
// and not an ES6 concise method
if (i) {
saveGetter(tag + i);
}

t = state.tokens.next;
adjacent(state.tokens.curr, state.tokens.next);
f = doFunction();
p = f["(params)"];

if (p) {
// Don't warn about getter/setter pairs if this is an ES6 concise method
if (i && p) {
warning("W076", t, p[0], i);
}

Expand All @@ -3074,7 +3070,11 @@ var JSHINT = (function () {
}

i = property_name();
if (!i) {

// ES6 allows for get() {...} and set() {...} method
// definition shorthand syntax, so we don't produce an error
// if the esnext option is enabled.
if (!i && !state.option.inESNext()) {
error("E035");
}

Expand All @@ -3084,13 +3084,19 @@ var JSHINT = (function () {
error("E049", state.tokens.next, "class setter method", i);
}

saveSetter(tag + i, state.tokens.next);
// We don't want to save this getter unless it's an actual getter
// and not an ES6 concise method
if (i) {
saveSetter(tag + i, state.tokens.next);
}

t = state.tokens.next;
adjacent(state.tokens.curr, state.tokens.next);
f = doFunction();
p = f["(params)"];

if (!p || p.length !== 1) {
// Don't warn about getter/setter pairs if this is an ES6 concise method
if (i && (!p || p.length !== 1)) {
warning("W077", t, i);
}
} else {
Expand Down Expand Up @@ -4023,7 +4029,8 @@ var JSHINT = (function () {
this.first = expression(0);

if (this.first &&
this.first.type === "(punctuator)" && this.first.value === "=" && !state.option.boss) {
this.first.type === "(punctuator)" && this.first.value === "=" &&
!this.first.paren && !state.option.boss) {
warningAt("W093", this.first.line, this.first.character);
}
}
Expand Down Expand Up @@ -4056,7 +4063,8 @@ var JSHINT = (function () {
nobreaknonadjacent(state.tokens.curr, state.tokens.next);
this.first = expression(10);

if (this.first.type === "(punctuator)" && this.first.value === "=" && !state.option.boss) {
if (this.first.type === "(punctuator)" && this.first.value === "=" &&
!this.first.paren && !state.option.boss) {
warningAt("W093", this.first.line, this.first.character);
}
}
Expand Down Expand Up @@ -4517,6 +4525,7 @@ var JSHINT = (function () {
var newOptionObj = {};
var newIgnoredObj = {};

o = _.clone(o);
state.reset();

if (o && o.scope) {
Expand Down
25 changes: 17 additions & 8 deletions Support/lex.js
Expand Up @@ -1314,16 +1314,17 @@ Lexer.prototype = {
this.char = 1;
this.from = 1;

var startsWith = function (prefix) {
return this.indexOf(prefix) === 0;
};
var endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
var inputTrimmed = this.input.trim();

// If we are ignoring linter errors, replace the input with empty string
// if it doesn't already at least start or end a multi-line comment
if (state.ignoreLinterErrors === true) {
var startsWith = function (prefix) {
return this.indexOf(prefix) === 0;
};
var endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
var inputTrimmed = this.input.trim();
if (! (startsWith.call(inputTrimmed, "/*") || endsWith.call(inputTrimmed, "*/"))) {
this.input = "";
}
Expand All @@ -1345,7 +1346,15 @@ Lexer.prototype = {
// long.

if (state.option.maxlen && state.option.maxlen < this.input.length) {
this.trigger("warning", { code: "W101", line: this.line, character: this.input.length });
var inComment = state.tokens.curr.comment ||
startsWith.call(inputTrimmed, "//") ||
startsWith.call(inputTrimmed, "/*");

var shouldTriggerError = !inComment || !reg.maxlenException.test(inputTrimmed);

if (shouldTriggerError) {
this.trigger("warning", { code: "W101", line: this.line, character: this.input.length });
}
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions Support/messages.js
Expand Up @@ -40,7 +40,7 @@ var errors = {
E024: "Unexpected '{a}'.",
E025: "Missing ':' on a case clause.",
E026: "Missing '}' to match '{' from line {a}.",
E027: "Missing ']' to match '[' form line {a}.",
E027: "Missing ']' to match '[' from line {a}.",
E028: "Illegal comma.",
E029: "Unclosed string.",

Expand Down Expand Up @@ -125,7 +125,7 @@ var warnings = {
W054: "The Function constructor is a form of eval.",
W055: "A constructor name should start with an uppercase letter.",
W056: "Bad constructor.",
W057: "Weird construction. Is 'new' unnecessary?",
W057: "Weird construction. Is 'new' necessary?",
W058: "Missing '()' invoking a constructor.",
W059: "Avoid arguments.{a}.",
W060: "document.write can be a form of eval.",
Expand Down
14 changes: 8 additions & 6 deletions Support/package.json
Expand Up @@ -33,10 +33,11 @@
"main": "./src/jshint.js",

"dependencies": {
"shelljs": "0.1.x",
"underscore": "1.4.x",
"cli": "0.4.x",
"minimatch": "0.x.x",
"shelljs": "0.1.x",
"underscore": "1.4.x",
"cli": "0.4.x",
"minimatch": "0.x.x",
"htmlparser2": "3.3.x",
"console-browserify": "0.1.x"
},

Expand All @@ -57,11 +58,12 @@
"strict": true,
"white": true,
"smarttabs": true,
"maxlen": 100,
"newcap": false,
"undef": true,
"unused": true,
"onecase": true,
"lastsemic": true,
"newcap": false,
"maxlen": 100,
"indent": 2
},

Expand Down
4 changes: 4 additions & 0 deletions Support/reg.js
Expand Up @@ -32,3 +32,7 @@ exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livesc

// Catches /* falls through */ comments (ft)
exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/;

// very conservative rule (eg: only one space between the start of the comment and the first character)
// to relax the maxlen option
exports.maxlenException = /^(?:(?:\/\/|\/\*|\*) ?)?[^ ]+$/;
3 changes: 3 additions & 0 deletions Support/vars.js
Expand Up @@ -52,6 +52,9 @@ exports.browser = {
atob : false,
blur : false,
btoa : false,
CanvasGradient : false,
CanvasPattern : false,
CanvasRenderingContext2D: false,
clearInterval : false,
clearTimeout : false,
close : false,
Expand Down

0 comments on commit 31d94d6

Please sign in to comment.