check method

  1. @override
void check(
  1. Brick brick
)
override

Validates the brick.yaml file

Implementation

@override
void check(Brick brick) {
  if (!shouldSync) {
    return;
  }

  final brickOvenFileName = brick.configPath ?? 'brick_oven.yaml';

  var isInSync = true;

  final brickYaml = brickYamlContent();

  if (brickYaml.isEmpty) {
    return;
  }

  if (brick.name != brickYaml['name']) {
    isInSync = false;
    di<Logger>().warn(
      '`name` (${brickYaml['name']}) in brick.yaml does not '
      'match the name in $brickOvenFileName (${brick.name})',
    );
  }

  final varsRaw = brickYaml['vars'];
  Iterable<String> vars = [];
  if (varsRaw is Map) {
    vars = varsRaw.keys.map((e) => '$e');
  } else if (varsRaw is List) {
    vars = varsRaw.map((e) => '$e');
  }

  final alwaysRemove = ['', ...Constants.variablesToIgnore, ...ignoreVars];

  final variables = {...brick.vars.expand((e) => e.split('.'))}
    ..removeAll(alwaysRemove);

  final variablesInBrickYaml = {...vars}..removeAll(alwaysRemove);

  if (variablesInBrickYaml.difference(variables).isNotEmpty) {
    isInSync = false;
    final vars =
        '"${variablesInBrickYaml.difference(variables).join('", "')}"';
    di<Logger>().warn(
      'Variables ($vars) exist in brick.yaml but not in $brickOvenFileName',
    );
  }

  if (variables.difference(variablesInBrickYaml).isNotEmpty) {
    isInSync = false;
    final vars =
        '"${variables.difference(variablesInBrickYaml).join('", "')}"';

    di<Logger>().warn(
      'Variables ($vars) exist in $brickOvenFileName but not in brick.yaml',
    );
  }

  if (isInSync) {
    di<Logger>().info(darkGray.wrap('brick.yaml is in sync'));
  } else {
    di<Logger>().err('brick.yaml is out of sync');
  }
}