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: avoid storing list of problems on Linter instance (refs #9161) #9214

Merged
merged 1 commit into from Sep 3, 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
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