Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: don't make Linter a subclass of EventEmitter (refs #9161) #9177

Merged
merged 1 commit into from Aug 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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