Skip to content

Commit 4bedb3d

Browse files
author
Josh Goldberg
authored
Added recommended --prettier flag to include eslint-config-prettier (#412)
* Made extending eslint-config-prettier built-in, with --ugly flag to opt out * Switched to --prettier * Switched to --prettier and normalized output * Moved to a rcommendation printed in reporting * Removed typings from .gitignore * Described --prettier behavior in README.md * Wording nit: 'when' * A few more cleanups, why not... * Ok last one * Agh, found a README.md typo: 'have'
1 parent 4165d5c commit 4bedb3d

23 files changed

+300
-72
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.tsbuildinfo
22
*.d.ts
3+
!src/typings/**/*.d.ts
34
*.log
45
*.map
56
coverage/

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Each of these flags is optional:
4646
- **[`editor`](#editor)**: Path to an editor configuration file to convert linter settings within.
4747
- **[`eslint`](#eslint)**: Path to an ESLint configuration file to read settings from.
4848
- **[`package`](#package)**: Path to a package.json file to read dependencies from.
49+
- **[`prettier`](#prettier)**: Add `eslint-config-prettier` to the plugins list.
4950
- **[`tslint`](#tslint)**: Path to a TSLint configuration file to read settings from.
5051
- **[`typescript`](#typescript)**: Path to a TypeScript configuration file to read TypeScript compiler options from.
5152

@@ -97,6 +98,22 @@ _Default: `package.json`_
9798
Path to a `package.json` file to read dependencies from.
9899
This will help inform the generated ESLint configuration file's [env](https://eslint.org/docs/user-guide/configuring#specifying-parser-options) settings.
99100

101+
#### `prettier`
102+
103+
```shell
104+
npx tslint-to-eslint-config --prettier
105+
```
106+
107+
_Default: `false`_
108+
109+
Add [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) to the list of ESLint plugins.
110+
We [highly recommend](./docs/FAQs.md#should-i-use-prettier) you use [Prettier](http://prettier.io) for code formatting.
111+
112+
When `--prettier` isn't enabled:
113+
114+
- If the output configuration already doesn't enable any formatting rules, it'll extend from `eslint-config-prettier`.
115+
- Otherwise, a CLI message will suggest running with `--prettier`.
116+
100117
#### `tslint`
101118

102119
```shell

docs/Architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Within `src/conversion/convertConfig.ts`, the following steps occur:
1414
1. Existing configurations are read from disk
1515
2. TSLint rules are converted into their ESLint configurations
1616
3. ESLint configurations are simplified based on extended ESLint and TSLint presets
17+
- 3a. If no output rules conflict with `eslint-config-prettier`, it's added in
1718
4. The simplified configuration is written to the output config file
1819
5. A summary of the results is printed to the user's console
1920

package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"chalk": "4.0.0",
1414
"commander": "5.1.0",
15+
"eslint-config-prettier": "^6.11.0",
1516
"strip-json-comments": "3.1.0",
1617
"tslint": "6.1.1",
1718
"typescript": "3.8.3"
@@ -28,7 +29,6 @@
2829
"@typescript-eslint/parser": "2.29.0",
2930
"babel-jest": "25.4.0",
3031
"eslint": "6.8.0",
31-
"eslint-config-prettier": "6.11.0",
3232
"husky": "4.2.5",
3333
"jest": "25.4.0",
3434
"lint-staged": "10.1.7",

src/cli/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
convertEditorConfig,
1111
ConvertEditorConfigDependencies,
1212
} from "../conversion/convertEditorConfig";
13+
import { addPrettierExtensions } from "../creation/simplification/prettier/addPrettierExtensions";
1314
import { removeExtendsDuplicatedRules } from "../creation/simplification/removeExtendsDuplicatedRules";
1415
import {
1516
retrieveExtendsValues,
@@ -103,6 +104,7 @@ const retrieveExtendsValuesDependencies: RetrieveExtendsValuesDependencies = {
103104
};
104105

105106
const simplifyPackageRulesDependencies: SimplifyPackageRulesDependencies = {
107+
addPrettierExtensions,
106108
removeExtendsDuplicatedRules,
107109
retrieveExtendsValues: bind(retrieveExtendsValues, retrieveExtendsValuesDependencies),
108110
};

src/cli/runCli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ export const runCli = async (
2020
const command = new Command()
2121
.usage("[options] <file ...> --language [language]")
2222
.option("--config [config]", "eslint configuration file to output to")
23+
.option("--editor [editor]", "editor configuration file to convert")
2324
.option("--eslint [eslint]", "eslint configuration file to convert using")
2425
.option("--package [package]", "package configuration file to convert using")
26+
.option("--prettier [prettier]", "add eslint-config-prettier to the plugins list")
2527
.option("--tslint [tslint]", "tslint configuration file to convert using")
2628
.option("--typescript [typescript]", "typescript configuration file to convert using")
27-
.option("--editor [editor]", "editor configuration file to convert")
2829
.option("-V --version", "output the package version");
2930

3031
const parsedArgv = {

src/conversion/conversionResults.stubs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { EditorSettingConversionResults } from "../editorSettings/convertEditorSettings";
2-
import { RuleConversionResults } from "../rules/convertRules";
2+
import { SimplifiedResultsConfiguration } from "../creation/simplification/simplifyPackageRules";
33

44
export const createEmptyConversionResults = (
5-
overrides: Partial<RuleConversionResults> = {},
6-
): RuleConversionResults => ({
5+
overrides: Partial<SimplifiedResultsConfiguration> = {},
6+
): SimplifiedResultsConfiguration => ({
77
converted: new Map(),
88
failed: [],
99
missing: [],

src/conversion/convertConfig.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const createStubDependencies = (
1717
simplifyPackageRules: async (_configurations, data) => ({
1818
...data,
1919
converted: new Map(),
20+
extends: [],
2021
failed: [],
22+
missing: [],
23+
plugins: new Set(),
2124
}),
2225
writeConversionResults: jest.fn().mockReturnValue(Promise.resolve()),
2326
...overrides,

src/conversion/convertConfig.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ export const convertConfig = async (
3434
);
3535

3636
// 3. ESLint configurations are simplified based on extended ESLint and TSLint presets
37-
const simplifiedConfiguration = {
38-
...ruleConversionResults,
39-
...(await dependencies.simplifyPackageRules(
40-
originalConfigurations.data.eslint,
41-
originalConfigurations.data.tslint,
42-
ruleConversionResults,
43-
)),
44-
};
37+
const simplifiedConfiguration = await dependencies.simplifyPackageRules(
38+
originalConfigurations.data.eslint,
39+
originalConfigurations.data.tslint,
40+
ruleConversionResults,
41+
settings.prettier,
42+
);
4543

4644
// 4. The simplified configuration is written to the output config file
4745
const fileWriteError = await dependencies.writeConversionResults(

0 commit comments

Comments
 (0)