Skip to content

Commit

Permalink
Chore: remove currentFilename prop from Linter instances (refs #9161) (
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Sep 5, 2017
1 parent 5566e94 commit 2eedc1f
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions lib/linter.js
Expand Up @@ -753,7 +753,6 @@ class Linter {
constructor() {
this.currentConfig = null;
this.scopeManager = null;
this.currentFilename = null;
this.traverser = null;
this.reportingConfig = [];
this.sourceCode = null;
Expand Down Expand Up @@ -812,15 +811,19 @@ class Linter {
text = this.sourceCode.text;
}

let providedFilename;

// evaluate arguments
if (typeof filenameOrOptions === "object") {
this.currentFilename = filenameOrOptions.filename;
providedFilename = filenameOrOptions.filename;
allowInlineConfig = filenameOrOptions.allowInlineConfig;
saveState = filenameOrOptions.saveState;
} else {
this.currentFilename = filenameOrOptions;
providedFilename = filenameOrOptions;
}

const filename = typeof providedFilename === "string" ? providedFilename : "<input>";

if (!saveState) {
this.reset();
}
Expand Down Expand Up @@ -855,7 +858,7 @@ class Linter {
stripUnicodeBOM(text).replace(astUtils.SHEBANG_MATCHER, (match, captured) => `//${captured}`),
config.parserOptions,
config.parser,
this.currentFilename
filename
);

if (!parseResult.success) {
Expand All @@ -870,7 +873,7 @@ class Linter {

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

config = modifyConfigResult.config;
modifyConfigResult.problems.forEach(problem => problems.push(problem));
Expand All @@ -889,7 +892,7 @@ class Linter {
{
getAncestors: () => this.traverser.parents(),
getDeclaredVariables: this.getDeclaredVariables.bind(this),
getFilename: this.getFilename.bind(this),
getFilename: () => filename,
getScope: this.getScope.bind(this),
getSourceCode: () => this.sourceCode,
markVariableAsUsed: this.markVariableAsUsed.bind(this),
Expand Down Expand Up @@ -1117,19 +1120,6 @@ class Linter {
return false;
}

/**
* Gets the filename for the currently parsed source.
* @returns {string} The filename associated with the source being parsed.
* Defaults to "<input>" if no filename info is present.
*/
getFilename() {
if (typeof this.currentFilename === "string") {
return this.currentFilename;
}
return "<input>";

}

/**
* Defines a new linting rule.
* @param {string} ruleId A unique rule identifier
Expand Down

0 comments on commit 2eedc1f

Please sign in to comment.