Print out the lengths of switch statements in code. Usage example:
find . -type f -name "*.ts" -not -path "*node_modules*" -not -path "*.git*" | ./switch-lengths.py | sort -n -r | head -n 10
Also handles match
statements (Rust).
Warning: match
can be a false positive in languages where switch
is a reserved word, and vice versa.
Example output:
$ find esbuild -name "*.go" | ./switch-lengths.py | sort -n -r | head -n 10
2329 esbuild/internal/js_parser/js_parser.go:12778-15106
1248 esbuild/internal/js_printer/js_printer.go:1989-3236
1220 esbuild/internal/js_parser/js_parser.go:6842-8061
1104 esbuild/internal/js_parser/js_parser.go:9971-11074
864 esbuild/pkg/cli/cli_impl.go:94-957
795 esbuild/internal/js_printer/js_printer.go:3993-4787
686 esbuild/internal/js_parser/js_parser.go:4101-4786
617 esbuild/internal/js_lexer/js_lexer.go:1016-1632
600 esbuild/internal/js_parser/js_parser.go:3326-3925
429 esbuild/internal/js_parser/js_parser.go:15287-15715