Skip to content

Commit

Permalink
Chore: avoid storing list of problems on Linter instance (refs #9161) (
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Sep 3, 2017
1 parent ed6d088 commit a567499
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions lib/linter.js
Expand Up @@ -761,7 +761,6 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
class Linter {

constructor() {
this.messages = [];
this.currentConfig = null;
this.scopeManager = null;
this.currentFilename = null;
Expand All @@ -779,7 +778,6 @@ class Linter {
* @returns {void}
*/
reset() {
this.messages = [];
this.currentConfig = null;
this.scopeManager = null;
this.traverser = null;
Expand Down Expand Up @@ -878,12 +876,14 @@ class Linter {
this.sourceCode = new SourceCode(text, parseResult.ast);
}

const problems = [];

// parse global comments and modify config
if (allowInlineConfig !== false) {
const modifyConfigResult = modifyConfigsFromComments(this.currentFilename, this.sourceCode.ast, config, this);

config = modifyConfigResult.config;
modifyConfigResult.problems.forEach(problem => this.messages.push(problem));
modifyConfigResult.problems.forEach(problem => problems.push(problem));
}

// ensure that severities are normalized in the config
Expand Down Expand Up @@ -955,9 +955,7 @@ class Linter {
if (problem.fix && ruleCreator.meta && !ruleCreator.meta.fixable) {
throw new Error("Fixable rules should export a `meta.fixable` property.");
}
if (!isDisabledByReportingConfig(this.reportingConfig, ruleId, problem)) {
this.messages.push(problem);
}
problems.push(problem);

/*
* This is used to avoid breaking rules that used monkeypatch Linter, and relied on
Expand Down Expand Up @@ -1039,18 +1037,9 @@ class Linter {
}
});

// sort by line and column
this.messages.sort((a, b) => {
const lineDiff = a.line - b.line;

if (lineDiff === 0) {
return a.column - b.column;
}
return lineDiff;

});

return this.messages;
return problems
.filter(problem => !isDisabledByReportingConfig(this.reportingConfig, problem.ruleId, problem))
.sort((problemA, problemB) => problemA.line - problemB.line || problemA.column - problemB.column);
}

/**
Expand Down

0 comments on commit a567499

Please sign in to comment.