Skip to content

ugly inline #60169

@stephane-archer

Description

@stephane-archer

input code:

  @override
  Future<List<String>?> getSavedLutFolders() async {
    final SharedPreferences sharedPreferences = await _sharedPreferences;
    final List<String>? bookmarks =
        sharedPreferences.getStringList(_sharedPreferencesKey);
    if (bookmarks == null) {
      return null;
    }

    List<String> result = [];
    for (var bookmark in bookmarks) {
      try {
        final path = await _bookmarkToPath(bookmark);
        result.add(path);
      } catch (e) {
        log("Error while resolving MacOS sandbox bookmark: $e");
        await _rmBadBookmark(bookmark, bookmarks, sharedPreferences);
      }
    }
    return result;
  }

  Future<void> _rmBadBookmark(
    String bookmarkToRemove,
    List<String> bookmarks,
    SharedPreferences sharedPreferences,
  ) async {
    bookmarks.remove(bookmarkToRemove);
    await sharedPreferences.setStringList(_sharedPreferencesKey, bookmarks);
  }

inline _rmBadBookmark

result code:

 @override
  Future<List<String>?> getSavedLutFolders() async {
    final SharedPreferences sharedPreferences = await _sharedPreferences;
    final List<String>? bookmarks =
        sharedPreferences.getStringList(_sharedPreferencesKey);
    if (bookmarks == null) {
      return null;
    }

    List<String> result = [];
    for (var bookmark in bookmarks) {
      try {
        final path = await _bookmarkToPath(bookmark);
        result.add(path);
      } catch (e) {
        log("Error while resolving MacOS sandbox bookmark: $e");
        await (
          String bookmarkToRemove,
          List<String> bookmarks,
          SharedPreferences sharedPreferences,
        ) async {
          bookmarks.remove(bookmarkToRemove);
          await sharedPreferences.setStringList(_sharedPreferencesKey, bookmarks);
        }(bookmark, bookmarks, sharedPreferences);
      }
    }
    return result;
  }

expected code:

  @override
  Future<List<String>?> getSavedLutFolders() async {
    final SharedPreferences sharedPreferences = await _sharedPreferences;
    final List<String>? bookmarks =
        sharedPreferences.getStringList(_sharedPreferencesKey);
    if (bookmarks == null) {
      return null;
    }

    List<String> result = [];
    for (var bookmark in bookmarks) {
      try {
        final path = await _bookmarkToPath(bookmark);
        result.add(path);
      } catch (e) {
        log("Error while resolving MacOS sandbox bookmark: $e");
          bookmarks.remove(bookmark);
          await sharedPreferences.setStringList(_sharedPreferencesKey, bookmarks);
      }
    }
    return result;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactoringIssues with analysis server refactoringstype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions