Skip to content

Commit

Permalink
Chore: Optimizes adding Linter methods (fixes #9000) (#9007)
Browse files Browse the repository at this point in the history
  • Loading branch information
seandenison26 authored and not-an-aardvark committed Jul 26, 2017
1 parent 0a0401f commit d0536d6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/linter.js
Expand Up @@ -1288,13 +1288,18 @@ const externalMethods = {
Object.keys(externalMethods).forEach(methodName => {
const exMethodName = externalMethods[methodName];

// All functions expected to have less arguments than 5.
Linter.prototype[methodName] = function(a, b, c, d, e) {
if (this.sourceCode) {
return this.sourceCode[exMethodName](a, b, c, d, e);
}
return null;
};
// Applies the SourceCode methods to the Linter prototype
Object.defineProperty(Linter.prototype, methodName, {
value() {
if (this.sourceCode) {
return this.sourceCode[exMethodName].apply(this.sourceCode, arguments);
}
return null;
},
configurable: true,
writable: true,
enumerable: false
});
});

module.exports = Linter;

0 comments on commit d0536d6

Please sign in to comment.