Skip to content

Commit

Permalink
Fix reports of errors with the --fix option in declaration-block-trai…
Browse files Browse the repository at this point in the history
…ling-semicolon
  • Loading branch information
ota-meshi authored and jeddy3 committed Jul 25, 2018
1 parent 148c09f commit f7edb36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
26 changes: 22 additions & 4 deletions jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/declaration-block-trailing-semicolon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ 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;
}

// auto-fix
if (context.fix) {
node.parent.raws.semicolon = false;
return;
}

message = messages.rejected;
Expand Down

0 comments on commit f7edb36

Please sign in to comment.