Skip to content

Commit

Permalink
Chore: don't make Linter a subclass of EventEmitter (refs #9161) (#9177)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Aug 30, 2017
1 parent e95af9b commit 1be5634
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/linter.js
Expand Up @@ -731,10 +731,9 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
* Object that is responsible for verifying JavaScript text
* @name eslint
*/
class Linter extends EventEmitter {
class Linter {

constructor() {
super();
this.messages = [];
this.currentConfig = null;
this.currentScopes = null;
Expand All @@ -747,17 +746,13 @@ class Linter extends EventEmitter {

this.rules = new Rules();
this.environments = new Environments();

// set unlimited listeners (see https://github.com/eslint/eslint/issues/524)
this.setMaxListeners(0);
}

/**
* Resets the internal state of the object.
* @returns {void}
*/
reset() {
this.removeAllListeners();
this.messages = [];
this.currentConfig = null;
this.currentScopes = null;
Expand Down Expand Up @@ -859,6 +854,10 @@ class Linter extends EventEmitter {
ast = this.sourceCode.ast;
}

const emitter = new EventEmitter();

emitter.setMaxListeners(Infinity);

// if espree failed to parse the file, there's no sense in setting up rules
if (ast) {

Expand Down Expand Up @@ -939,7 +938,7 @@ class Linter extends EventEmitter {

// add all the selectors from the rule as listeners
Object.keys(rule).forEach(selector => {
this.on(selector, timing.enabled
emitter.on(selector, timing.enabled
? timing.time(ruleId, rule[selector])
: rule[selector]
);
Expand Down Expand Up @@ -972,9 +971,7 @@ class Linter extends EventEmitter {
// augment global scope with declared global variables
addDeclaredGlobals(ast, this.currentScopes[0], this.currentConfig, this.environments);

let eventGenerator = new NodeEventGenerator(this);

eventGenerator = new CodePathAnalyzer(eventGenerator);
const eventGenerator = new CodePathAnalyzer(new NodeEventGenerator(emitter));

/*
* Each node has a type property. Whenever a particular type of
Expand Down

0 comments on commit 1be5634

Please sign in to comment.