Browse Source

.jshintrc: Add the "forin" option & fix fallout

Also added few missing |hasOwnProperty| calls that JSHint didn't detect
because it only looks whether there is an |if| statement wrapping the
loop body.
redux
David Majda 8 years ago
parent
commit
95fd64ec15
  1. 1
      .jshintrc
  2. 4
      bin/pegjs
  3. 4
      lib/compiler.js
  4. 4
      lib/peg.js
  5. 18
      lib/utils.js
  6. 12
      spec/generated-parser.spec.js
  7. 6
      spec/helpers.js
  8. 8
      spec/parser.spec.js

1
.jshintrc

@ -2,6 +2,7 @@
"curly": true,
"eqeqeq": true,
"evil": true,
"forin": true,
"laxbreak": true,
"noempty": true,
"nonew": true,

4
bin/pegjs

@ -70,7 +70,9 @@ function addExtraOptions(options, json) {
}
for (var key in extraOptions) {
options[key] = extraOptions[key];
if (extraOptions.hasOwnProperty(key)) {
options[key] = extraOptions[key];
}
}
}

4
lib/compiler.js

@ -48,7 +48,9 @@ module.exports = {
});
for (stage in passes) {
utils.each(passes[stage], runPass);
if (passes.hasOwnProperty(stage)) {
utils.each(passes[stage], runPass);
}
}
switch (options.output) {

4
lib/peg.js

@ -24,7 +24,9 @@ module.exports = {
var converted = {}, stage;
for (stage in passes) {
converted[stage] = utils.values(passes[stage]);
if (passes.hasOwnProperty(stage)) {
converted[stage] = utils.values(passes[stage]);
}
}
return converted;

18
lib/utils.js

@ -69,7 +69,9 @@ var utils = {
keys: function(object) {
var result = [];
for (var key in object) {
result.push(key);
if (object.hasOwnProperty(key)) {
result.push(key);
}
}
return result;
},
@ -77,7 +79,9 @@ var utils = {
values: function(object) {
var result = [];
for (var key in object) {
result.push(object[key]);
if (object.hasOwnProperty(key)) {
result.push(object[key]);
}
}
return result;
},
@ -85,15 +89,19 @@ var utils = {
clone: function(object) {
var result = {};
for (var key in object) {
result[key] = object[key];
if (object.hasOwnProperty(key)) {
result[key] = object[key];
}
}
return result;
},
defaults: function(object, defaults) {
for (var key in defaults) {
if (!(key in object)) {
object[key] = defaults[key];
if (defaults.hasOwnProperty(key)) {
if (!(key in object)) {
object[key] = defaults[key];
}
}
}
},

12
spec/generated-parser.spec.js

@ -15,7 +15,9 @@ describe("generated parser", function() {
* changed later.
*/
for (key in options) {
clonedOptions[key] = options[key];
if (options.hasOwnProperty(key)) {
clonedOptions[key] = options[key];
}
}
describe(
@ -123,10 +125,12 @@ describe("generated parser", function() {
} else {
if (details) {
for (key in details) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
return false;
return false;
}
}
}
}

6
spec/helpers.js

@ -29,9 +29,11 @@ beforeEach(function() {
if (!isObject(value)) { return false; }
for (key in details) {
if (!(key in value)) { return false; }
if (details.hasOwnProperty(key)) {
if (!(key in value)) { return false; }
if (!matchDetails(value[key], details[key])) { return false; }
if (!matchDetails(value[key], details[key])) { return false; }
}
}
return true;

8
spec/parser.spec.js

@ -145,10 +145,12 @@ describe("PEG.js grammar parser", function() {
} else {
if (details) {
for (key in details) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
return false;
return false;
}
}
}
}

Loading…
Cancel
Save