From f8add8fd8a9f75e0fdcd9c1a39223f937ff76330 Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Sun, 13 Aug 2017 18:44:36 -0700 Subject: [PATCH] Fix: don't autofix with linter.verifyAndFix when `fix: false` is used (#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. --- lib/linter.js | 2 +- tests/lib/linter.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/linter.js b/lib/linter.js index bb17ac21647..a000a69a1a1 100755 --- a/lib/linter.js +++ b/lib/linter.js @@ -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: diff --git a/tests/lib/linter.js b/tests/lib/linter.js index ba98b0a1fe0..b0f423ccd63 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -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", () => {