components/sync/PRESUBMIT.py
def CheckModelTypeInfoMap(input_api, output_api, model_type_file):
  """Checks the kModelTypeInfoMap in model_type.cc follows conventions.
  Checks that the kModelTypeInfoMap follows the below rules:
    1) The model type string should match the model type name, but with
       only the first letter capitalized and spaces instead of underscores.
    2) The root tag should be the same as the model type but all lowercase.
    3) The notification type should match the proto message name.
    4) No duplicate data across model types.
   Args:
    input_api: presubmit_support InputApi instance
    output_api: presubmit_support OutputApi instance
    model_type_file: AffectedFile object where the ModelTypeInfoMap is
  Returns:
    A (potentially empty) list PresubmitError objects corresponding to
    violations of the above rules.
  """
  accumulated_problems = []
  map_entries = ParseModelTypeEntries(
    input_api, model_type_file.AbsoluteLocalPath())
  # If any line of the map changed, we check the whole thing since
  # definitions span multiple lines and there are rules that apply across
  # all definitions e.g. no duplicated field values.
  check_map = False
  for line_num, _ in model_type_file.ChangedContents():
    for map_entry in map_entries:
      if line_num in map_entry.affected_lines:
        check_map = True
        break

  if not check_map:
    return []
  proto_field_definitions = ParseEntitySpecificsProtoFieldIdentifiers(
    input_api, os.path.abspath(PROTO_FILE_PATH))
  accumulated_problems.extend(
    CheckNoDuplicatedFieldValues(output_api, map_entries))

  for map_entry in map_entries:
    entry_problems = []
    entry_problems.extend(
      CheckNotificationTypeMatchesProtoMessageName(
        output_api, map_entry, proto_field_definitions))
    entry_problems.extend(CheckRootTagNotInBlocklist(output_api, map_entry))

    if map_entry.model_type not in EXCEPTION_MODEL_TYPES:
      entry_problems.extend(
        CheckModelTypeStringMatchesModelType(output_api, map_entry))
      entry_problems.extend(
        CheckRootTagMatchesModelType(output_api, map_entry))

    if len(entry_problems) > 0:
      accumulated_problems.extend(entry_problems)

  return accumulated_problems
Checks the kModelTypeInfoMap in model_type.cc follows conventions.
  Checks that the kModelTypeInfoMap follows the below rules:
    1) The model type string should match the model type name, but with
       only the first letter capitalized and spaces instead of underscores.
    2) The root tag should be the same as the model type but all lowercase.
    3) The notification type should match the proto message name.
    4) No duplicate data across model types.
   Args:
    input_api: presubmit_support InputApi instance
    output_api: presubmit_support OutputApi instance
    model_type_file: AffectedFile object where the ModelTypeInfoMap is
  Returns:
    A (potentially empty) list PresubmitError objects corresponding to
    violations of the above rules.
  
Checks the kModelTypeInfoMap in model_type.cc follows conventions.
Checks that the kModelTypeInfoMap follows the below rules:
1) The model type string should match the model type name, but with
only the first letter capitalized and spaces instead of underscores.
2) The root tag should be the same as the model type but all lowercase.
3) The notification type should match the proto message name.
4) No duplicate data across model types.
Checks the kModelTypeInfoMap in model_type . cc follows conventions . Checks that the kModelTypeInfoMap follows the below rules : 1 ) The model type string should match the model type name but with only the first letter capitalized and spaces instead of underscores . 2 ) The root tag should be the same as the model type but all lowercase . 3 ) The notification type should match the proto message name . 4 ) No duplicate data across model types .
def CheckModelTypeInfoMap(input_api, output_api, model_type_file):
  accumulated_problems = []
  map_entries = ParseModelTypeEntries(
    input_api, model_type_file.AbsoluteLocalPath())
  check_map = False
  for line_num, _ in model_type_file.ChangedContents():
    for map_entry in map_entries:
      if line_num in map_entry.affected_lines:
        check_map = True
        break
  if not check_map:
    return []
  proto_field_definitions = ParseEntitySpecificsProtoFieldIdentifiers(
    input_api, os.path.abspath(PROTO_FILE_PATH))
  accumulated_problems.extend(
    CheckNoDuplicatedFieldValues(output_api, map_entries))
  for map_entry in map_entries:
    entry_problems = []
    entry_problems.extend(
      CheckNotificationTypeMatchesProtoMessageName(
        output_api, map_entry, proto_field_definitions))
    entry_problems.extend(CheckRootTagNotInBlocklist(output_api, map_entry))
    if map_entry.model_type not in EXCEPTION_MODEL_TYPES:
      entry_problems.extend(
        CheckModelTypeStringMatchesModelType(output_api, map_entry))
      entry_problems.extend(
        CheckRootTagMatchesModelType(output_api, map_entry))
    if len(entry_problems) > 0:
      accumulated_problems.extend(entry_problems)
  return accumulated_problems
def CheckModelTypeInfoMap ( input_api , output_api , model_type_file ) : accumulated_problems = [ ] map_entries = ParseModelTypeEntries ( input_api , model_type_file . AbsoluteLocalPath ( ) ) check_map = False for line_num , _ in model_type_file . ChangedContents ( ) : for map_entry in map_entries : if line_num in map_entry . affected_lines : check_map = True break if not check_map : return [ ] proto_field_definitions = ParseEntitySpecificsProtoFieldIdentifiers ( input_api , os . path . abspath ( PROTO_FILE_PATH ) ) accumulated_problems . extend ( CheckNoDuplicatedFieldValues ( output_api , map_entries ) ) for map_entry in map_entries : entry_problems = [ ] entry_problems . extend ( CheckNotificationTypeMatchesProtoMessageName ( output_api , map_entry , proto_field_definitions ) ) entry_problems . extend ( CheckRootTagNotInBlocklist ( output_api , map_entry ) ) if map_entry . model_type not in EXCEPTION_MODEL_TYPES : entry_problems . extend ( CheckModelTypeStringMatchesModelType ( output_api , map_entry ) ) entry_problems . extend ( CheckRootTagMatchesModelType ( output_api , map_entry ) ) if len ( entry_problems ) > 0 : accumulated_problems . extend ( entry_problems ) return accumulated_problems
Checks the kModelTypeInfoMap in model_type.cc follows conventions.
Checks the kModelTypeInfoMap in model_type . cc follows conventions .
"""Checks the kModelTypeInfoMap in model_type.cc follows conventions.
  Checks that the kModelTypeInfoMap follows the below rules:
    1) The model type string should match the model type name, but with
       only the first letter capitalized and spaces instead of underscores.
    2) The root tag should be the same as the model type but all lowercase.
    3) The notification type should match the proto message name.
    4) No duplicate data across model types.
   Args:
    input_api: presubmit_support InputApi instance
    output_api: presubmit_support OutputApi instance
    model_type_file: AffectedFile object where the ModelTypeInfoMap is
  Returns:
    A (potentially empty) list PresubmitError objects corresponding to
    violations of the above rules.
  """ # If any line of the map changed, we check the whole thing since # definitions span multiple lines and there are rules that apply across # all definitions e.g. no duplicated field values.
A (potentially empty) list PresubmitError objects corresponding to
violations of the above rules.
A ( potentially empty ) list PresubmitError objects corresponding to violations of the above rules .
input_api
output_api
model_type_file