Skip to content
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
24 changes: 19 additions & 5 deletions src/input/findTSLintConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ export type FindTSLintConfigurationDependencies = {
importer: SansDependencies<typeof importer>;
};

const knownErrors = [
[
"unknown option `--print-config",
() => new Error("TSLint v5.18 required. Please update your version."),
],
[
"Could not find configuration path.",
(filePath: string) =>
new Error(
`Could not find your TSLint configuration file at '${filePath}'. Try providing a different --tslint path.`,
),
],
] as const;

export const findTSLintConfiguration = async (
dependencies: FindTSLintConfigurationDependencies,
config: string | undefined,
Expand All @@ -33,11 +47,11 @@ export const findTSLintConfiguration = async (
]);

if (reportedConfiguration instanceof Error) {
if (reportedConfiguration.message.includes("unknown option `--print-config")) {
return new Error("TSLint v5.18 required. Please update your version.");
}

return reportedConfiguration;
return (
knownErrors.find(([knownError]) =>
reportedConfiguration.message.includes(knownError),
)?.[1](filePath) ?? reportedConfiguration
);
}

if (rawConfiguration instanceof Error) {
Expand Down
18 changes: 18 additions & 0 deletions src/input/findTslintConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ describe("findTSLintConfiguration", () => {
);
});

it("replaces an error with a file-not-found complaint when the file path is not found", async () => {
// Arrange
const stderr = "Could not find configuration path.";
const dependencies = createStubDependencies({
exec: createStubThrowingExec({ stderr }),
});

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

// Assert
expect(result).toEqual(
expect.objectContaining({
message: `Could not find your TSLint configuration file at './tslint.json'. Try providing a different --tslint path.`,
}),
);
});

it("defaults the configuration file when one isn't provided", async () => {
// Arrange
const dependencies = createStubDependencies({
Expand Down