Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: don't require a third argument in linter.verifyAndFix (fixes #8805
…) (#8809)

Previously, `linter.verifyAndFix` would crash if no third argument was provided, because some debugging lines assumed that the argument always existed. This updates the method to make the third argument optional.
  • Loading branch information
not-an-aardvark authored and gyandeeps committed Jun 27, 2017
1 parent 5ad8b70 commit a53ef7e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/developer-guide/nodejs-api.md
Expand Up @@ -159,7 +159,7 @@ var messages = linter.verifyAndFix("var foo", {
rules: {
semi: 2
}
}, { filename: "foo.js" });
});
```

Output object from this method:
Expand Down
5 changes: 3 additions & 2 deletions lib/linter.js
Expand Up @@ -1205,6 +1205,7 @@ class Linter extends EventEmitter {
fixedResult,
fixed = false,
passNumber = 0;
const debugTextDescription = options && options.filename || `${text.slice(0, 10)}...`;

/**
* This loop continues until one of the following is true:
Expand All @@ -1218,10 +1219,10 @@ class Linter extends EventEmitter {
do {
passNumber++;

debug(`Linting code for ${options.filename} (pass ${passNumber})`);
debug(`Linting code for ${debugTextDescription} (pass ${passNumber})`);
messages = this.verify(text, config, options);

debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`);
debug(`Generating fixed text for ${debugTextDescription} (pass ${passNumber})`);
fixedResult = SourceCodeFixer.applyFixes(this.getSourceCode(), messages);

// stop if there are any syntax errors.
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -3776,6 +3776,20 @@ describe("eslint", () => {
assert.equal(messages.output, "var a;", "Fixes were applied correctly");
assert.isTrue(messages.fixed);
});

it("does not require a third argument", () => {
const fixResult = linter.verifyAndFix("var a", {
rules: {
semi: 2
}
});

assert.deepEqual(fixResult, {
fixed: true,
messages: [],
output: "var a;"
});
});
});

describe("Edge cases", () => {
Expand Down

0 comments on commit a53ef7e

Please sign in to comment.