Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: reset to the default color #12174

Merged
merged 1 commit into from Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cli-engine/formatters/stylish.js
Expand Up @@ -96,5 +96,6 @@ module.exports = function(results) {
}
}

return total > 0 ? output : "";
// Resets output color, for prevent change on top level
return total > 0 ? chalk.reset(output) : "";
ricardogobbosouza marked this conversation as resolved.
Show resolved Hide resolved
};
20 changes: 20 additions & 0 deletions tests/lib/cli-engine/formatters/stylish.js
Expand Up @@ -19,6 +19,12 @@ const assert = require("chai").assert,
* for Sinon to work.
*/
const chalkStub = Object.create(chalk, {
reset: {
value(str) {
return chalk.reset(str);
},
writable: true
},
yellow: {
value(str) {
return chalk.yellow(str);
Expand Down Expand Up @@ -47,6 +53,7 @@ describe("formatter:stylish", () => {

beforeEach(() => {
chalk.enabled = false;
sinon.spy(chalkStub, "reset");
sinon.spy(chalkStub.yellow, "bold");
sinon.spy(chalkStub.red, "bold");
});
Expand All @@ -68,6 +75,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "");
assert.strictEqual(chalkStub.reset.callCount, 0);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -93,8 +101,10 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);

});

describe("when the error is fixable", () => {
Expand All @@ -106,6 +116,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n 1 error and 0 warnings potentially fixable with the `--fix` option.\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 2);
});
Expand All @@ -132,6 +143,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected foo foo\n\n\u2716 1 problem (0 errors, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 1);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -145,6 +157,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected foo foo\n\n\u2716 1 problem (0 errors, 1 warning)\n 0 errors and 1 warning potentially fixable with the `--fix` option.\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 2);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand Down Expand Up @@ -172,6 +185,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected . foo\n\n\u2716 1 problem (0 errors, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 1);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -195,6 +209,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down Expand Up @@ -224,6 +239,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (1 error, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down Expand Up @@ -258,6 +274,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (1 error, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -271,6 +288,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (2 errors, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -284,6 +302,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (0 errors, 2 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -304,6 +323,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 0:0 error Couldn't find foo.js\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down