Skip to content

Commit fd1aedf

Browse files
author
Josh Goldberg
authored
Added explicit error for a missing TSLint configuration file (#827)
1 parent 6813eb0 commit fd1aedf

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/input/findTSLintConfiguration.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ export type FindTSLintConfigurationDependencies = {
1818
importer: SansDependencies<typeof importer>;
1919
};
2020

21+
const knownErrors = [
22+
[
23+
"unknown option `--print-config",
24+
() => new Error("TSLint v5.18 required. Please update your version."),
25+
],
26+
[
27+
"Could not find configuration path.",
28+
(filePath: string) =>
29+
new Error(
30+
`Could not find your TSLint configuration file at '${filePath}'. Try providing a different --tslint path.`,
31+
),
32+
],
33+
] as const;
34+
2135
export const findTSLintConfiguration = async (
2236
dependencies: FindTSLintConfigurationDependencies,
2337
config: string | undefined,
@@ -33,11 +47,11 @@ export const findTSLintConfiguration = async (
3347
]);
3448

3549
if (reportedConfiguration instanceof Error) {
36-
if (reportedConfiguration.message.includes("unknown option `--print-config")) {
37-
return new Error("TSLint v5.18 required. Please update your version.");
38-
}
39-
40-
return reportedConfiguration;
50+
return (
51+
knownErrors.find(([knownError]) =>
52+
reportedConfiguration.message.includes(knownError),
53+
)?.[1](filePath) ?? reportedConfiguration
54+
);
4155
}
4256

4357
if (rawConfiguration instanceof Error) {

src/input/findTslintConfiguration.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ describe("findTSLintConfiguration", () => {
6767
);
6868
});
6969

70+
it("replaces an error with a file-not-found complaint when the file path is not found", async () => {
71+
// Arrange
72+
const stderr = "Could not find configuration path.";
73+
const dependencies = createStubDependencies({
74+
exec: createStubThrowingExec({ stderr }),
75+
});
76+
77+
// Act
78+
const result = await findTSLintConfiguration(dependencies, undefined);
79+
80+
// Assert
81+
expect(result).toEqual(
82+
expect.objectContaining({
83+
message: `Could not find your TSLint configuration file at './tslint.json'. Try providing a different --tslint path.`,
84+
}),
85+
);
86+
});
87+
7088
it("defaults the configuration file when one isn't provided", async () => {
7189
// Arrange
7290
const dependencies = createStubDependencies({

0 commit comments

Comments
 (0)