function validateObjectTypeAnnotation()

in src/rule-generated-flow-types.js [150:254]


function validateObjectTypeAnnotation(
  context,
  Component,
  type,
  propName,
  propType,
  importFixRange,
  typeAliasMap,
  onlyVerify
) {
  const options = getOptions(context.options[0]);
  const propTypeProperty = getPropTypeProperty(
    context,
    typeAliasMap,
    propType,
    propName
  );

  const atleastOnePropertyExists = !!propType.properties[0];

  if (!propTypeProperty) {
    if (onlyVerify) {
      return false;
    }
    context.report({
      message:
        '`{{prop}}` is not declared in the `props` of the React component or it is not marked with the ' +
        'generated flow type `{{type}}`. See ' +
        'https://facebook.github.io/relay/docs/en/graphql-in-relay.html#importing-generated-definitions',
      data: {
        prop: propName,
        type
      },
      fix: options.fix
        ? fixer => {
            const whitespace = ' '.repeat(Component.parent.loc.start.column);
            const fixes = [
              genImportFixer(
                fixer,
                importFixRange,
                type,
                options.haste,
                whitespace
              )
            ];
            if (atleastOnePropertyExists) {
              fixes.push(
                fixer.insertTextBefore(
                  propType.properties[0],
                  `${propName}: ${type}, `
                )
              );
            } else {
              fixes.push(fixer.replaceText(propType, `{${propName}: ${type}}`));
            }
            return fixes;
          }
        : null,
      loc: Component.loc
    });
    return false;
  }
  if (
    propTypeProperty.value.type === 'NullableTypeAnnotation' &&
    propTypeProperty.value.typeAnnotation.type === 'GenericTypeAnnotation' &&
    propTypeProperty.value.typeAnnotation.id.name === type
  ) {
    return true;
  }
  if (
    propTypeProperty.value.type !== 'GenericTypeAnnotation' ||
    propTypeProperty.value.id.name !== type
  ) {
    if (onlyVerify) {
      return false;
    }
    context.report({
      message:
        'Component property `{{prop}}` expects to use the generated ' +
        '`{{type}}` flow type. See https://facebook.github.io/relay/docs/en/graphql-in-relay.html#importing-generated-definitions',
      data: {
        prop: propName,
        type
      },
      fix: options.fix
        ? fixer => {
            const whitespace = ' '.repeat(Component.parent.loc.start.column);
            return [
              genImportFixer(
                fixer,
                importFixRange,
                type,
                options.haste,
                whitespace
              ),
              fixer.replaceText(propTypeProperty.value, type)
            ];
          }
        : null,
      loc: Component.loc
    });
    return false;
  }
  return true;
}