Skip to content

Commit

Permalink
Fix: don't autofix with linter.verifyAndFix when fix: false is used (
Browse files Browse the repository at this point in the history
…#9098)

Due to a bug, `linter.verifyAndFix` previously applied all autofixes when the `fix` option was set to `false`, even though the documented behavior was to apply no autofixes. This commit fixes the bug.
  • Loading branch information
not-an-aardvark committed Aug 14, 2017
1 parent 77bcee4 commit f8add8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linter.js
Expand Up @@ -1210,7 +1210,7 @@ class Linter extends EventEmitter {
fixed = false,
passNumber = 0;
const debugTextDescription = options && options.filename || `${text.slice(0, 10)}...`;
const shouldFix = options && options.fix || true;
const shouldFix = options && typeof options.fix !== "undefined" ? options.fix : true;

/**
* This loop continues until one of the following is true:
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -3819,6 +3819,16 @@ describe("Linter", () => {
output: "var a;"
});
});

it("does not apply autofixes when fix argument is `false`", () => {
const fixResult = linter.verifyAndFix("var a", {
rules: {
semi: 2
}
}, { fix: false });

assert.strictEqual(fixResult.fixed, false);
});
});

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

0 comments on commit f8add8f

Please sign in to comment.