Skip to content

Commit 73e9042

Browse files
Fix tsc again; start on docs
1 parent 824b795 commit 73e9042

File tree

6 files changed

+92
-28
lines changed

6 files changed

+92
-28
lines changed

docs/Architecture/Comments.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Comments
2+
3+
Comment conversions in `src/converters/comments/convertComments.ts` are the last root-level converter to be run.
4+
The `ruleEquivalents` map it receives is filled out with the rule equivalents from earlier converters, i.e. lint rule converters.
5+
6+
In general, its flow is:
7+
8+
1. If no comments are requested to be converted, immediately report it out and mark this as passed.
9+
2. Create the list of include and possibly exclude globs to search on.
10+
3. Search for files matching those globs to have their comments converted.
11+
4. Convert comments in the contents of each file, storing equivalents in a cache.
12+
5. Report out the results of converting the unique globbed file paths.
13+
14+
## File Manipulations
15+
16+
Source files are parsed into TypeScript files by `src/comments/parseFileComments.ts`, which then extracts their comment nodes.
17+
Those comments are parsed for TSLint rule disable or enable comments.
18+
19+
Comments that match will be rewritten in their their file to their new ESLint rule equivalent in `src/comments/replaceFileComments.ts`, as determined by:
20+
21+
1. First, if the `ruleEquivalents` cache received from configuration convertion has the TSLint rule's ESLint equivalents listed, those are used.
22+
2. Failing that, a comment-specific `ruleCommentsCache` is populated with rules converted ad-hoc with no arguments.

docs/Architecture/Linters.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Linters
2+
3+
4+
Within `src/converters/lintConfigs/convertLintConfig.ts`, the following steps occur:
5+
6+
1. Existing configurations are read from disk
7+
2. TSLint rules are converted into their ESLint configurations
8+
3. ESLint configurations are summarized based on extended ESLint and TSLint presets
9+
- 3a. If no output rules conflict with `eslint-config-prettier`, it's added in
10+
- 3b. Any ESLint rules that are configured the same as an extended preset are trimmed
11+
4. The summarized configuration is written to the output config file
12+
5. Files to transform comments in have source text rewritten using the cached rule conversion results
13+
6. A summary of the results is printed to the user's console
14+
15+
### Conversion Results
16+
17+
The overall configuration generated by steps 2-3 and printed in 4-5 contains the following information:
18+
19+
### Rule Converters
20+
21+
Each TSLint rule should output at least one ESLint rule as the equivalent.
22+
"Converters" for TSLint rules are located in `src/rules/converters/`, and keyed under their names by the map in `src/rules/converters.ts`.
23+
24+
Each converter for a TSLint rule takes an arguments object for the rule, and returns an array of objects containing:
25+
26+
- `rules`: At least one equivalent ESLint rule and options
27+
- `notices`: Any extra info that should be printed after conversion
28+
- `plugins`: Any plugins that should now be installed if not already
29+
30+
The `rules` output is an array of objects containing:
31+
32+
- `ruleName`: Equivalent ESLint rule name that should be enabled
33+
- `ruleArguments`: Any arguments for that ESLint rule
34+
35+
Multiple objects must be supported because some general-use TSLint rules can only be represented by two or more ESLint rules.
36+
For example, TSLint's `no-banned-terms` is represented by ESLint's `no-caller` and `no-eval`.
37+
38+
### Rule Mergers
39+
40+
It's possible that one ESLint rule will be output by multiple converters.
41+
"Mergers" for those ESLint rules should take in two configurations to the same rule and output the equivalent single configuration.
42+
These are located in `src/rules/mergers/`, and keyed under their names by the map in `src/rules/mergers.ts`.
43+
44+
For example, `@typescript-eslint/ban-types` spreads both arguments' `types` members into one large `types` object.

docs/Architecture/Linting.md

Whitespace-only changes.

docs/Architecture/README.md

-11
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ These are located in `src/rules/mergers/`, and keyed under their names by the ma
5151

5252
For example, `@typescript-eslint/ban-types` spreads both arguments' `types` members into one large `types` object.
5353

54-
## Comment Conversion
55-
56-
Comments are converted after rule conversion by `src/comments/convertComments.ts`.
57-
Source files are parsed into TypeScript files by `src/comments/parseFileComments.ts`, which then extracts their comment nodes.
58-
Those comments are parsed for TSLint rule disable or enable comments.
59-
60-
Comments that match will be rewritten in their their file to their new ESLint rule equivalent in `src/comments/replaceFileComments.ts`, as determined by:
61-
62-
1. First, if the `ruleEquivalents` cache received from configuration convertion has the TSLint rule's ESLint equivalents listed, those are used.
63-
2. Failing that, a comment-specific `ruleCommentsCache` is populated with rules converted ad-hoc with no arguments.
64-
6554
## Editor Configuration Conversion
6655

