From 8beb94fa60e574f13521b65da0228e5de53177a9 Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Sat, 2 Sep 2017 19:27:40 -0400 Subject: [PATCH] Chore: avoid storing list of problems on Linter instance (refs #9161) --- lib/linter.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/linter.js b/lib/linter.js index 7e32eedb9aa..d6dec4b4541 100755 --- a/lib/linter.js +++ b/lib/linter.js @@ -761,7 +761,6 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze( class Linter { constructor() { - this.messages = []; this.currentConfig = null; this.scopeManager = null; this.currentFilename = null; @@ -779,7 +778,6 @@ class Linter { * @returns {void} */ reset() { - this.messages = []; this.currentConfig = null; this.scopeManager = null; this.traverser = null; @@ -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 @@ -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 @@ -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); } /**