Skip to content

Instantly share code, notes, and snippets.

@rjz
Created February 12, 2020 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjz/9161a1ce0adbc82bec6d254d5f5ceccb to your computer and use it in GitHub Desktop.
Save rjz/9161a1ce0adbc82bec6d254d5f5ceccb to your computer and use it in GitHub Desktop.
List of strict null-checked files inside a TypeScript project
#!/bin/bash
# Returns a list of strict null-checked files inside the current directory.
# Useful for gradually introducing the `--strictNullCheck` flag to a
# TypeScript project.
#
# See: https://code.visualstudio.com/blogs/2019/05/23/strict-null
TS_FLAGS='--strictNullChecks --outDir=/dev/null'
filter_defs() {
grep -v node_modules \
| grep -v '.d.ts$' \
| sort \
| uniq
}
TS_FILES=$(find . -name '*.ts' \
| cut -d/ -f2- \
| filter_defs)
TS_ERRORS=$(yarn tsc --noEmit $TS_FLAGS 2> /dev/null \
| grep -o '.*\.ts[x]*([0-9,]*): error' \
| cut -d\( -f1 \
| filter_defs)
comm -23 <(echo "$TS_FILES") <(echo "$TS_ERRORS")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment