Created
January 6, 2023 15:36
-
-
Save rohan20/60a5b4b2a4b42982f541437f7ead593d to your computer and use it in GitHub Desktop.
measure-flutter-dart-sound-null-safety-migration-progress
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
# Measures sound-null-safety migration progress. | |
# | |
# Does so by checking total number of dart files and number of Dart files with the either of the following 3 statements: | |
# - "// @dart=2.9" | |
# - "// ignore: import_of_legacy_library_into_null_safe" | |
# - "// ignore_for_file: import_of_legacy_library_into_null_safe" | |
import itertools | |
import os | |
import sys | |
dart_files_count = 0 | |
dart_files_with_unsound_null_safety_count = 0 | |
lib_path = os.path.abspath(__file__ + "/../../lib") | |
test_path = os.path.abspath(__file__ + "/../../test") | |
for subdir, dirs, files in itertools.chain(os.walk(lib_path), os.walk(test_path)): | |
for file in files: | |
filepath = subdir + os.sep + file | |
if filepath.endswith(".dart"): | |
dart_files_count += 1 | |
print(filepath) | |
with open(filepath, 'r') as dart_file: | |
dart_file_read = dart_file.read() | |
fileHasDart2Dot9Comment = "// @dart=2.9\n" in dart_file_read | |
fileHasAIgnoreImportOfLegacyLibraryIntoNullSafeComment = \ | |
"// ignore: import_of_legacy_library_into_null_safe" in dart_file_read | |
fileHasAIgnoreForFileImportOfLegacyLibraryIntoNullSafeComment = \ | |
"// ignore_for_file: import_of_legacy_library_into_null_safe" in dart_file_read | |
if fileHasDart2Dot9Comment or fileHasAIgnoreImportOfLegacyLibraryIntoNullSafeComment or fileHasAIgnoreForFileImportOfLegacyLibraryIntoNullSafeComment: # noqa: E501 (This comment ignores the line length warning) | |
dart_files_with_unsound_null_safety_count += 1 | |
print(f"\nDart files count: {dart_files_count}") | |
print(f"Dart files with unsound null safety count: {dart_files_with_unsound_null_safety_count}") | |
dart_files_with_sound_null_safety_count = dart_files_count - dart_files_with_unsound_null_safety_count | |
sound_null_safety_migration_progress = dart_files_with_sound_null_safety_count * 100 / dart_files_count | |
sound_null_safety_migration_progress_rounded = str(round(sound_null_safety_migration_progress, 2)) | |
print(f"\nSound null safety migration progress: {sound_null_safety_migration_progress_rounded}%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment