Skip to content

Commit cce3475

Browse files
author
Josh Goldberg
authored
Updated docs/Editors.md for new system (#757)
1 parent dde88c8 commit cce3475

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

docs/Architecture/Editors.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Editors
22

3-
Editor lint configurations are converted by `src/converters/editorConfigs/convertEditorConfig.ts`.
4-
Any setting that matches a known built-in TSLint setting will be replaced with the ESLint equivalent.
3+
Editor lint configurations are converted by `src/converters/editorConfigs/convertEditorConfigs.ts`, which calls to a neighboring `convertEditorConfig.ts` on each file path.
54

6-
For now, only VS Code editor settings are accounted for.
7-
Eventually this will be refactored to allow other editors such as Atom.
8-
9-
1. An existing editor configuration is read from disk.
10-
2. If the existing configuration is not found or errored, nothing else needs to be done.
11-
3. Configuration settings are converted to their ESLint equivalents.
12-
4. Those ESLint equivalents are written to the configuration file.
13-
5. Results from converting are reported to the user.
5+
1. Requested `--editor` paths are deduplicated into the list of file paths to convert.
6+
2. Each path is mapped, if possible, to its editor's converter function.
7+
3. Results from calling `convertEditorConfig` on that file and configuration are stored.
8+
a. The requested path's contents are read from disk.
9+
b. That converter function is run on the file path.
10+
c. If no error occurred, the description of changed settings is reported.
11+
3. Results of converting are reported to the console and back to the calling code.

src/converters/editorConfigs/convertEditorConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ export type ConvertEditorConfigDependencies = {
66
fileSystem: Pick<FileSystem, "readFile" | "writeFile">;
77
};
88

9+
/**
10+
* @see /docs/Editors.md for documentation.
11+
*/
912
export const convertEditorConfig = async (
1013
dependencies: ConvertEditorConfigDependencies,
1114
converter: EditorConfigConverter,
1215
requestedPath: string,
1316
settings: TSLintToESLintSettings,
1417
) => {
18+
// 3a. The requested path's contents are read from disk.
1519
const originalFileContents = await dependencies.fileSystem.readFile(requestedPath);
1620
if (originalFileContents instanceof Error) {
1721
return originalFileContents;
1822
}
1923

24+
// 3b. That converter function is run on the file path.
2025
const conversion = converter(originalFileContents, settings);
26+
27+
// 3c. If no error occurred, the description of changed settings is reported.
2128
const error = await dependencies.fileSystem.writeFile(requestedPath, conversion.contents);
2229

2330
return error ?? conversion;

src/converters/editorConfigs/convertEditorConfigs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type ConvertEditorConfigsDependencies = {
1212
typeof reportEditorConfigConversionResults
1313
>;
1414
};
15+
16+
/**
17+
* @see /docs/Editors.md for documentation.
18+
*/
1519
export const convertEditorConfigs = async (
1620
dependencies: ConvertEditorConfigsDependencies,
1721
settings: TSLintToESLintSettings,
@@ -20,10 +24,13 @@ export const convertEditorConfigs = async (
2024
failed: new Map(),
2125
successes: new Map(),
2226
};
27+
28+
// 1. Requested `--editor` paths are deduplicated into the list of file paths to convert.
2329
const requestedPaths = uniqueFromSources(settings.editor);
2430

2531
await Promise.all(
2632
requestedPaths.map(async (requestedPath) => {
33+
// 2. Each path is mapped, if possible, to its editor's converter function.
2734
const descriptor = dependencies.editorConfigDescriptors.find(([defaultPath]) =>
2835
defaultPathMatches(defaultPath, requestedPath),
2936
);
@@ -35,6 +42,7 @@ export const convertEditorConfigs = async (
3542
return;
3643
}
3744

45+
// 3. Results from calling `convertEditorConfig` on that file and configuration are stored.
3846
const result = await dependencies.convertEditorConfig(
3947
descriptor[1],
4048
requestedPath,
@@ -49,6 +57,7 @@ export const convertEditorConfigs = async (
4957
}),
5058
);
5159

60+
// 4. Results of converting are reported to the console and back to the calling code.
5261
dependencies.reportEditorConfigConversionResults(results);
5362

5463
return results.failed.size === 0

0 commit comments

Comments
 (0)