Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrade: chalk to 2.x release (#9115)
  • Loading branch information
ntwb authored and not-an-aardvark committed Aug 18, 2017
1 parent 6ef734a commit d00e24f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile.js
Expand Up @@ -458,7 +458,7 @@ function hasBranch(branchName) {
*/
function getFormatterResults() {
const CLIEngine = require("./lib/cli-engine"),
chalk = require("chalk");
stripAnsi = require("strip-ansi");

const formatterFiles = fs.readdirSync("./lib/formatters/"),
cli = new CLIEngine({
Expand Down Expand Up @@ -489,7 +489,7 @@ function getFormatterResults() {

if (fileExt === ".js") {
data.formatterResults[name] = {
result: chalk.stripColor(cli.getFormatter(name)(rawMessages.results))
result: stripAnsi(cli.getFormatter(name)(rawMessages.results))
};
}
return data;
Expand Down
3 changes: 2 additions & 1 deletion lib/formatters/stylish.js
Expand Up @@ -5,6 +5,7 @@
"use strict";

const chalk = require("chalk"),
stripAnsi = require("strip-ansi"),
table = require("text-table");

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -71,7 +72,7 @@ module.exports = function(results) {
{
align: ["", "r", "l"],
stringLength(str) {
return chalk.stripColor(str).length;
return stripAnsi(str).length;
}
}
).split("\n").map(el => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.dim(`${p1}:${p2}`))).join("\n")}\n\n`;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"ajv": "^5.2.0",
"babel-code-frame": "^6.22.0",
"chalk": "^1.1.3",
"chalk": "^2.1.0",
"concat-stream": "^1.6.0",
"cross-spawn": "^5.1.0",
"debug": "^2.6.8",
Expand Down Expand Up @@ -68,6 +68,7 @@
"progress": "^2.0.0",
"require-uncached": "^1.0.3",
"semver": "^5.3.0",
"strip-ansi": "^4.0.0",
"strip-json-comments": "~2.0.1",
"table": "^4.0.1",
"text-table": "~0.2.0"
Expand Down
21 changes: 11 additions & 10 deletions tests/lib/formatters/codeframe.js
Expand Up @@ -14,6 +14,7 @@ const sinon = require("sinon");
const proxyquire = require("proxyquire");
const chalk = require("chalk");
const path = require("path");
const stripAnsi = require("strip-ansi");

// Chalk protects its methods so we need to inherit from it for Sinon to work.
const chalkStub = Object.create(chalk, {
Expand Down Expand Up @@ -86,7 +87,7 @@ describe("formatter:codeframe", () => {
it("should return a string in the correct format for warnings", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
`warning: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
"> 1 | var foo = 1;",
" | ^",
Expand Down Expand Up @@ -115,7 +116,7 @@ describe("formatter:codeframe", () => {
it("should return a string in the correct format", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
`warning: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
"> 1 | var foo = 1;",
" | ^",
Expand Down Expand Up @@ -147,7 +148,7 @@ describe("formatter:codeframe", () => {
it("should return a string in the correct format for errors", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
`error: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
"> 1 | var foo = 1;",
" | ^",
Expand Down Expand Up @@ -193,7 +194,7 @@ describe("formatter:codeframe", () => {
it("should return a string with multiple entries", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
"error: Missing semicolon (semi) at foo.js:1:14:",
"> 1 | const foo = 1",
" | ^",
Expand Down Expand Up @@ -241,7 +242,7 @@ describe("formatter:codeframe", () => {
it("should return a string with code preview pointing to the correct location after fixes", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
"error: 'foo' is assigned a value but never used (no-unused-vars) at foo.js:4:11:",
" 2 | ",
" 3 | // a comment",
Expand Down Expand Up @@ -286,7 +287,7 @@ describe("formatter:codeframe", () => {
it("should return a string with multiple entries", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
"error: Missing semicolon (semi) at foo.js:1:14:",
"> 1 | const foo = 1",
" | ^",
Expand Down Expand Up @@ -322,7 +323,7 @@ describe("formatter:codeframe", () => {
it("should return a string in the correct format", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), [
assert.equal(stripAnsi(result), [
"error: Parsing error: Unexpected token { at foo.js:1:2:",
"> 1 | e{}",
" | ^",
Expand All @@ -347,7 +348,7 @@ describe("formatter:codeframe", () => {
it("should return a string without code preview (codeframe)", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), "error: Couldn't find foo.js at foo.js\n\n\n1 error found.");
assert.equal(stripAnsi(result), "error: Couldn't find foo.js at foo.js\n\n\n1 error found.");
});
});

Expand All @@ -367,13 +368,13 @@ describe("formatter:codeframe", () => {
it("should return a string without code preview (codeframe)", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
assert.equal(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
});

it("should output filepath but without 'line:column' appended", () => {
const result = formatter(code);

assert.equal(chalk.stripColor(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
assert.equal(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
});
});

Expand Down

0 comments on commit d00e24f

Please sign in to comment.