Repository: typescript-eslint/tslint-to-eslint-config (ts)

Issue:
Errors in writing the output configuration file are ignored
### 🐛 Bug Report

-   `tslint-to-eslint-config` version: 0.1.7
-   ESLint version: N/A
-   Node version: **8.X**

#### Actual Behavior

`npx tslint-to-eslint-config` prints out happy console messages but doesn't signal any error when creating an output `.eslintrc.js` file fails.

#### Expected Behavior

Logging the error and exiting with a non-zero status code would sure be nice!

There's a line something like `await dependencies.writeConfigurationFile(...);` where the result value is ignored. If that write method returns a failure result, that should be returned by `runCli` as a failure result.

#### Reproduction

```
mkdir temp
cd temp
npm init --yes
echo "{}" > tslint.json
npx tslint-to-eslint-config
```

~This will fail silently on **Node 8.X** because of #63. Note that #63 tracks fixing the Node 8 crash; this issue is for correctly logging any failure such as that one.~ Presumably, this issue will come up again if the writing of the configuration file fails for a permissions issue.

Pull request:
Added error reporting for writeConfigurationFile failures
## PR Checklist

-   [x] Addresses an existing issue: fixes #64
-   [x] That issue was marked as [`status: accepting prs`](https://github.com/typescript-eslint/tslint-to-eslint-config/labels/status%3A%20accepting%20prs)

## Overview

The `Error | undefined` result of `dependencies.fileSystem.writeFile` is returned and checked for in `writeConfigurationFile`.

Patch:
diff --git a/.eslintrc.js b/.eslintrc.js
index 23c49bc..bf30114 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -44,6 +44,7 @@ module.exports = {
         "no-empty-function": 0,
         "no-restricted-syntax": 0,
         "no-param-reassign": 0,
+        "no-return-await": 0,
         "no-shadow": 0,
         "no-undef": 0,
         "no-useless-constructor": 0,
diff --git a/src/conversion/convertConfig.ts b/src/conversion/convertConfig.ts
index 8091c96..a6308d0 100644
--- a/src/conversion/convertConfig.ts
+++ b/src/conversion/convertConfig.ts
@@ -43,11 +43,17 @@ export const convertConfig = async (
     };
 
     // 4. The simplified configuration is written to the output config file
-    await dependencies.writeConversionResults(
+    const fileWriteError = await dependencies.writeConversionResults(
         settings.config,
         simplifiedConfiguration,
         originalConfigurations.data,
     );
+    if (fileWriteError !== undefined) {
+        return {
+            errors: [fileWriteError],
+            status: ResultStatus.Failed,
+        };
+    }
 
     // 5. A summary of the results is printed to the user's console
     dependencies.reportConversionResults(simplifiedConfiguration);
diff --git a/src/creation/writeConversionResults.ts b/src/creation/writeConversionResults.ts
index 4aeb043..49be3eb 100644
--- a/src/creation/writeConversionResults.ts
+++ b/src/creation/writeConversionResults.ts
@@ -33,5 +33,5 @@ export const writeConversionResults = async (
         rules: formatConvertedRules(ruleConversionResults, originalConfigurations.tslint),
     };
 
-    await dependencies.fileSystem.writeFile(outputPath, formatOutput(outputPath, output));
+    return await dependencies.fileSystem.writeFile(outputPath, formatOutput(outputPath, output));
 };


Test patch:
diff --git a/src/conversion/convertConfig.test.ts b/src/conversion/convertConfig.test.ts
index ddb9735..92a9eb1 100644
--- a/src/conversion/convertConfig.test.ts
+++ b/src/conversion/convertConfig.test.ts
@@ -2,10 +2,18 @@ import { ResultStatus, FailedResult, SucceededDataResult } from "../types";
 import { convertConfig, ConvertConfigDependencies } from "./convertConfig";
 import { OriginalConfigurations } from "../input/findOriginalConfigurations";
 
+const stubSettings = {
+    config: "./eslintrc.js",
+};
+
 const createStubDependencies = (
-    overrides: Pick<ConvertConfigDependencies, "findOriginalConfigurations">,
+    overrides: Partial<ConvertConfigDependencies> = {},
 ): ConvertConfigDependencies => ({
     convertRules: jest.fn(),
+    findOriginalConfigurations: jest.fn().mockResolvedValue({
+        data: createStubOriginalConfigurationsData(),
+        status: ResultStatus.Succeeded,
+    }),
     reportConversionResults: jest.fn(),
     simplifyPackageRules: async (_configurations, data) => data,
     writeConversionResults: jest.fn().mockReturnValue(Promise.resolve()),
@@ -29,32 +37,37 @@ describe("convertConfig", () => {
         const dependencies = createStubDependencies({
             findOriginalConfigurations: async () => findError,
         });
-        const settings = {
-            config: "./eslintrc.js",
-        };
 
         // Act
-        const result = await convertConfig(dependencies, settings);
+        const result = await convertConfig(dependencies, stubSettings);
 
         // Assert
         expect(result).toEqual(findError);
     });
 
-    it("returns a successful result when finding the original configurations succeeds", async () => {
+    it("returns the failure result when writing to the configuration file fails", async () => {
         // Arrange
-        const findSuccess: SucceededDataResult<OriginalConfigurations> = {
-            data: createStubOriginalConfigurationsData(),
-            status: ResultStatus.Succeeded,
-        };
+        const fileWriteError = new Error();
         const dependencies = createStubDependencies({
-            findOriginalConfigurations: async () => findSuccess,
+            writeConversionResults: jest.fn().mockResolvedValueOnce(fileWriteError),
         });
-        const settings = {
-            config: "./eslintrc.js",
-        };
 
         // Act
-        const result = await convertConfig(dependencies, settings);
+        const result = await convertConfig(dependencies, stubSettings);
+
+        // Assert
+        expect(result).toEqual({
+            errors: [fileWriteError],
+            status: ResultStatus.Failed,
+        });
+    });
+
+    it("returns a successful result when finding the original configurations succeeds", async () => {
+        // Arrange
+        const dependencies = createStubDependencies();
+
+        // Act
+        const result = await convertConfig(dependencies, stubSettings);
 
         // Assert
         expect(result).toEqual({