-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: writing TypeScript config file (#2114)
## PR Checklist - [x] Addresses an existing open issue: fixes #2113 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/TypeStat/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/TypeStat/blob/main/.github/CONTRIBUTING.md) were taken ## Overview - Fixes issue where `null` was inserted to typestat.json `includes` list - Fixes issue where option was `inferableTypes` when it should be `noInferableTypes` - Added basic testing for config generation For future: - Config generation is still little bit broken. If I want to select just "Remove type annotations that don't change the meaning of code" option, the generated config file does not have it but instead has just `"incompleteTypes": true`. -> Needs new issue created. 🐙
- Loading branch information
1 parent
3c740f7
commit 90ef5e5
Showing
4 changed files
with
160 additions
and
72 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/initialization/initializeTypeScript/writeMultiTypeScriptConfig.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { InitializationImprovement } from "./improvements.js"; | ||
import { generateMultiTypeScriptConfig } from "./writeMultiTypeScriptConfig.js"; | ||
|
||
describe("writeMultiTypeScriptConfig", () => { | ||
it("creates multi TypeScript config", () => { | ||
const config = generateMultiTypeScriptConfig({ | ||
fileName: "typestat.json", | ||
improvements: new Set([ | ||
InitializationImprovement.MissingProperties, | ||
InitializationImprovement.NoImplicitAny, | ||
InitializationImprovement.NoImplicitThis, | ||
InitializationImprovement.NoInferableTypes, | ||
InitializationImprovement.StrictNullChecks, | ||
]), | ||
project: { filePath: "./tsconfig.json" }, | ||
testFiles: "test/**/*.{ts,tsx}", | ||
}); | ||
|
||
expect(config).toStrictEqual([ | ||
{ | ||
fixes: { | ||
incompleteTypes: true, | ||
noImplicitAny: true, | ||
noImplicitThis: true, | ||
noInferableTypes: true, | ||
strictNonNullAssertions: true, | ||
}, | ||
include: ["test/**/*.{ts,tsx}"], | ||
projectPath: "./tsconfig.json", | ||
types: { | ||
strictNullChecks: true, | ||
}, | ||
}, | ||
{ | ||
fixes: { | ||
incompleteTypes: true, | ||
noImplicitAny: true, | ||
noImplicitThis: true, | ||
noInferableTypes: true, | ||
}, | ||
include: undefined, | ||
projectPath: "./tsconfig.json", | ||
}, | ||
{ | ||
fixes: { | ||
incompleteTypes: true, | ||
noImplicitAny: true, | ||
noImplicitThis: true, | ||
noInferableTypes: true, | ||
}, | ||
include: ["test/**/*.{ts,tsx}"], | ||
projectPath: "./tsconfig.json", | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/initialization/initializeTypeScript/writeSingleTypeScriptConfig.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { InitializationImprovement } from "./improvements.js"; | ||
import { generateSingleTypeScriptConfig } from "./writeSingleTypeScriptConfig.js"; | ||
|
||
describe("writeMultiTypeScriptConfig", () => { | ||
it("creates multi TypeScript config", () => { | ||
const config = generateSingleTypeScriptConfig({ | ||
fileName: "typestat.json", | ||
improvements: new Set([InitializationImprovement.NoImplicitAny]), | ||
project: { filePath: "./tsconfig.json" }, | ||
}); | ||
|
||
expect(config).toStrictEqual({ | ||
fixes: { | ||
incompleteTypes: true, | ||
noImplicitAny: true, | ||
}, | ||
include: undefined, | ||
projectPath: "./tsconfig.json", | ||
}); | ||
|
||
expect(JSON.stringify(config)).toBe( | ||
'{"fixes":{"incompleteTypes":true,"noImplicitAny":true},"projectPath":"./tsconfig.json"}', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters