Skip to content

Allowed --comments not to be provided #443

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

Merged
merged 1 commit into from
May 3, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/comments/convertComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ const createStubDependencies = (
});

describe("convertComments", () => {
it("returns an empty result when --comment is not provided", async () => {
// Arrange
const dependencies = createStubDependencies();

// Act
const result = await convertComments(dependencies, undefined);

// Assert
expect(result).toEqual({
data: undefined,
status: ResultStatus.Succeeded,
});
});

it("returns an error when --comment is given as a boolean value", async () => {
// Arrange
const dependencies = createStubDependencies();
Expand Down
9 changes: 8 additions & 1 deletion src/comments/convertComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const noGlobsResult: ResultWithDataStatus<string[]> = {
export const convertComments = async (
dependencies: ConvertCommentsDependencies,
filePathGlobs: true | string | string[] | undefined,
): Promise<ResultWithDataStatus<string[]>> => {
): Promise<ResultWithDataStatus<string[] | undefined>> => {
if (filePathGlobs === undefined) {
return {
data: undefined,
status: ResultStatus.Succeeded,
};
}

if (filePathGlobs === true) {
return noGlobsResult;
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversion/convertConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const convertConfig = async (

// 6. A summary of the results is printed to the user's console
await dependencies.reportConversionResults(settings.config, simplifiedConfiguration);
dependencies.reportCommentResults(settings.comments, commentsResult);
dependencies.reportCommentResults(commentsResult);
await dependencies.logMissingPackages(
simplifiedConfiguration,
originalConfigurations.data.packages,
Expand Down
30 changes: 18 additions & 12 deletions src/reporting/reportCommentResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ResultStatus } from "../types";
import { reportCommentResults } from "./reportCommentResults";

describe("reportCommentResults", () => {
it("logs a suggestion when no comment globs are provided", () => {
it("logs a suggestion when no comment globs were requested", () => {
// Arrange
const logger = createStubLogger();

// Act
reportCommentResults({ logger }, undefined, { data: [], status: ResultStatus.Succeeded });
reportCommentResults({ logger }, { data: undefined, status: ResultStatus.Succeeded });

// Assert
expectEqualWrites(
Expand All @@ -23,7 +23,7 @@ describe("reportCommentResults", () => {
const errors = [new Error("Hello")];

// Act
reportCommentResults({ logger }, ["src/index.ts"], { errors, status: ResultStatus.Failed });
reportCommentResults({ logger }, { errors, status: ResultStatus.Failed });

// Assert
expectEqualWrites(
Expand All @@ -44,7 +44,7 @@ describe("reportCommentResults", () => {
const errors = [new Error("Hello"), new Error("World")];

// Act
reportCommentResults({ logger }, ["src/index.ts"], { errors, status: ResultStatus.Failed });
reportCommentResults({ logger }, { errors, status: ResultStatus.Failed });

// Assert
expectEqualWrites(
Expand All @@ -65,10 +65,13 @@ describe("reportCommentResults", () => {
const logger = createStubLogger();

// Act
reportCommentResults({ logger }, ["src/*.ts"], {
data: ["src/index.ts"],
status: ResultStatus.Succeeded,
});
reportCommentResults(
{ logger },
{
data: ["src/index.ts"],
status: ResultStatus.Succeeded,
},
);

// Assert
expectEqualWrites(
Expand All @@ -82,10 +85,13 @@ describe("reportCommentResults", () => {
const logger = createStubLogger();

// Act
reportCommentResults({ logger }, ["src/*.ts"], {
data: ["src/index.ts", "src/data.ts"],
status: ResultStatus.Succeeded,
});
reportCommentResults(
{ logger },
{
data: ["src/index.ts", "src/data.ts"],
status: ResultStatus.Succeeded,
},
);

// Assert
expectEqualWrites(
Expand Down
21 changes: 10 additions & 11 deletions src/reporting/reportCommentResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@ export type ReportCommentResultsDependencies = {

export const reportCommentResults = (
dependencies: ReportCommentResultsDependencies,
commentGlobs: string | string[] | undefined,
commentsResult: ResultWithDataStatus<string[]>,
commentsResult: ResultWithDataStatus<string[] | undefined>,
) => {
if (commentGlobs === undefined) {
dependencies.logger.stdout.write(
chalk.magentaBright(
`${EOL}♻ Consider using --comment to replace TSLint comment directives in your source files. ♻${EOL}`,
),
);
return;
}

if (commentsResult.status === ResultStatus.Failed) {
const headline = `${commentsResult.errors.length} error${
commentsResult.errors.length === 1 ? "" : "s"
Expand All @@ -40,6 +30,15 @@ export const reportCommentResults = (
return;
}

if (commentsResult.data === undefined) {
dependencies.logger.stdout.write(
chalk.magentaBright(
`${EOL}♻ Consider using --comment to replace TSLint comment directives in your source files. ♻${EOL}`,
),
);
return;
}

dependencies.logger.stdout.write(chalk.magentaBright(`${EOL}♻ ${commentsResult.data.length}`));
dependencies.logger.stdout.write(
chalk.magenta(` file${commentsResult.data.length === 1 ? "" : "s"}`),
Expand Down
2 changes: 1 addition & 1 deletion src/reporting/reportOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const logSuccessfulConversions = (
converted: Map<string, EditorSetting | ESLintRuleOptions>,
logger: Logger,
) => {
logger.stdout.write(chalk.greenBright(`✨ ${converted.size}`));
logger.stdout.write(chalk.greenBright(`${EOL} ✨ ${converted.size}`));
logger.stdout.write(
converted.size === 1
? chalk.green(` ${conversionTypeName} replaced with its ESLint equivalent.`)
Expand Down