getDartFormatter function

DartFormatter getDartFormatter(
  1. String outputDirPath
)

根据 outputDirPath 向上查找项目根目录,读取 analysis_options.yaml 中的 formatter 配置(page_width、trailing_commas)以及 pubspec.yaml 中的语言版本, 创建并缓存对应的 DartFormatter

Implementation

DartFormatter getDartFormatter(String outputDirPath) {
  final projectRoot = _findProjectRoot(outputDirPath);
  final cacheKey = projectRoot ?? outputDirPath;
  return _formatterCache.putIfAbsent(
      cacheKey, () => _buildFormatter(projectRoot));
}