Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

chore: switch from colors.js to chalk #3171

Merged
merged 2 commits into from
Sep 26, 2017
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"babel-code-frame": "^6.22.0",
"colors": "^1.1.2",
"chalk": "^2.1.0",
"commander": "^2.9.0",
"diff": "^3.2.0",
"glob": "^7.1.1",
Expand All @@ -54,7 +54,7 @@
"devDependencies": {
"@types/babel-code-frame": "^6.20.0",
"@types/chai": "^3.5.0",
"@types/colors": "^1.1.3",
"@types/chalk": "^0.4.31",
"@types/commander": "^2.9.0",
"@types/diff": "^3.2.0",
"@types/glob": "^5.0.30",
Expand Down
8 changes: 4 additions & 4 deletions src/formatters/codeFrameFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import codeFrame = require("babel-code-frame");
import * as colors from "colors";
import * as chalk from "chalk";

import * as Utils from "../utils";

Expand Down Expand Up @@ -66,11 +66,11 @@ export class Formatter extends AbstractFormatter {
}

let failureString = failure.getFailure();
failureString = colors.red(failureString);
failureString = chalk.red(failureString);

// Rule
let ruleName = failure.getRuleName();
ruleName = colors.gray(`(${ruleName})`);
ruleName = chalk.gray(`(${ruleName})`);

// Frame
const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
Expand All @@ -79,7 +79,7 @@ export class Formatter extends AbstractFormatter {
lineAndCharacter.line + 1, // babel-code-frame is 1 index
lineAndCharacter.character,
{
forceColor: colors.enabled,
forceColor: chalk.enabled,
highlightCode: true,
},
);
Expand Down
10 changes: 5 additions & 5 deletions src/formatters/stylishFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AbstractFormatter } from "../language/formatter/abstractFormatter";
import { IFormatterMetadata } from "../language/formatter/formatter";
import { RuleFailure } from "../language/rule/rule";

import * as colors from "colors";
import * as chalk from "chalk";

import * as Utils from "../utils";

Expand Down Expand Up @@ -70,12 +70,12 @@ export class Formatter extends AbstractFormatter {
}

let failureString = failure.getFailure();
failureString = colors.yellow(failureString);
failureString = chalk.yellow(failureString);

// Rule
let ruleName = failure.getRuleName();
ruleName = this.pad(ruleName, ruleMaxSize);
ruleName = colors.grey(ruleName);
ruleName = chalk.grey(ruleName);

