ConfigModel.fromRules constructor

ConfigModel.fromRules(
  1. Map<String, LintOptions> rules
)

Factory constructor to create a ConfigModel from a LintOptions map.

If the map is empty, returns a default configuration. Otherwise, attempts to read the first rule's configuration and parse it. Errors are printed to stdout if parsing fails.

Implementation

factory ConfigModel.fromRules(Map<String, LintOptions> rules) {
  if (rules.isEmpty) return ConfigModel();

  try {
    return ConfigModel.fromMap(
      rules.entries.first.value.json,
    );
  } on Exception catch (error, stackTrace) {
    // Log parsing errors to stdout
    stdout
      ..write(error)
      ..write(stackTrace);
    return ConfigModel();
  }
}