6756
Editor lint configurations are converted by `src/editorSettings/convertEditorSettings.ts`.

src/cli/main.ts

+25-17
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ import { nativeImporter } from "../adapters/nativeImporter";
77
import { processLogger } from "../adapters/processLogger";
88
import { bind } from "../binding";
99
import {
10-
findEditorConfiguration,
11-
FindEditorConfigurationDependencies,
12-
} from "../input/findEditorConfiguration";
13-
import { findESLintConfiguration } from "../input/findESLintConfiguration";
14-
import {
15-
findOriginalConfigurations,
16-
FindOriginalConfigurationsDependencies,
17-
} from "../input/findOriginalConfigurations";
18-
import { findPackagesConfiguration } from "../input/findPackagesConfiguration";
19-
import { findTSLintConfiguration } from "../input/findTSLintConfiguration";
20-
import { findTypeScriptConfiguration } from "../input/findTypeScriptConfiguration";
21-
import { importer, ImporterDependencies } from "../input/importer";
22-
import { mergeLintConfigurations } from "../input/mergeLintConfigurations";
10+
collectCommentFileNames,
11+
CollectCommentFileNamesDependencies,
12+
} from "../comments/collectCommentFileNames";
2313
import {
2414
ReportCommentResultsDependencies,
2515
reportCommentResults,
@@ -81,9 +71,23 @@ import { writeEditorConfigConversionResults } from "../converters/lintConfigs/wr
8171
import { addPrettierExtensions } from "../converters/lintConfigs/summarization/prettier/addPrettierExtensions";
8272
import { removeExtendsDuplicatedRules } from "../converters/lintConfigs/pruning/removeExtendsDuplicatedRules";
8373
import {
84-
collectCommentFileNames,
85-
CollectCommentFileNamesDependencies,
86-
} from "../comments/collectCommentFileNames";
74+
ExtractGlobPathsDependencies,
75+
extractGlobPaths,
76+
} from "../converters/comments/extractGlobPaths";
77+
import {
78+
findEditorConfiguration,
79+
FindEditorConfigurationDependencies,
80+
} from "../input/findEditorConfiguration";
81+
import { findESLintConfiguration } from "../input/findESLintConfiguration";
82+
import {
83+
findOriginalConfigurations,
84+
FindOriginalConfigurationsDependencies,
85+
} from "../input/findOriginalConfigurations";
86+
import { findPackagesConfiguration } from "../input/findPackagesConfiguration";
87+
import { findTSLintConfiguration } from "../input/findTSLintConfiguration";
88+
import { findTypeScriptConfiguration } from "../input/findTypeScriptConfiguration";
89+
import { importer, ImporterDependencies } from "../input/importer";
90+
import { mergeLintConfigurations } from "../input/mergeLintConfigurations";
8791

8892
const convertFileCommentsDependencies: ConvertFileCommentsDependencies = {
8993
converters: ruleConverters,
@@ -133,10 +137,14 @@ const collectCommentFileNamesDependencies: CollectCommentFileNamesDependencies =
133137
findTypeScriptConfiguration: bind(findTypeScriptConfiguration, findConfigurationDependencies),
134138
};
135139

140+
const extractGlobPathsDependencies: ExtractGlobPathsDependencies = {
141+
globAsync,
142+
};
143+
136144
const convertCommentsDependencies: ConvertCommentsDependencies = {
137145
collectCommentFileNames: bind(collectCommentFileNames, collectCommentFileNamesDependencies),
138146
convertFileComments: bind(convertFileComments, convertFileCommentsDependencies),
139-
globAsync,
147+
extractGlobPaths: bind(extractGlobPaths, extractGlobPathsDependencies),
140148
reportCommentResults: bind(reportCommentResults, reportCommentResultsDependencies),
141149
};
142150

src/converters/comments/convertComments.ts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const convertComments = async (
6565
};
6666
}
6767

68+
// 5. Report out the results of converting the unique globbed file paths.
6869
dependencies.reportCommentResults(uniqueGlobbedFilePaths);
6970

7071
return {

0 commit comments

Comments
 (0)