// Lines
const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
Expand All @@ -84,8 +84,8 @@ export class Formatter extends AbstractFormatter {
positionTuple = this.pad(positionTuple, positionMaxSize);

positionTuple = failure.getRuleSeverity() === "warning"
? colors.blue(`${failure.getRuleSeverity().toUpperCase()}: ${positionTuple}`)
: colors.red(`${failure.getRuleSeverity().toUpperCase()}: ${positionTuple}`);
? chalk.blue(`${failure.getRuleSeverity().toUpperCase()}: ${positionTuple}`)
: chalk.red(`${failure.getRuleSeverity().toUpperCase()}: ${positionTuple}`);

// Output
const output = `${positionTuple} ${ruleName} ${failureString}`;
Expand Down
20 changes: 10 additions & 10 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import * as colors from "colors";
import * as chalk from "chalk";
import * as diff from "diff";
import * as fs from "fs";
import * as glob from "glob";
Expand Down Expand Up @@ -209,7 +209,7 @@ export function consoleTestResultsHandler(testResults: TestResult[]): boolean {

export function consoleTestResultHandler(testResult: TestResult): boolean {
// needed to get colors to show up when passing through Grunt
(colors as any).enabled = true;
(chalk as any).enabled = true;

let didAllTestsPass = true;

Expand All @@ -219,17 +219,17 @@ export function consoleTestResultHandler(testResult: TestResult): boolean {

/* tslint:disable:no-console */
if (results.skipped) {
console.log(colors.yellow(` Skipped, requires typescript ${results.requirement}`));
console.log(chalk.yellow(` Skipped, requires typescript ${results.requirement}`));
} else {
const markupDiffResults = diff.diffLines(results.markupFromMarkup, results.markupFromLinter);
const fixesDiffResults = diff.diffLines(results.fixesFromLinter, results.fixesFromMarkup);
const didMarkupTestPass = !markupDiffResults.some((hunk) => hunk.added === true || hunk.removed === true);
const didFixesTestPass = !fixesDiffResults.some((hunk) => hunk.added === true || hunk.removed === true);

if (didMarkupTestPass && didFixesTestPass) {
console.log(colors.green(" Passed"));
console.log(chalk.green(" Passed"));
} else {
console.log(colors.red(" Failed!"));
console.log(chalk.red(" Failed!"));
didAllTestsPass = false;
if (!didMarkupTestPass) {
displayDiffResults(markupDiffResults, MARKUP_FILE_EXTENSION);
Expand All @@ -247,15 +247,15 @@ export function consoleTestResultHandler(testResult: TestResult): boolean {

function displayDiffResults(diffResults: diff.IDiffResult[], extension: string) {
/* tslint:disable:no-console */
console.log(colors.green(`Expected (from ${extension} file)`));
console.log(colors.red("Actual (from TSLint)"));
console.log(chalk.green(`Expected (from ${extension} file)`));
console.log(chalk.red("Actual (from TSLint)"));

for (const diffResult of diffResults) {
let color = colors.grey;
let color = chalk.grey;
if (diffResult.added) {
color = colors.green.underline;
color = chalk.green.underline;
} else if (diffResult.removed) {
color = colors.red.underline;
color = chalk.red.underline;
}
process.stdout.write(color(diffResult.value));
}
Expand Down
6 changes: 3 additions & 3 deletions test/formatters/codeFrameFormatterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { assert } from "chai";
import * as colors from "colors";
import * as chalk from "chalk";

import * as ts from "typescript";

Expand All @@ -28,7 +28,7 @@ describe("CodeFrame Formatter", () => {
let formatter: IFormatter;

before(() => {
(colors as any).enabled = true;
(chalk as any).enabled = true;
const Formatter = TestUtils.getFormatter("codeFrame");
sourceFile = TestUtils.getSourceFile(TEST_FILE);
formatter = new Formatter();
Expand Down Expand Up @@ -109,7 +109,7 @@ describe("CodeFrame Formatter", () => {
return lines.split("\n").map((line) => line.trim());
}

const expectedResult = toTrimmedLines(colors.enabled ? expectedResultColored : expectedResultPlain);
const expectedResult = toTrimmedLines(chalk.enabled ? expectedResultColored : expectedResultPlain);
const result = toTrimmedLines(formatter.format(failures));

assert.deepEqual(result, expectedResult);
Expand Down
4 changes: 2 additions & 2 deletions test/ruleTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import * as colors from "colors";
import * as chalk from "chalk";
import * as glob from "glob";
import * as path from "path";

import { consoleTestResultHandler, runTest } from "../src/test";

/* tslint:disable:no-console */
console.log();
console.log(colors.underline("Testing Lint Rules:"));
console.log(chalk.underline("Testing Lint Rules:"));
/* tslint:enable:no-console */

const testDirectories = glob.sync("test/rules/**/tslint.json").map(path.dirname);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
version "3.5.2"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-3.5.2.tgz#c11cd2817d3a401b7ba0f5a420f35c56139b1c1e"

"@types/colors@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/colors/-/colors-1.1.3.tgz#5413b0a7a1b16dd18be0e3fd57d2feecc81cc776"
"@types/chalk@^0.4.31":
version "0.4.31"
resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-0.4.31.tgz#a31d74241a6b1edbb973cf36d97a2896834a51f9"

"@types/commander@^2.9.0":
version "2.9.1"
Expand Down Expand Up @@ -297,7 +297,7 @@ chalk@^1.1.0, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0:
chalk@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e"
dependencies:
Expand Down