From f7edb36c2b1a65892e877d92de7bd65914b5c7c6 Mon Sep 17 00:00:00 2001 From: ota Date: Thu, 26 Jul 2018 04:37:16 +0900 Subject: [PATCH] Fix reports of errors with the --fix option in declaration-block-trailing-semicolon --- jest-setup.js | 26 ++++++++++++++++--- .../index.js | 5 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/jest-setup.js b/jest-setup.js index 3adde122b6..34c5c54dba 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -105,13 +105,31 @@ global.testRule = (rule, schema) => { } // Check the fix - return stylelint(Object.assign({ fix: true }, options)).then( - output => { + return stylelint(Object.assign({ fix: true }, options)) + .then(output => { const fixedCode = getOutputCss(output); expect(fixedCode).toBe(testCase.fixed); expect(fixedCode).not.toBe(testCase.code); - } - ); + return { + fixedCode, + warnings: output.results[0].warnings + }; + }) + .then(({ fixedCode, warnings }) => { + // Checks whether only errors other than those fixed are reported. + return stylelint({ + code: fixedCode, + config: stylelintConfig, + syntax: schema.syntax + }).then(output => ({ + output, + warnings + })); + }) + .then(({ output, warnings }) => { + expect(output.results[0].warnings).toEqual(warnings); + expect(output.results[0].parseErrors).toEqual([]); + }); }); }); }); diff --git a/lib/rules/declaration-block-trailing-semicolon/index.js b/lib/rules/declaration-block-trailing-semicolon/index.js index 59a61e755f..61cf337701 100644 --- a/lib/rules/declaration-block-trailing-semicolon/index.js +++ b/lib/rules/declaration-block-trailing-semicolon/index.js @@ -57,11 +57,11 @@ const rule = function(expectation, _, context) { node.raws.between = ""; node.parent.raws.after = " "; } + return; } message = messages.expected; - } - if (expectation === "never") { + } else if (expectation === "never") { if (!node.parent.raws.semicolon) { return; } @@ -69,6 +69,7 @@ const rule = function(expectation, _, context) { // auto-fix if (context.fix) { node.parent.raws.semicolon = false; + return; } message = messages.rejected;