-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(null): switch strictNullChecks config from opt-in to opt-out fo…
…r new files (#6284) #### Details This PR updates our strictNullChecks config and tooling to include all non-test `.ts` and `.tsx` files in the strict null checks set by default, only excluding those files explicitly marked as having known issues in `tsconfig.strictNullChecks.json`. This: * Simplifies the `strictNullChecks` config file a lot (it reduces the size by half and is now a flat list of files instead of a mix of files and glob patterns) * Saves a step of having to manually run `yarn null:autoadd` for most changes, since new files are now implicitly added * Removes the corresponding item from our PR checklist (I left the automated PR check in place since it doesn't hurt anything and has a self-descriptive error message if it does fail) To implement this, I wrote a script to perform the conversion from an include list to an exclude list. I included it for review in this PR, but I don't expect it to need to be run again in the future. I verified that `yarn null:progress` reports finding the same counts of checked and eligible files before and after the change: > ## Web strict-null progress > **81%** complete (**1273**/1562 non-test files) > *Contribute at [#2869](#2869). Last update: Tue Dec 20 2022* I ensured that the assorted helper scripts (`yarn null:find`, `yarn null:autoadd`, `yarn null:check`) all still work as expected. ##### Motivation #2869 and see above ##### Context I considered renaming `autoadd` to something else now that it's arguably "removing an exclusion" rather than "adding an inclusion", but I decided to leave it as it; it's still "adding new files to the strict null checked set" and it felt like more work/confusion than it was worth to try to update all the issues/team working knowledge/etc about it. #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [x] Addresses an existing issue: #2869 - ~~[x] Ran `yarn null:autoadd`~~ - [x] Ran `yarn fastpass` - [n/a] Added/updated relevant unit test(s) (and ran `yarn test`) - [n/a] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`. - [n/a] (UI changes only) Added screenshots/GIFs to description above - [n/a] (UI changes only) Verified usability with NVDA/JAWS
- Loading branch information
Showing
7 changed files
with
359 additions
and
730 deletions.
There are no files selected for viewing
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
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
85 changes: 0 additions & 85 deletions
85
tools/strict-null-checks/collapse-completed-directories.js
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// @ts-check | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const config = require('./config'); | ||
const { getAllCheckedFiles, getAllEligibleFiles } = require('./eligible-file-finder'); | ||
const { writeTsConfig } = require('./write-tsconfig'); | ||
|
||
const repoRoot = config.repoRoot; | ||
const tsconfigPath = path.join(repoRoot, config.targetTsconfig); | ||
|
||
async function main() { | ||
const excludeList = await buildExcludeList(); | ||
const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath).toString()); | ||
|
||
delete tsconfig.files; | ||
tsconfig.include = ['src/**/*.ts', 'src/**/*.tsx']; | ||
tsconfig.exclude = ['**/*.test.ts', '**/*.test.tsx', ...excludeList]; | ||
|
||
await writeTsConfig(tsconfigPath, tsconfig); | ||
} | ||
|
||
async function buildExcludeList() { | ||
const checkedFiles = await getAllCheckedFiles(); | ||
const eligibleFiles = await getAllEligibleFiles(); | ||
|
||
const allUncheckedFiles = eligibleFiles.filter(file => !checkedFiles.has(file)); | ||
|
||
allUncheckedFiles.sort(); | ||
|
||
return allUncheckedFiles.map(file => path.relative(repoRoot, file).replace(/\\/g, '/')); | ||
} | ||
|
||
main().catch(error => { | ||
console.error(error.stack); | ||
process.exit(1); | ||
}); |
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
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const prettier = require('prettier'); | ||
|
||
module.exports = { | ||
writeTsconfigSync: (tsconfigPath, content) => { | ||
writeTsConfig: async (tsconfigPath, content) => { | ||
let serializedContent = JSON.stringify(content, null, ' '); | ||
serializedContent += '\n'; | ||
|
||
fs.writeFileSync(tsconfigPath, serializedContent); | ||
let prettierConfigPath = path.join(__dirname, '..', '..', 'prettier.config.js'); | ||
let prettierConfig = await prettier.resolveConfig(prettierConfigPath); | ||
let formattedContent = prettier.format(serializedContent, { | ||
...prettierConfig, | ||
filepath: tsconfigPath, | ||
}); | ||
|
||
fs.writeFileSync(tsconfigPath, formattedContent); | ||
}, | ||
}; |
Oops, something went wrong.