Skip to content

Instantly share code, notes, and snippets.

@rjz
Created February 26, 2021 18:41
Show Gist options
  • Select an option

  • Save rjz/2d6c735facd619dc9296bc59fcb09324 to your computer and use it in GitHub Desktop.

Select an option

Save rjz/2d6c735facd619dc9296bc59fcb09324 to your computer and use it in GitHub Desktop.

Revisions

  1. rjz created this gist Feb 26, 2021.
    24 changes: 24 additions & 0 deletions strict_null_checks.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash

    # Brute force search for TypeScript files in the current directory that fail
    # the `--strictNullChecks` flag. YMMV.

    # edit this function to exclude files that _shouldn't_ be checked.
    filter_defs() {
    grep -v node_modules \
    | grep -v '.d.ts$' \
    | sort \
    | uniq
    }

    TS_FLAGS='--strictNullChecks --outDir=/dev/null'

    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")